-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.py
executable file
·108 lines (80 loc) · 3.16 KB
/
init.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
102
103
104
105
106
107
#!/usr/bin/env python
__author__ = "Stamped ([email protected])"
__version__ = "1.0"
__copyright__ = "Copyright (c) 2012 Stamped.com"
__license__ = "TODO"
import os, pickle, string, sys
from subprocess import Popen, PIPE
from optparse import OptionParser
from config import convert
import utils
node_name = ""
virtualenv_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "bin/activate")
def get_virtualenv_bin_path():
global virtualenv_path
return os.path.join(virtualenv_path, "bin/activate")
def check_shell(cmd, stdout=False, show_cmd=True):
if show_cmd:
print '[%s] %s' % (node_name, cmd)
path = get_virtualenv_bin_path()
if os.path.exists(path):
cmd = ". %s && %s" % (path, cmd)
sys.stdout.flush()
sys.stderr.flush()
ret = utils.shell(cmd, stdout)
sys.stdout.flush()
sys.stderr.flush()
if 0 != ret:
print 'error running shell command: %s' % cmd
sys.exit(1)
def parseCommandLine():
usage = "Usage: %prog pickled-params"
version = "%prog " + __version__
parser = OptionParser(usage=usage, version=version)
(options, args) = parser.parse_args()
if len(args) != 1:
parser.print_help()
sys.exit(1)
import json
params = json.loads(args[0].replace("'", '"'))
return (options, params)
def main():
global virtualenv_path
path = os.path.dirname(os.path.abspath(__file__))
virtualenv_path = os.path.dirname(path)
os.chdir(path)
"""
if os.path.exists(os.path.join(virtualenv_path, "bin")):
# remove virtualenv if it previously exists for some reason
# otherwise, the virtualenv creation step will fail
utils.shell('rm -rf %s/bin %s/install %s/lib' % (virtualenv_path, virtualenv_path, virtualenv_path))
"""
# parse commandline
(options, params) = parseCommandLine()
assert 'name' in params
global node_name
node_name = params['name']
params['path'] = virtualenv_path
from pprint import pprint
pprint(params)
check_shell('easy_install virtualenv', True)
if not os.path.exists(os.path.join(virtualenv_path, "bin")):
check_shell('virtualenv %s && . %s/bin/activate' % (virtualenv_path, virtualenv_path))
check_shell('pip install Jinja2')
template_dir = os.path.join(path, "config/templates")
for template in sorted(os.listdir(template_dir)):
if not template.endswith(".j2"):
continue
input_file = os.path.join(template_dir, template)
output_file = os.path.join(os.path.join(path, "config/generated"), template[0:-3])
check_shell('python config/convert.py -t %s -o %s "%s"' % \
(input_file, output_file, pickle.dumps(params)), show_cmd=False)
os.chdir('pynode')
check_shell('python setup.py build --build-base=/tmp --force')
check_shell('python setup.py install --force --record=.pynode.record')
check_shell('rm -rf `cat .pynode.record`')
check_shell('python setup.py install --force')
os.chdir(path)
check_shell('pynode %s' % "config/generated/default.py", True)
if __name__ == '__main__':
main()