This repository has been archived by the owner on Dec 31, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathquickstart.py
executable file
·101 lines (79 loc) · 2.94 KB
/
quickstart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
"""
quickstart.py
Set up a virtual environment with necessary dependencies installed
"""
import sys
import os
import subprocess
import argparse
import errno
ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
VENV_DIR = os.path.abspath(os.path.join(ROOT_DIR, 'env'))
PYVER = "%d.%d" % (sys.version_info[0], sys.version_info[1])
MERCURIAL_WIN_BINARY = "http://mercurial.selenic.com/release/windows/mercurial-2.5.2.win32-py%s.exe" % PYVER
def find_python():
for bindir in ['Scripts', 'bin']:
for suffix in ['.exe', '']:
python_bin = os.path.join(VENV_DIR, bindir, 'python' + suffix)
easy_install_bin = os.path.join(VENV_DIR, bindir, 'easy_install' + suffix)
if os.path.exists(python_bin) and os.path.exists(easy_install_bin):
return python_bin, easy_install_bin
raise RuntimeError("Something went wrong in virtualenv creation: "
"python and pip not found!")
def run_cmd(cmd):
print("$ %s" % " ".join(cmd))
ret = subprocess.call(cmd)
if ret != 0:
print("ERROR: command failed!")
sys.exit(1)
def main():
p = argparse.ArgumentParser(usage=__doc__.strip())
args = p.parse_args()
try:
import virtualenv
except ImportError:
print("ERROR: You need to install Virtualenv (https://pypi.python.org/pypi/virtualenv) first")
sys.exit(0)
try:
find_python()
except RuntimeError:
print("\n-- Creating virtualenv in deploy/env")
print("$ virtualenv %s" % VENV_DIR)
virtualenv.create_environment(VENV_DIR)
python_bin, easy_install_bin = find_python()
os.chdir(ROOT_DIR)
data_dir = os.path.abspath(os.path.join(ROOT_DIR, "data"))
try:
os.mkdir(os.path.abspath(os.path.join(ROOT_DIR, "data")))
except OSError:
if OSError.errno != errno.EEXIST:
print("ERROR: Unable to create `data` directory in the root %s" % ROOT_DIR)
else:
pass
print("\n-- Installing required modules")
with open('requirements.txt', 'r') as f:
requirements = [x.strip() for x in f.read().splitlines() if x.strip()]
if sys.platform.startswith('win'):
# Download the windows binary
requirements = [MERCURIAL_WIN_BINARY if x.lower().startswith('mercurial')
else x for x in requirements]
run_cmd([easy_install_bin] + requirements)
print("\n-- Setting up development database")
run_cmd([python_bin, 'manage.py', 'syncdb'])
run_cmd([python_bin, 'manage.py', 'migrate'])
run_cmd([python_bin, 'manage.py', 'loaddata', 'base'])
run_cmd([python_bin, 'manage.py', 'loaddata', 'sample'])
run_cmd([python_bin, 'manage.py', 'rebuild_index'])
print(r"""
-- All done!
Now you can do:
* Linux & OSX:
source env/bin/activate
python manage.py runserver
* Windows:
env\Scripts\activate
python manage.py runserver
""")
if __name__ == "__main__":
main()