-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.py
executable file
·192 lines (153 loc) · 4.36 KB
/
bootstrap.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python
""" simple creation of three commands, customised for your specific system.
windows users get a corresponding batch file. yippeeyaiyay.
"""
version = '0.9'
import os
import sys
pyjsbuild = """#!%(python)s
pyjsversion = r'%(ver)s'
pyjspth = r'%(pyjspth)s'
import os
import sys
sys.path[0:0] = [r'%(pth)s']
sys.path.append(os.path.join(pyjspth, 'pgen'))
import pyjs
pyjs.pyjspth = pyjspth
pyjs.path += [os.path.join(pyjspth, 'library'),
os.path.join(pyjspth, 'addons'),
]
import pyjs.browser
if __name__ == '__main__':
if "--version" in sys.argv:
print "Version:", pyjsversion
sys.exit(0)
pyjs.browser.build_script()
"""
pyjscompile = """#!%(python)s
pyjsversion = r'%(ver)s'
pyjspth = r'%(pyjspth)s'
import os
import sys
sys.path[0:0] = [r'%(pth)s']
sys.path.append(os.path.join(pyjspth, 'pgen'))
import pyjs.translator
pyjs.pyjspth = pyjspth
pyjs.path += [os.path.join(pyjspth, 'library')]
if __name__ == '__main__':
if "--version" in sys.argv:
print "Version:", pyjsversion
sys.exit(0)
pyjs.translator.main()
"""
pyjampiler= """#!%(python)s
pyjsversion = r'%(ver)s'
pyjspth = r'%(pyjspth)s'
import os
import sys
sys.path[0:0] = [r'%(pth)s']
sys.path.append(os.path.join(pyjspth, 'pgen'))
import pyjs.pyjampiler
pyjs.pyjspth = pyjspth
pyjs.path += [os.path.join(pyjspth, 'library')]
if __name__ == '__main__':
if "--version" in sys.argv:
print "Version:", pyjsversion
sys.exit(0)
pyjs.pyjampiler.Builder()
"""
pyjdsh = """#!/bin/sh
PYJAMAS_HOME="%(pyjspth)s"
PYJAMAS_SITE="%(pyjssitepth)s"
if [ "Q${PYTHONPATH}" = "Q" ] ; then
export PYTHONPATH="${PYJAMAS_HOME}:${PYJAMAS_SITE}"
else
export PYTHONPATH="${PYJAMAS_HOME}:${PYJAMAS_SITE}:${PYTHONPATH}"
fi
%(python)s $@
"""
pyjdinitpth = os.path.join("pyjd", "__init__.py.in")
pyjdinit = open(pyjdinitpth, "r").read()
batcmdtxt = '''@echo off
set CMD_LINE_ARGS=
:setArgs
if ""%%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%%CMD_LINE_ARGS%% %%1
shift
goto setArgs
:doneSetArgs
"%(python)s" "%(cmd)s.py" %%CMD_LINE_ARGS%%
'''
pyjdbat = '''@echo off
set PYJAMAS_HOME=%(pyjspth)s
set PYJAMAS_SITE=%(pyjssitepth)s
set PYTHONPATH=%%PYJAMAS_HOME%%;%%PYJAMAS_SITE%%;%%PYTHONPATH%%
set CMD_LINE_ARGS=
:setArgs
if ""%%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%%CMD_LINE_ARGS%% %%1
shift
goto setArgs
:doneSetArgs
"%(python)s" %%CMD_LINE_ARGS%%
'''
def make_cmd(prefix, pth, pyjsversion, pyjspth, cmdname, txt):
python = sys.executable
ver = pyjsversion
pyjssitepth = os.path.join(pyjspth, 'site-packages')
if sys.platform == 'win32':
cmd_name = cmdname + ".py"
if cmdname == 'pyjd':
cmd_name = 'pyjd.bat'
else:
cmd_name = cmdname
p = os.path.join(prefix, "bin")
if not os.path.exists(p):
os.makedirs(p)
cmd = os.path.join("bin", cmd_name)
cmd = os.path.join(prefix, cmd)
if os.path.exists(cmd):
if sys.platform == 'win32' \
and hasattr(os, "chmod"):
os.chmod(cmd, 0x1ed)
os.unlink(cmd)
f = open(cmd, "w")
f.write(txt % locals())
f.close()
if hasattr(os, "chmod"):
os.chmod(cmd, 0x16d)
if sys.platform == 'win32' and cmdname != 'pyjd':
cmd = os.path.join("bin", cmdname)
cmd = os.path.join(prefix, cmd)
cmd = os.path.abspath(cmd)
batcmd = "%s.bat" % cmd
f = open(batcmd, "w")
f.write(batcmdtxt % locals())
f.close()
if __name__ == '__main__':
if len(sys.argv) >= 2:
pth = sys.argv[1]
pyjspth = pth
else:
pth = os.path.abspath(os.getcwd())
pyjspth = pth
pth = os.path.join(pth, 'pyjs', 'src')
if len(sys.argv) == 3:
prefix = sys.argv[2]
elif len(sys.argv) == 4:
prefix = sys.argv[3]
pyjspth = sys.argv[2]
else:
prefix = "."
make_cmd(prefix, pth, version, pyjspth, "pyjsbuild", pyjsbuild)
make_cmd(prefix, pth, version, pyjspth, "pyjscompile", pyjscompile)
make_cmd(prefix, pth, version, pyjspth, "pyjampiler", pyjampiler)
# create pyjd/__init__.py
pyjdinitpth = os.path.join("pyjd", "__init__.py")
f = open(pyjdinitpth, "w")
f.write(pyjdinit % (version, pyjspth))
f.close()
if sys.platform == 'win32':
make_cmd(prefix, pth, version, pyjspth, "pyjd", pyjdbat)
else:
make_cmd(prefix, pth, version, pyjspth, "pyjd", pyjdsh)