author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 11 Oct 2017 11:54:55 +0300 | |
changeset 1867 | 418777c1fbc7 |
parent 1853 | 47a3f39bead0 |
child 2418 | 5587c490a070 |
permissions | -rw-r--r-- |
371 | 1 |
#!/usr/bin/env python |
2 |
||
1853
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
3 |
|
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
4 |
from __future__ import absolute_import |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
5 |
from __future__ import print_function |
371 | 6 |
import sys |
7 |
import shutil |
|
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
8 |
import re |
1834
cd42b426028b
fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
9 |
import os |
1850
614396cbffbf
fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
10 |
from os.path import join, basename, abspath, split, isfile, isdir |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
11 |
from hashlib import md5 |
371 | 12 |
from optparse import OptionParser |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
13 |
from cStringIO import StringIO |
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
14 |
|
1853
47a3f39bead0
fix pylint warning "(relative-import) Relative import 'Y', should be 'X.Y'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
15 |
from svgui.pyjs import pyjs |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
16 |
|
371 | 17 |
|
18 |
usage = """ |
|
19 |
usage: %prog [options] <application module name or path> |
|
20 |
||
21 |
This is the command line builder for the pyjamas project, which can |
|
22 |
be used to build Ajax applications from Python. |
|
23 |
For more information, see the website at http://pyjs.org/ |
|
24 |
""" |
|
25 |
||
26 |
# GWT1.2 Impl | GWT1.2 Output | Pyjamas 0.2 Platform | Pyjamas 0.2 Output |
|
27 |
# -------------+-----------------------+----------------------+---------------------- |
|
28 |
# IE6 | ie6 | IE6 | ie6 |
|
29 |
# Opera | opera | Opera | opera |
|
30 |
# Safari | safari | Safari | safari |
|
31 |
# -- | gecko1_8 | Mozilla | mozilla |
|
32 |
# -- | gecko | OldMoz | oldmoz |
|
33 |
# Standard | all | (default code) | all |
|
34 |
# Mozilla | gecko1_8, gecko | -- | -- |
|
35 |
# Old | safari, gecko, opera | -- | -- |
|
36 |
||
37 |
version = "%prog pyjamas version 2006-08-19" |
|
38 |
||
39 |
# these names in lowercase need match the strings |
|
40 |
# returned by "provider$user.agent" in order to be selected corretly |
|
41 |
app_platforms = ['IE6', 'Opera', 'OldMoz', 'Safari', 'Mozilla'] |
|
42 |
||
43 |
# usually defaults to e.g. /usr/share/pyjamas |
|
44 |
_data_dir = os.path.join(pyjs.prefix, "share/pyjamas") |
|
45 |
||
46 |
||
47 |
# .cache.html files produces look like this |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
48 |
CACHE_HTML_PAT = re.compile('^[a-z]*.[0-9a-f]{32}\.cache\.html$') |
371 | 49 |
|
50 |
# ok these are the three "default" library directories, containing |
|
51 |
# the builtins (str, List, Dict, ord, round, len, range etc.) |
|
52 |
# the main pyjamas libraries (pyjamas.ui, pyjamas.Window etc.) |
|
53 |
# and the contributed addons |
|
54 |
||
55 |
for p in ["library/builtins", |
|
56 |
"library", |
|
57 |
"addons"]: |
|
58 |
p = os.path.join(_data_dir, p) |
|
59 |
if os.path.isdir(p): |
|
60 |
pyjs.path.append(p) |
|
61 |
||
62 |
||
63 |
def read_boilerplate(data_dir, filename): |
|
64 |
return open(join(data_dir, "builder/boilerplate", filename)).read() |
|
65 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
66 |
|
371 | 67 |
def copy_boilerplate(data_dir, filename, output_dir): |
68 |
filename = join(data_dir, "builder/boilerplate", filename) |
|
69 |
shutil.copy(filename, output_dir) |
|
70 |
||
71 |
||
72 |
# taken and modified from python2.4 |
|
73 |
def copytree_exists(src, dst, symlinks=False): |
|
74 |
if not os.path.exists(src): |
|
75 |
return |
|
76 |
||
77 |
names = os.listdir(src) |
|
78 |
try: |
|
79 |
os.mkdir(dst) |
|
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1775
diff
changeset
|
80 |
except Exception: |
371 | 81 |
pass |
82 |
||
83 |
errors = [] |
|
84 |
for name in names: |
|
85 |
if name.startswith('CVS'): |
|
86 |
continue |
|
87 |
if name.startswith('.git'): |
|
88 |
continue |
|
89 |
if name.startswith('.svn'): |
|
90 |
continue |
|
91 |
||
92 |
srcname = os.path.join(src, name) |
|
93 |
dstname = os.path.join(dst, name) |
|
94 |
try: |
|
95 |
if symlinks and os.path.islink(srcname): |
|
96 |
linkto = os.readlink(srcname) |
|
97 |
os.symlink(linkto, dstname) |
|
98 |
elif isdir(srcname): |
|
99 |
copytree_exists(srcname, dstname, symlinks) |
|
100 |
else: |
|
101 |
shutil.copy2(srcname, dstname) |
|
102 |
except (IOError, os.error), why: |
|
103 |
errors.append((srcname, dstname, why)) |
|
104 |
if errors: |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
105 |
print(errors) |
371 | 106 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
107 |
|
371 | 108 |
def check_html_file(source_file, dest_path): |
109 |
""" Checks if a base HTML-file is available in the PyJamas |
|
110 |
output directory. |
|
111 |
If the HTML-file isn't available, it will be created. |
|
112 |
||
113 |
If a CSS-file with the same name is available |
|
114 |
in the output directory, a reference to this CSS-file |
|
115 |
is included. |
|
116 |
||
117 |
If no CSS-file is found, this function will look for a special |
|
118 |
CSS-file in the output directory, with the name |
|
119 |
"pyjamas_default.css", and if found it will be referenced |
|
120 |
in the generated HTML-file. |
|
121 |
||
122 |
[thank you to stef mientki for contributing this function] |
|
123 |
""" |
|
124 |
||
125 |
base_html = """\ |
|
126 |
<html> |
|
127 |
<!-- auto-generated html - you should consider editing and |
|
128 |
adapting this to suit your requirements |
|
129 |
--> |
|
130 |
<head> |
|
131 |
<meta name="pygwt:module" content="%(modulename)s"> |
|
132 |
%(css)s |
|
133 |
<title>%(title)s</title> |
|
134 |
</head> |
|
135 |
<body bgcolor="white"> |
|
136 |
<script language="javascript" src="pygwt.js"></script> |
|
137 |
</body> |
|
138 |
</html> |
|
139 |
""" |
|
140 |
||
1758
845ca626db09
clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1757
diff
changeset
|
141 |
filename = os.path.split(source_file)[1] |
845ca626db09
clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1757
diff
changeset
|
142 |
mod_name = os.path.splitext(filename)[0] |
845ca626db09
clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1757
diff
changeset
|
143 |
file_name = os.path.join(dest_path, mod_name + '.html') |
371 | 144 |
|
145 |
# if html file in output directory exists, leave it alone. |
|
1771
f68a105000be
clean-up: fix PEP8 E211 whitespace before '[' or '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
146 |
if os.path.exists(file_name): |
371 | 147 |
return 0 |
148 |
||
1746
45d6f5fba016
clean-up: fix PEP8 E202 whitespace before ')'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
149 |
if os.path.exists(os.path.join(dest_path, mod_name + '.css')): |
371 | 150 |
css = "<link rel='stylesheet' href='" + mod_name + ".css'>" |
1746
45d6f5fba016
clean-up: fix PEP8 E202 whitespace before ')'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
151 |
elif os.path.exists(os.path.join(dest_path, 'pyjamas_default.css')): |
371 | 152 |
css = "<link rel='stylesheet' href='pyjamas_default.css'>" |
153 |
||
154 |
else: |
|
155 |
css = '' |
|
156 |
||
157 |
title = 'PyJamas Auto-Generated HTML file ' + mod_name |
|
158 |
||
159 |
base_html = base_html % {'modulename': mod_name, 'title': title, 'css': css} |
|
160 |
||
1771
f68a105000be
clean-up: fix PEP8 E211 whitespace before '[' or '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
161 |
fh = open(file_name, 'w') |
f68a105000be
clean-up: fix PEP8 E211 whitespace before '[' or '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
162 |
fh.write(base_html) |
f68a105000be
clean-up: fix PEP8 E211 whitespace before '[' or '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
163 |
fh.close() |
371 | 164 |
|
165 |
return 1 |
|
166 |
||
167 |
||
168 |
def build(app_name, output, js_includes=(), debug=False, dynamic=0, |
|
169 |
data_dir=None, cache_buster=False, optimize=False): |
|
170 |
||
171 |
# make sure the output directory is always created in the current working |
|
172 |
# directory or at the place given if it is an absolute path. |
|
173 |
output = os.path.abspath(output) |
|
174 |
msg = "Building '%(app_name)s' to output directory '%(output)s'" % locals() |
|
175 |
if debug: |
|
176 |
msg += " with debugging statements" |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
177 |
print(msg) |
371 | 178 |
|
179 |
# check the output directory |
|
180 |
if os.path.exists(output) and not os.path.isdir(output): |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
181 |
print("Output destination %s exists and is not a directory" % output, file=sys.stderr) |
371 | 182 |
return |
183 |
if not os.path.isdir(output): |
|
184 |
try: |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
185 |
print("Creating output directory") |
371 | 186 |
os.mkdir(output) |
187 |
except StandardError, e: |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
188 |
print("Exception creating output directory %s: %s" % (output, e), file=sys.stderr) |
371 | 189 |
|
1753
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
190 |
# public dir |
371 | 191 |
for p in pyjs.path: |
192 |
pub_dir = join(p, 'public') |
|
193 |
if isdir(pub_dir): |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
194 |
print("Copying: public directory of library %r" % p) |
371 | 195 |
copytree_exists(pub_dir, output) |
196 |
||
1753
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
197 |
# AppName.html - can be in current or public directory |
371 | 198 |
html_input_filename = app_name + ".html" |
199 |
html_output_filename = join(output, basename(html_input_filename)) |
|
200 |
if os.path.isfile(html_input_filename): |
|
201 |
if not os.path.isfile(html_output_filename) or \ |
|
202 |
os.path.getmtime(html_input_filename) > \ |
|
203 |
os.path.getmtime(html_output_filename): |
|
204 |
try: |
|
205 |
shutil.copy(html_input_filename, html_output_filename) |
|
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1775
diff
changeset
|
206 |
except Exception: |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
207 |
print("Warning: Missing module HTML file %s" % html_input_filename, file=sys.stderr) |
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
208 |
|
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
209 |
print("Copying: %(html_input_filename)s" % locals()) |
371 | 210 |
|
211 |
if check_html_file(html_input_filename, output): |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
212 |
print("Warning: Module HTML file %s has been auto-generated" % html_input_filename, file=sys.stderr) |
371 | 213 |
|
1753
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
214 |
# pygwt.js |
371 | 215 |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
216 |
print("Copying: pygwt.js") |
371 | 217 |
|
218 |
pygwt_js_template = read_boilerplate(data_dir, "pygwt.js") |
|
219 |
pygwt_js_output = open(join(output, "pygwt.js"), "w") |
|
220 |
||
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
221 |
print(pygwt_js_template, file=pygwt_js_output) |
371 | 222 |
|
223 |
pygwt_js_output.close() |
|
224 |
||
1753
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
225 |
# Images |
371 | 226 |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
227 |
print("Copying: Images and History") |
371 | 228 |
copy_boilerplate(data_dir, "corner_dialog_topleft_black.png", output) |
229 |
copy_boilerplate(data_dir, "corner_dialog_topright_black.png", output) |
|
230 |
copy_boilerplate(data_dir, "corner_dialog_bottomright_black.png", output) |
|
231 |
copy_boilerplate(data_dir, "corner_dialog_bottomleft_black.png", output) |
|
232 |
copy_boilerplate(data_dir, "corner_dialog_edge_black.png", output) |
|
233 |
copy_boilerplate(data_dir, "corner_dialog_topleft.png", output) |
|
234 |
copy_boilerplate(data_dir, "corner_dialog_topright.png", output) |
|
235 |
copy_boilerplate(data_dir, "corner_dialog_bottomright.png", output) |
|
236 |
copy_boilerplate(data_dir, "corner_dialog_bottomleft.png", output) |
|
237 |
copy_boilerplate(data_dir, "corner_dialog_edge.png", output) |
|
238 |
copy_boilerplate(data_dir, "tree_closed.gif", output) |
|
239 |
copy_boilerplate(data_dir, "tree_open.gif", output) |
|
240 |
copy_boilerplate(data_dir, "tree_white.gif", output) |
|
241 |
copy_boilerplate(data_dir, "history.html", output) |
|
242 |
||
1753
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
243 |
# all.cache.html |
371 | 244 |
app_files = generateAppFiles(data_dir, js_includes, app_name, debug, |
245 |
output, dynamic, cache_buster, optimize) |
|
246 |
||
1753
19f19c66b67e
clean-up: fix most PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
247 |
# AppName.nocache.html |
371 | 248 |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
249 |
print("Creating: %(app_name)s.nocache.html" % locals()) |
371 | 250 |
|
251 |
home_nocache_html_template = read_boilerplate(data_dir, "home.nocache.html") |
|
252 |
home_nocache_html_output = open(join(output, app_name + ".nocache.html"), |
|
253 |
"w") |
|
254 |
||
255 |
# the selector templ is added to the selectScript function |
|
256 |
select_tmpl = """O(["true","%s"],"%s");""" |
|
257 |
script_selectors = StringIO() |
|
258 |
||
259 |
for platform, file_prefix in app_files: |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
260 |
print(select_tmpl % (platform, file_prefix), file=script_selectors) |
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
261 |
|
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
262 |
print( |
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
263 |
home_nocache_html_template % dict( |
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
264 |
app_name=app_name, |
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
265 |
script_selectors=script_selectors.getvalue(), |
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
266 |
), file=home_nocache_html_output) |
371 | 267 |
|
268 |
home_nocache_html_output.close() |
|
269 |
||
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
270 |
print("Done. You can run your app by opening '%(html_output_filename)s' in a browser" % locals()) |
371 | 271 |
|
272 |
||
273 |
def generateAppFiles(data_dir, js_includes, app_name, debug, output, dynamic, |
|
274 |
cache_buster, optimize): |
|
275 |
||
276 |
all_cache_html_template = read_boilerplate(data_dir, "all.cache.html") |
|
277 |
mod_cache_html_template = read_boilerplate(data_dir, "mod.cache.html") |
|
278 |
||
279 |
# clean out the old ones first |
|
280 |
for name in os.listdir(output): |
|
281 |
if CACHE_HTML_PAT.match(name): |
|
282 |
p = join(output, name) |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
283 |
print("Deleting existing app file %s" % p) |
371 | 284 |
os.unlink(p) |
285 |
||
286 |
app_files = [] |
|
287 |
parser = pyjs.PlatformParser("platform") |
|
288 |
app_headers = '' |
|
1764
d5df428640ff
clean-up: fix PEP8 E502 the backslash is redundant between brackets
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
289 |
scripts = ['<script type="text/javascript" src="%s"></script>' % |
d5df428640ff
clean-up: fix PEP8 E502 the backslash is redundant between brackets
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1763
diff
changeset
|
290 |
script for script in js_includes] |
371 | 291 |
app_body = '\n'.join(scripts) |
292 |
||
293 |
mod_code = {} |
|
294 |
mod_libs = {} |
|
295 |
modules = {} |
|
296 |
app_libs = {} |
|
297 |
early_app_libs = {} |
|
298 |
app_code = {} |
|
299 |
overrides = {} |
|
300 |
pover = {} |
|
301 |
app_modnames = {} |
|
302 |
mod_levels = {} |
|
303 |
||
304 |
# First, generate all the code. |
|
305 |
# Second, (dynamic only), post-analyse the places where modules |
|
306 |
# haven't changed |
|
307 |
# Third, write everything out. |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
728
diff
changeset
|
308 |
|
371 | 309 |
for platform in app_platforms: |
310 |
||
311 |
mod_code[platform] = {} |
|
312 |
mod_libs[platform] = {} |
|
313 |
modules[platform] = [] |
|
314 |
pover[platform] = {} |
|
315 |
app_libs[platform] = '' |
|
316 |
early_app_libs[platform] = '' |
|
317 |
app_code[platform] = {} |
|
318 |
app_modnames[platform] = {} |
|
319 |
||
320 |
# Application.Platform.cache.html |
|
321 |
||
322 |
parser.setPlatform(platform) |
|
323 |
app_translator = pyjs.AppTranslator( |
|
324 |
parser=parser, dynamic=dynamic, optimize=optimize) |
|
325 |
early_app_libs[platform], appcode = \ |
|
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
326 |
app_translator.translate(None, is_app=False, |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
327 |
debug=debug, |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
328 |
library_modules=['dynamicajax.js', |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
329 |
'_pyjs.js', 'sys', |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
330 |
'pyjslib']) |
371 | 331 |
pover[platform].update(app_translator.overrides.items()) |
332 |
for mname, name in app_translator.overrides.items(): |
|
333 |
pd = overrides.setdefault(mname, {}) |
|
334 |
pd[platform] = name |
|
335 |
||
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
336 |
print(appcode) |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
337 |
# mod_code[platform][app_name] = appcode |
371 | 338 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
728
diff
changeset
|
339 |
# platform.Module.cache.js |
371 | 340 |
|
341 |
modules_done = ['pyjslib', 'sys', '_pyjs.js'] |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
342 |
# modules_to_do = [app_name] + app_translator.library_modules |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
728
diff
changeset
|
343 |
modules_to_do = [app_name] + app_translator.library_modules |
371 | 344 |
|
345 |
dependencies = {} |
|
346 |
||
347 |
deps = map(pyjs.strip_py, modules_to_do) |
|
348 |
for d in deps: |
|
349 |
sublist = add_subdeps(dependencies, d) |
|
350 |
modules_to_do += sublist |
|
351 |
deps = uniquify(deps) |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
352 |
# dependencies[app_name] = deps |
371 | 353 |
|
354 |
modules[platform] = modules_done + modules_to_do |
|
355 |
||
356 |
while modules_to_do: |
|
357 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
358 |
# print "modules to do", modules_to_do |
371 | 359 |
|
360 |
mn = modules_to_do.pop() |
|
361 |
mod_name = pyjs.strip_py(mn) |
|
362 |
||
363 |
if mod_name in modules_done: |
|
364 |
continue |
|
365 |
||
366 |
modules_done.append(mod_name) |
|
367 |
||
368 |
mod_cache_name = "%s.%s.cache.js" % (platform.lower(), mod_name) |
|
369 |
||
370 |
parser.setPlatform(platform) |
|
371 |
mod_translator = pyjs.AppTranslator(parser=parser, optimize=optimize) |
|
372 |
mod_libs[platform][mod_name], mod_code[platform][mod_name] = \ |
|
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
373 |
mod_translator.translate(mod_name, |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
374 |
is_app=False, |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1764
diff
changeset
|
375 |
debug=debug) |
371 | 376 |
pover[platform].update(mod_translator.overrides.items()) |
377 |
for mname, name in mod_translator.overrides.items(): |
|
378 |
pd = overrides.setdefault(mname, {}) |
|
379 |
pd[platform] = name |
|
380 |
||
381 |
mods = mod_translator.library_modules |
|
382 |
modules_to_do += mods |
|
383 |
modules[platform] += mods |
|
384 |
||
385 |
deps = map(pyjs.strip_py, mods) |
|
386 |
sd = subdeps(mod_name) |
|
387 |
if len(sd) > 1: |
|
388 |
deps += sd[:-1] |
|
389 |
while mod_name in deps: |
|
390 |
deps.remove(mod_name) |
|
391 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
392 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
393 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
394 |
# print "modname preadd:", mod_name, deps |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
395 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
396 |
|
371 | 397 |
for d in deps: |
398 |
sublist = add_subdeps(dependencies, d) |
|
399 |
modules_to_do += sublist |
|
400 |
modules_to_do += add_subdeps(dependencies, mod_name) |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
401 |
# print "modname:", mod_name, deps |
371 | 402 |
deps = uniquify(deps) |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
403 |
# print "modname:", mod_name, deps |
371 | 404 |
dependencies[mod_name] = deps |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
728
diff
changeset
|
405 |
|
371 | 406 |
# work out the dependency ordering of the modules |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
728
diff
changeset
|
407 |
|
371 | 408 |
mod_levels[platform] = make_deps(None, dependencies, modules_done) |
409 |
||
410 |
# now write everything out |
|
411 |
||
412 |
for platform in app_platforms: |
|
413 |
||
414 |
early_app_libs_ = early_app_libs[platform] |
|
415 |
app_libs_ = app_libs[platform] |
|
416 |
app_code_ = app_code[platform] |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
417 |
# modules_ = filter_mods(app_name, modules[platform]) |
371 | 418 |
mods = flattenlist(mod_levels[platform]) |
419 |
mods.reverse() |
|
420 |
modules_ = filter_mods(None, mods) |
|
421 |
||
422 |
for mod_name in modules_: |
|
423 |
||
424 |
mod_code_ = mod_code[platform][mod_name] |
|
425 |
||
426 |
mod_name = pyjs.strip_py(mod_name) |
|
427 |
||
428 |
override_name = "%s.%s" % (platform.lower(), mod_name) |
|
1763
bcc07ff2362c
clean-up: fix PEP8 W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1758
diff
changeset
|
429 |
if override_name in pover[platform]: |
371 | 430 |
mod_cache_name = "%s.cache.js" % (override_name) |
431 |
else: |
|
432 |
mod_cache_name = "%s.cache.js" % (mod_name) |
|
433 |
||
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
434 |
print("Creating: " + mod_cache_name) |
371 | 435 |
|
436 |
modlevels = make_deps(None, dependencies, dependencies[mod_name]) |
|
437 |
||
438 |
modnames = [] |
|
439 |
||
440 |
for md in modlevels: |
|
441 |
mnames = map(lambda x: "'%s'" % x, md) |
|
442 |
mnames = "new pyjslib.List([\n\t\t\t%s])" % ',\n\t\t\t'.join(mnames) |
|
443 |
modnames.append(mnames) |
|
444 |
||
445 |
modnames.reverse() |
|
446 |
modnames = "new pyjslib.List([\n\t\t%s\n\t])" % ',\n\t\t'.join(modnames) |
|
447 |
||
448 |
# convert the overrides |
|
449 |
||
450 |
overnames = map(lambda x: "'%s': '%s'" % x, pover[platform].items()) |
|
451 |
overnames = "new pyjslib.Dict({\n\t\t%s\n\t})" % ',\n\t\t'.join(overnames) |
|
452 |
||
453 |
if dynamic: |
|
454 |
mod_cache_html_output = open(join(output, mod_cache_name), "w") |
|
455 |
else: |
|
456 |
mod_cache_html_output = StringIO() |
|
457 |
||
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
458 |
print(mod_cache_html_template % dict( |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
459 |
mod_name=mod_name, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
460 |
app_name=app_name, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
461 |
modnames=modnames, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
462 |
overrides=overnames, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
463 |
mod_libs=mod_libs[platform][mod_name], |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
464 |
dynamic=dynamic, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
465 |
mod_code=mod_code_, |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
466 |
), file=mod_cache_html_output) |
371 | 467 |
|
468 |
if dynamic: |
|
469 |
mod_cache_html_output.close() |
|
470 |
else: |
|
471 |
mod_cache_html_output.seek(0) |
|
472 |
app_libs_ += mod_cache_html_output.read() |
|
473 |
||
474 |
# write out the dependency ordering of the modules |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
728
diff
changeset
|
475 |
|
371 | 476 |
app_modnames = [] |
477 |
||
478 |
for md in mod_levels[platform]: |
|
479 |
mnames = map(lambda x: "'%s'" % x, md) |
|
480 |
mnames = "new pyjslib.List([\n\t\t\t%s])" % ',\n\t\t\t'.join(mnames) |
|
481 |
app_modnames.append(mnames) |
|
482 |
||
483 |
app_modnames.reverse() |
|
484 |
app_modnames = "new pyjslib.List([\n\t\t%s\n\t])" % ',\n\t\t'.join(app_modnames) |
|
485 |
||
486 |
# convert the overrides |
|
487 |
||
488 |
overnames = map(lambda x: "'%s': '%s'" % x, pover[platform].items()) |
|
489 |
overnames = "new pyjslib.Dict({\n\t\t%s\n\t})" % ',\n\t\t'.join(overnames) |
|
490 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
491 |
# print "platform names", platform, overnames |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
492 |
# print pover |
371 | 493 |
|
494 |
# now write app.allcache including dependency-ordered list of |
|
495 |
# library modules |
|
496 |
||
497 |
file_contents = all_cache_html_template % dict( |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
498 |
app_name=app_name, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
499 |
early_app_libs=early_app_libs_, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
500 |
app_libs=app_libs_, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
501 |
app_code=app_code_, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
502 |
app_body=app_body, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
503 |
overrides=overnames, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
504 |
platform=platform.lower(), |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
505 |
dynamic=dynamic, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
506 |
app_modnames=app_modnames, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
507 |
app_headers=app_headers |
371 | 508 |
) |
509 |
if cache_buster: |
|
510 |
digest = md5.new(file_contents).hexdigest() |
|
511 |
file_name = "%s.%s.%s" % (platform.lower(), app_name, digest) |
|
512 |
else: |
|
513 |
file_name = "%s.%s" % (platform.lower(), app_name) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
728
diff
changeset
|
514 |
file_name += ".cache.html" |
371 | 515 |
out_path = join(output, file_name) |
516 |
out_file = open(out_path, 'w') |
|
517 |
out_file.write(file_contents) |
|
518 |
out_file.close() |
|
519 |
app_files.append((platform.lower(), file_name)) |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
520 |
print("Created app file %s:%s: %s" % ( |
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
521 |
app_name, platform, out_path)) |
371 | 522 |
|
523 |
return app_files |
|
524 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
525 |
|
371 | 526 |
def flattenlist(ll): |
527 |
res = [] |
|
528 |
for l in ll: |
|
529 |
res += l |
|
530 |
return res |
|
531 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
532 |
|
371 | 533 |
def subdeps(m): |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
534 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
535 |
creates sub-dependencies e.g. pyjamas.ui.Widget |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
536 |
creates pyjamas.ui.Widget, pyjamas.ui and pyjamas. |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
537 |
""" |
371 | 538 |
d = [] |
539 |
m = m.split(".") |
|
540 |
for i in range(0, len(m)): |
|
541 |
d.append('.'.join(m[:i+1])) |
|
542 |
return d |
|
543 |
||
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1746
diff
changeset
|
544 |
|
371 | 545 |
def add_subdeps(deps, mod_name): |
546 |
sd = subdeps(mod_name) |
|
547 |
if len(sd) == 1: |
|
548 |
return [] |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
549 |
# print "subdeps", mod_name, sd |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
550 |
# print "deps", deps |
371 | 551 |
res = [] |
552 |
for i in range(0, len(sd)-1): |
|
553 |
parent = sd[i] |
|
554 |
child = sd[i+1] |
|
1755
624b9694cb0d
clean-up: fix PEP8 E741 ambiguous variable name
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
555 |
k = deps.get(child, []) |
624b9694cb0d
clean-up: fix PEP8 E741 ambiguous variable name
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
556 |
k.append(parent) |
624b9694cb0d
clean-up: fix PEP8 E741 ambiguous variable name
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
557 |
deps[child] = k |
371 | 558 |
if parent not in res: |
559 |
res.append(parent) |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
560 |
# print deps |
371 | 561 |
return res |
562 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
563 |
|
371 | 564 |
def uniquify(md): |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
565 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
566 |
makes unique and preserves list order |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
567 |
""" |
371 | 568 |
res = [] |
569 |
for m in md: |
|
570 |
if m not in res: |
|
571 |
res.append(m) |
|
572 |
return res |
|
573 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
574 |
|
371 | 575 |
def filter_mods(app_name, md): |
576 |
while 'sys' in md: |
|
577 |
md.remove('sys') |
|
578 |
while 'pyjslib' in md: |
|
579 |
md.remove('pyjslib') |
|
580 |
while app_name in md: |
|
581 |
md.remove(app_name) |
|
582 |
md = filter(lambda x: not x.endswith('.js'), md) |
|
583 |
md = map(pyjs.strip_py, md) |
|
584 |
||
585 |
return uniquify(md) |
|
586 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
587 |
|
371 | 588 |
def filter_deps(app_name, deps): |
589 |
||
590 |
res = {} |
|
591 |
for (k, l) in deps.items(): |
|
592 |
mods = filter_mods(k, l) |
|
593 |
while k in mods: |
|
594 |
mods.remove(k) |
|
595 |
res[k] = mods |
|
596 |
return res |
|
597 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
598 |
|
371 | 599 |
def has_nodeps(mod, deps): |
1775
b45f2768fab1
clean-up: fix PEP8 E713 test for membership should be 'not in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
600 |
if mod not in deps or not deps[mod]: |
371 | 601 |
return True |
602 |
return False |
|
603 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
604 |
|
371 | 605 |
def nodeps_list(mod_list, deps): |
606 |
res = [] |
|
607 |
for mod in mod_list: |
|
608 |
if has_nodeps(mod, deps): |
|
609 |
res.append(mod) |
|
610 |
return res |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
728
diff
changeset
|
611 |
|
371 | 612 |
# this function takes a dictionary of dependent modules and |
613 |
# creates a list of lists. the first list will be modules |
|
614 |
# that have no dependencies; the second list will be those |
|
615 |
# modules that have the first list as dependencies; the |
|
616 |
# third will be those modules that have the first and second... |
|
617 |
# etc. |
|
618 |
||
619 |
||
620 |
def make_deps(app_name, deps, mod_list): |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
621 |
print("Calculating Dependencies ...") |
371 | 622 |
mod_list = filter_mods(app_name, mod_list) |
623 |
deps = filter_deps(app_name, deps) |
|
624 |
||
625 |
if not mod_list: |
|
626 |
return [] |
|
627 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
628 |
# print mod_list |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
629 |
# print deps |
371 | 630 |
|
631 |
ordered_deps = [] |
|
632 |
last_len = -1 |
|
633 |
while deps: |
|
634 |
l_deps = len(deps) |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
635 |
# print l_deps |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
636 |
if l_deps == last_len: |
371 | 637 |
for m, dl in deps.items(): |
638 |
for d in dl: |
|
639 |
if m in deps.get(d, []): |
|
640 |
raise Exception('Circular Imports found: \n%s %s -> %s %s' |
|
641 |
% (m, dl, d, deps[d])) |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
642 |
# raise Exception('Could not calculate dependencies: \n%s' % deps) |
371 | 643 |
break |
644 |
last_len = l_deps |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
645 |
# print "modlist", mod_list |
371 | 646 |
nodeps = nodeps_list(mod_list, deps) |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
647 |
# print "nodeps", nodeps |
371 | 648 |
mod_list = filter(lambda x: x not in nodeps, mod_list) |
649 |
newdeps = {} |
|
650 |
for k in deps.keys(): |
|
651 |
depslist = deps[k] |
|
652 |
depslist = filter(lambda x: x not in nodeps, depslist) |
|
653 |
if depslist: |
|
654 |
newdeps[k] = depslist |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
655 |
# print "newdeps", newdeps |
371 | 656 |
deps = newdeps |
657 |
ordered_deps.append(nodeps) |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
658 |
# time.sleep(0) |
371 | 659 |
|
660 |
if mod_list: |
|
1737
a39c2918c015
clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
661 |
ordered_deps.append(mod_list) # last dependencies - usually the app(s) |
371 | 662 |
|
663 |
ordered_deps.reverse() |
|
664 |
||
665 |
return ordered_deps |
|
666 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
667 |
|
371 | 668 |
def main(): |
669 |
global app_platforms |
|
670 |
||
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
671 |
parser = OptionParser(usage=usage, version=version) |
1773
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
672 |
parser.add_option( |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
673 |
"-o", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
674 |
"--output", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
675 |
dest="output", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
676 |
help="directory to which the webapp should be written" |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
677 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
678 |
parser.add_option( |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
679 |
"-j", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
680 |
"--include-js", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
681 |
dest="js_includes", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
682 |
action="append", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
683 |
help="javascripts to load into the same frame as the rest of the script" |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
684 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
685 |
parser.add_option( |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
686 |
"-I", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
687 |
"--library_dir", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
688 |
dest="library_dirs", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
689 |
action="append", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
690 |
help="additional paths appended to PYJSPATH" |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
691 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
692 |
parser.add_option( |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
693 |
"-D", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
694 |
"--data_dir", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
695 |
dest="data_dir", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
696 |
help="path for data directory" |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
697 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
698 |
parser.add_option( |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
699 |
"-m", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
700 |
"--dynamic-modules", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
701 |
action="store_true", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
702 |
dest="dynamic", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
703 |
default=False, |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
704 |
help="Split output into separate dynamically-loaded modules (experimental)" |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
705 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
706 |
parser.add_option( |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
707 |
"-P", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
708 |
"--platforms", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
709 |
dest="platforms", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
710 |
help="platforms to build for, comma-separated" |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
711 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
712 |
parser.add_option( |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
713 |
"-d", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
714 |
"--debug", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
715 |
action="store_true", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
716 |
dest="debug" |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
717 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
718 |
parser.add_option( |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
719 |
"-O", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
720 |
"--optimize", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
721 |
action="store_true", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
722 |
dest="optimize", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
723 |
default=False, |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
724 |
help="Optimize generated code (removes all print statements)", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
725 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
726 |
parser.add_option( |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
727 |
"-c", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
728 |
"--cache_buster", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
729 |
action="store_true", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
730 |
dest="cache_buster", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
731 |
help="Enable browser cache-busting (MD5 hash added to output filenames)" |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
732 |
) |
371 | 733 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
734 |
parser.set_defaults(output="output", js_includes=[], library_dirs=[], |
371 | 735 |
platforms=(','.join(app_platforms)), |
736 |
data_dir=os.path.join(sys.prefix, "share/pyjamas"), |
|
737 |
dynamic=False, |
|
738 |
cache_buster=False, |
|
739 |
debug=False) |
|
740 |
(options, args) = parser.parse_args() |
|
741 |
if len(args) != 1: |
|
742 |
parser.error("incorrect number of arguments") |
|
743 |
||
744 |
data_dir = abspath(options.data_dir) |
|
745 |
||
746 |
app_path = args[0] |
|
747 |
if app_path.endswith('.py'): |
|
748 |
app_path = abspath(app_path) |
|
749 |
if not isfile(app_path): |
|
750 |
parser.error("Application file not found %r" % app_path) |
|
751 |
app_path, app_name = split(app_path) |
|
752 |
app_name = app_name[:-3] |
|
753 |
pyjs.path.append(app_path) |
|
754 |
elif os.path.sep in app_path: |
|
755 |
parser.error("Not a valid module declaration %r" % app_path) |
|
756 |
else: |
|
757 |
app_name = app_path |
|
758 |
||
759 |
for d in options.library_dirs: |
|
760 |
pyjs.path.append(abspath(d)) |
|
761 |
||
762 |
if options.platforms: |
|
1757
0de89da92ee0
clean-up: fix PEP8 E111 indentation is not a multiple of four
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1755
diff
changeset
|
763 |
app_platforms = options.platforms.split(',') |
371 | 764 |
|
765 |
# this is mostly for getting boilerplate stuff |
|
766 |
data_dir = os.path.abspath(options.data_dir) |
|
767 |
||
768 |
build(app_name, options.output, options.js_includes, |
|
769 |
options.debug, options.dynamic and 1 or 0, data_dir, |
|
770 |
options.cache_buster, options.optimize) |
|
771 |
||
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1746
diff
changeset
|
772 |
|
371 | 773 |
if __name__ == "__main__": |
774 |
main() |