-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootstrap.py
More file actions
executable file
·101 lines (84 loc) · 3.18 KB
/
bootstrap.py
File metadata and controls
executable file
·101 lines (84 loc) · 3.18 KB
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
from optparse import OptionParser
import os
import subprocess
import shutil
import logging
import signal
import re
pwd = os.path.abspath(os.path.dirname(__file__))
vedir = os.path.abspath(os.path.join(pwd, "ve"))
def kill_daemons(sig=signal.SIGKILL):
uid = os.getuid()
cmd = ['ps', 'x', '-U', str(uid), '-o', 'pid,command']
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
lines = proc.stdout.readlines()[1:]
logging.debug("Searching %d processes for this user.", len(lines))
for l in lines:
l = l.strip()
m = re.match('(\\d+) (npact-.*)', l)
if m:
pid, name = m.groups()
logging.warning("Killing proc %s %r", pid, name)
os.kill(int(pid), sig)
def cleanup_existing():
if os.path.exists(vedir):
logging.info("Removing existing virtual environment")
shutil.rmtree(vedir)
def init_virtualenv():
logging.info("Creating virtualenvironment")
virtualenv_support_dir = os.path.abspath(
os.path.join(pwd, "lib", "virtualenv_support"))
ret = subprocess.call(["python", "virtualenv.py",
"--extra-search-dir=%s" % virtualenv_support_dir,
"--prompt=(npact)",
vedir],
cwd=pwd)
if ret:
logging.critical("Failed creating virtualenv: %s", ret)
exit(ret)
logging.debug("Installing libraries")
cmd = [os.path.join(vedir, 'bin', 'pip'), "install",
# "--index-url=''",
"--requirement", os.path.join(pwd, "requirements.txt")]
ret = subprocess.call(cmd, cwd=pwd)
if ret:
logging.critical("Failed installing libraries from requirements.txt")
exit(ret)
def create_aux_directories():
if not os.path.exists('webroot'):
os.makedirs('webroot')
def build_pynpact():
logging.info("Building pynpact C code.")
pynpact_dir = os.path.join(os.path.dirname(__file__), "pynpact/")
ret = subprocess.call(["make"], cwd=pynpact_dir)
if ret:
logging.critical("Make failed; C programs may not be availalbe.")
if __name__ == '__main__':
parser = OptionParser("""%prog [options] [Command ...]
Runs the initialization and building code to get the system into a
working state after a fresh checkout.
When given with no commands does the full process. Specific steps
can be invoked by name, including:
* kill-daemons
* cleanup-existing
* init-virtualenv
* create-aux-directories
* build-pynpact
""")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
help="Show more verbose log messages.")
(options, args) = parser.parse_args()
logging.basicConfig(level=(options.verbose and logging.DEBUG or logging.INFO),
format="%(asctime)s %(levelname)-8s %(message)s",
datefmt='%H:%M:%S')
if len(args) == 0:
cleanup_existing()
kill_daemons()
init_virtualenv()
create_aux_directories()
build_pynpact()
print "\nSuccessfully finished bootstrap.py!"
else:
for arg in args:
globals()[arg.replace('-','_')]()