author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Tue, 03 Oct 2017 16:07:02 +0300 | |
changeset 1842 | 05c1f7aa8991 |
parent 1834 | cd42b426028b |
child 1846 | 14b40afccd69 |
permissions | -rw-r--r-- |
371 | 1 |
#!/usr/bin/env python |
2 |
||
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
3 |
from __future__ import print_function |
371 | 4 |
import sys |
5 |
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
|
6 |
import time |
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
7 |
import re |
1834
cd42b426028b
fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
8 |
import os |
cd42b426028b
fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
9 |
from os.path import join, dirname, 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
|
10 |
from hashlib import md5 |
371 | 11 |
from copy import copy |
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 |
|
371 | 15 |
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 |
tmpl = read_boilerplate(data_dir, "all.cache.html") |
|
288 |
parser = pyjs.PlatformParser("platform") |
|
289 |
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
|
290 |
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
|
291 |
script for script in js_includes] |
371 | 292 |
app_body = '\n'.join(scripts) |
293 |
||
294 |
mod_code = {} |
|
295 |
mod_libs = {} |
|
296 |
modules = {} |
|
297 |
app_libs = {} |
|
298 |
early_app_libs = {} |
|
299 |
app_code = {} |
|
300 |
overrides = {} |
|
301 |
pover = {} |
|
302 |
app_modnames = {} |
|
303 |
mod_levels = {} |
|
304 |
||
305 |
# First, generate all the code. |
|
306 |
# Second, (dynamic only), post-analyse the places where modules |
|
307 |
# haven't changed |
|
308 |
# Third, write everything out. |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
728
diff
changeset
|
309 |
|
371 | 310 |
for platform in app_platforms: |
311 |
||
312 |
mod_code[platform] = {} |
|
313 |
mod_libs[platform] = {} |
|
314 |
modules[platform] = [] |
|
315 |
pover[platform] = {} |
|
316 |
app_libs[platform] = '' |
|
317 |
early_app_libs[platform] = '' |
|
318 |
app_code[platform] = {} |
|
319 |
app_modnames[platform] = {} |
|
320 |
||
321 |
# Application.Platform.cache.html |
|
322 |
||
323 |
parser.setPlatform(platform) |
|
324 |
app_translator = pyjs.AppTranslator( |
|
325 |
parser=parser, dynamic=dynamic, optimize=optimize) |
|
326 |
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
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
'_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
|
331 |
'pyjslib']) |
371 | 332 |
pover[platform].update(app_translator.overrides.items()) |
333 |
for mname, name in app_translator.overrides.items(): |
|
334 |
pd = overrides.setdefault(mname, {}) |
|
335 |
pd[platform] = name |
|
336 |
||
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
337 |
print(appcode) |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
338 |
# mod_code[platform][app_name] = appcode |
371 | 339 |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
728
diff
changeset
|
340 |
# platform.Module.cache.js |
371 | 341 |
|
342 |
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
|
343 |
# 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
|
344 |
modules_to_do = [app_name] + app_translator.library_modules |
371 | 345 |
|
346 |
dependencies = {} |
|
347 |
||
348 |
deps = map(pyjs.strip_py, modules_to_do) |
|
349 |
for d in deps: |
|
350 |
sublist = add_subdeps(dependencies, d) |
|
351 |
modules_to_do += sublist |
|
352 |
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
|
353 |
# dependencies[app_name] = deps |
371 | 354 |
|
355 |
modules[platform] = modules_done + modules_to_do |
|
356 |
||
357 |
while modules_to_do: |
|
358 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
359 |
# print "modules to do", modules_to_do |
371 | 360 |
|
361 |
mn = modules_to_do.pop() |
|
362 |
mod_name = pyjs.strip_py(mn) |
|
363 |
||
364 |
if mod_name in modules_done: |
|
365 |
continue |
|
366 |
||
367 |
modules_done.append(mod_name) |
|
368 |
||
369 |
mod_cache_name = "%s.%s.cache.js" % (platform.lower(), mod_name) |
|
370 |
||
371 |
parser.setPlatform(platform) |
|
372 |
mod_translator = pyjs.AppTranslator(parser=parser, optimize=optimize) |
|
373 |
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
|
374 |
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
|
375 |
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
|
376 |
debug=debug) |
371 | 377 |
pover[platform].update(mod_translator.overrides.items()) |
378 |
for mname, name in mod_translator.overrides.items(): |
|
379 |
pd = overrides.setdefault(mname, {}) |
|
380 |
pd[platform] = name |
|
381 |
||
382 |
mods = mod_translator.library_modules |
|
383 |
modules_to_do += mods |
|
384 |
modules[platform] += mods |
|
385 |
||
386 |
deps = map(pyjs.strip_py, mods) |
|
387 |
sd = subdeps(mod_name) |
|
388 |
if len(sd) > 1: |
|
389 |
deps += sd[:-1] |
|
390 |
while mod_name in deps: |
|
391 |
deps.remove(mod_name) |
|
392 |
||
1782
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 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
395 |
# 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
|
396 |
|
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
397 |
|
371 | 398 |
for d in deps: |
399 |
sublist = add_subdeps(dependencies, d) |
|
400 |
modules_to_do += sublist |
|
401 |
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
|
402 |
# print "modname:", mod_name, deps |
371 | 403 |
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
|
404 |
# print "modname:", mod_name, deps |
371 | 405 |
dependencies[mod_name] = deps |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
728
diff
changeset
|
406 |
|
371 | 407 |
# 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
|
408 |
|
371 | 409 |
mod_levels[platform] = make_deps(None, dependencies, modules_done) |
410 |
||
411 |
# now write everything out |
|
412 |
||
413 |
for platform in app_platforms: |
|
414 |
||
415 |
early_app_libs_ = early_app_libs[platform] |
|
416 |
app_libs_ = app_libs[platform] |
|
417 |
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
|
418 |
# modules_ = filter_mods(app_name, modules[platform]) |
371 | 419 |
mods = flattenlist(mod_levels[platform]) |
420 |
mods.reverse() |
|
421 |
modules_ = filter_mods(None, mods) |
|
422 |
||
423 |
for mod_name in modules_: |
|
424 |
||
425 |
mod_code_ = mod_code[platform][mod_name] |
|
426 |
||
427 |
mod_name = pyjs.strip_py(mod_name) |
|
428 |
||
429 |
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
|
430 |
if override_name in pover[platform]: |
371 | 431 |
mod_cache_name = "%s.cache.js" % (override_name) |
432 |
else: |
|
433 |
mod_cache_name = "%s.cache.js" % (mod_name) |
|
434 |
||
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
435 |
print("Creating: " + mod_cache_name) |
371 | 436 |
|
437 |
modlevels = make_deps(None, dependencies, dependencies[mod_name]) |
|
438 |
||
439 |
modnames = [] |
|
440 |
||
441 |
for md in modlevels: |
|
442 |
mnames = map(lambda x: "'%s'" % x, md) |
|
443 |
mnames = "new pyjslib.List([\n\t\t\t%s])" % ',\n\t\t\t'.join(mnames) |
|
444 |
modnames.append(mnames) |
|
445 |
||
446 |
modnames.reverse() |
|
447 |
modnames = "new pyjslib.List([\n\t\t%s\n\t])" % ',\n\t\t'.join(modnames) |
|
448 |
||
449 |
# convert the overrides |
|
450 |
||
451 |
overnames = map(lambda x: "'%s': '%s'" % x, pover[platform].items()) |
|
452 |
overnames = "new pyjslib.Dict({\n\t\t%s\n\t})" % ',\n\t\t'.join(overnames) |
|
453 |
||
454 |
if dynamic: |
|
455 |
mod_cache_html_output = open(join(output, mod_cache_name), "w") |
|
456 |
else: |
|
457 |
mod_cache_html_output = StringIO() |
|
458 |
||
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
459 |
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
|
460 |
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
|
461 |
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
|
462 |
modnames=modnames, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
463 |
overrides=overnames, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
464 |
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
|
465 |
dynamic=dynamic, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
466 |
mod_code=mod_code_, |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
467 |
), file=mod_cache_html_output) |
371 | 468 |
|
469 |
if dynamic: |
|
470 |
mod_cache_html_output.close() |
|
471 |
else: |
|
472 |
mod_cache_html_output.seek(0) |
|
473 |
app_libs_ += mod_cache_html_output.read() |
|
474 |
||
475 |
# 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
|
476 |
|
371 | 477 |
app_modnames = [] |
478 |
||
479 |
for md in mod_levels[platform]: |
|
480 |
mnames = map(lambda x: "'%s'" % x, md) |
|
481 |
mnames = "new pyjslib.List([\n\t\t\t%s])" % ',\n\t\t\t'.join(mnames) |
|
482 |
app_modnames.append(mnames) |
|
483 |
||
484 |
app_modnames.reverse() |
|
485 |
app_modnames = "new pyjslib.List([\n\t\t%s\n\t])" % ',\n\t\t'.join(app_modnames) |
|
486 |
||
487 |
# convert the overrides |
|
488 |
||
489 |
overnames = map(lambda x: "'%s': '%s'" % x, pover[platform].items()) |
|
490 |
overnames = "new pyjslib.Dict({\n\t\t%s\n\t})" % ',\n\t\t'.join(overnames) |
|
491 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
492 |
# 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
|
493 |
# print pover |
371 | 494 |
|
495 |
# now write app.allcache including dependency-ordered list of |
|
496 |
# library modules |
|
497 |
||
498 |
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
|
499 |
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
|
500 |
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
|
501 |
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
|
502 |
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
|
503 |
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
|
504 |
overrides=overnames, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
505 |
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
|
506 |
dynamic=dynamic, |
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
507 |
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
|
508 |
app_headers=app_headers |
371 | 509 |
) |
510 |
if cache_buster: |
|
511 |
digest = md5.new(file_contents).hexdigest() |
|
512 |
file_name = "%s.%s.%s" % (platform.lower(), app_name, digest) |
|
513 |
else: |
|
514 |
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
|
515 |
file_name += ".cache.html" |
371 | 516 |
out_path = join(output, file_name) |
517 |
out_file = open(out_path, 'w') |
|
518 |
out_file.write(file_contents) |
|
519 |
out_file.close() |
|
520 |
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
|
521 |
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
|
522 |
app_name, platform, out_path)) |
371 | 523 |
|
524 |
return app_files |
|
525 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
526 |
|
371 | 527 |
def flattenlist(ll): |
528 |
res = [] |
|
529 |
for l in ll: |
|
530 |
res += l |
|
531 |
return res |
|
532 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
533 |
|
371 | 534 |
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
|
535 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
536 |
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
|
537 |
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
|
538 |
""" |
371 | 539 |
d = [] |
540 |
m = m.split(".") |
|
541 |
for i in range(0, len(m)): |
|
542 |
d.append('.'.join(m[:i+1])) |
|
543 |
return d |
|
544 |
||
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
|
545 |
|
371 | 546 |
def add_subdeps(deps, mod_name): |
547 |
sd = subdeps(mod_name) |
|
548 |
if len(sd) == 1: |
|
549 |
return [] |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
550 |
# 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
|
551 |
# print "deps", deps |
371 | 552 |
res = [] |
553 |
for i in range(0, len(sd)-1): |
|
554 |
parent = sd[i] |
|
555 |
child = sd[i+1] |
|
1755
624b9694cb0d
clean-up: fix PEP8 E741 ambiguous variable name
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
556 |
k = deps.get(child, []) |
624b9694cb0d
clean-up: fix PEP8 E741 ambiguous variable name
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
557 |
k.append(parent) |
624b9694cb0d
clean-up: fix PEP8 E741 ambiguous variable name
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1754
diff
changeset
|
558 |
deps[child] = k |
371 | 559 |
if parent not in res: |
560 |
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
|
561 |
# print deps |
371 | 562 |
return res |
563 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
564 |
|
371 | 565 |
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
|
566 |
""" |
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
567 |
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
|
568 |
""" |
371 | 569 |
res = [] |
570 |
for m in md: |
|
571 |
if m not in res: |
|
572 |
res.append(m) |
|
573 |
return res |
|
574 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
575 |
|
371 | 576 |
def filter_mods(app_name, md): |
577 |
while 'sys' in md: |
|
578 |
md.remove('sys') |
|
579 |
while 'pyjslib' in md: |
|
580 |
md.remove('pyjslib') |
|
581 |
while app_name in md: |
|
582 |
md.remove(app_name) |
|
583 |
md = filter(lambda x: not x.endswith('.js'), md) |
|
584 |
md = map(pyjs.strip_py, md) |
|
585 |
||
586 |
return uniquify(md) |
|
587 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
588 |
|
371 | 589 |
def filter_deps(app_name, deps): |
590 |
||
591 |
res = {} |
|
592 |
for (k, l) in deps.items(): |
|
593 |
mods = filter_mods(k, l) |
|
594 |
while k in mods: |
|
595 |
mods.remove(k) |
|
596 |
res[k] = mods |
|
597 |
return res |
|
598 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
599 |
|
371 | 600 |
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
|
601 |
if mod not in deps or not deps[mod]: |
371 | 602 |
return True |
603 |
return False |
|
604 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
605 |
|
371 | 606 |
def nodeps_list(mod_list, deps): |
607 |
res = [] |
|
608 |
for mod in mod_list: |
|
609 |
if has_nodeps(mod, deps): |
|
610 |
res.append(mod) |
|
611 |
return res |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
728
diff
changeset
|
612 |
|
371 | 613 |
# this function takes a dictionary of dependent modules and |
614 |
# creates a list of lists. the first list will be modules |
|
615 |
# that have no dependencies; the second list will be those |
|
616 |
# modules that have the first list as dependencies; the |
|
617 |
# third will be those modules that have the first and second... |
|
618 |
# etc. |
|
619 |
||
620 |
||
621 |
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
|
622 |
print("Calculating Dependencies ...") |
371 | 623 |
mod_list = filter_mods(app_name, mod_list) |
624 |
deps = filter_deps(app_name, deps) |
|
625 |
||
626 |
if not mod_list: |
|
627 |
return [] |
|
628 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
629 |
# print mod_list |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
630 |
# print deps |
371 | 631 |
|
632 |
ordered_deps = [] |
|
633 |
last_len = -1 |
|
634 |
while deps: |
|
635 |
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
|
636 |
# print l_deps |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
637 |
if l_deps == last_len: |
371 | 638 |
for m, dl in deps.items(): |
639 |
for d in dl: |
|
640 |
if m in deps.get(d, []): |
|
641 |
raise Exception('Circular Imports found: \n%s %s -> %s %s' |
|
642 |
% (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
|
643 |
# raise Exception('Could not calculate dependencies: \n%s' % deps) |
371 | 644 |
break |
645 |
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
|
646 |
# print "modlist", mod_list |
371 | 647 |
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
|
648 |
# print "nodeps", nodeps |
371 | 649 |
mod_list = filter(lambda x: x not in nodeps, mod_list) |
650 |
newdeps = {} |
|
651 |
for k in deps.keys(): |
|
652 |
depslist = deps[k] |
|
653 |
depslist = filter(lambda x: x not in nodeps, depslist) |
|
654 |
if depslist: |
|
655 |
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
|
656 |
# print "newdeps", newdeps |
371 | 657 |
deps = newdeps |
658 |
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
|
659 |
# time.sleep(0) |
371 | 660 |
|
661 |
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
|
662 |
ordered_deps.append(mod_list) # last dependencies - usually the app(s) |
371 | 663 |
|
664 |
ordered_deps.reverse() |
|
665 |
||
666 |
return ordered_deps |
|
667 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
668 |
|
371 | 669 |
def main(): |
670 |
global app_platforms |
|
671 |
||
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
672 |
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
|
673 |
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
|
674 |
"-o", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
675 |
"--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 |
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
|
677 |
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
|
678 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
679 |
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
|
680 |
"-j", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
681 |
"--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
|
682 |
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
|
683 |
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
|
684 |
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
|
685 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
686 |
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
|
687 |
"-I", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
688 |
"--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
|
689 |
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
|
690 |
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
|
691 |
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
|
692 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
693 |
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
|
694 |
"-D", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
695 |
"--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 |
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
|
697 |
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
|
698 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
699 |
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
|
700 |
"-m", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
701 |
"--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
|
702 |
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
|
703 |
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
|
704 |
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
|
705 |
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
|
706 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
707 |
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
|
708 |
"-P", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
709 |
"--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 |
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
|
711 |
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
|
712 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
713 |
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
|
714 |
"-d", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
715 |
"--debug", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
716 |
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
|
717 |
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
|
718 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
719 |
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
|
720 |
"-O", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
721 |
"--optimize", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
722 |
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
|
723 |
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
|
724 |
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
|
725 |
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
|
726 |
) |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
727 |
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
|
728 |
"-c", |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1771
diff
changeset
|
729 |
"--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
|
730 |
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
|
731 |
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
|
732 |
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
|
733 |
) |
371 | 734 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
735 |
parser.set_defaults(output="output", js_includes=[], library_dirs=[], |
371 | 736 |
platforms=(','.join(app_platforms)), |
737 |
data_dir=os.path.join(sys.prefix, "share/pyjamas"), |
|
738 |
dynamic=False, |
|
739 |
cache_buster=False, |
|
740 |
debug=False) |
|
741 |
(options, args) = parser.parse_args() |
|
742 |
if len(args) != 1: |
|
743 |
parser.error("incorrect number of arguments") |
|
744 |
||
745 |
data_dir = abspath(options.data_dir) |
|
746 |
||
747 |
app_path = args[0] |
|
748 |
if app_path.endswith('.py'): |
|
749 |
app_path = abspath(app_path) |
|
750 |
if not isfile(app_path): |
|
751 |
parser.error("Application file not found %r" % app_path) |
|
752 |
app_path, app_name = split(app_path) |
|
753 |
app_name = app_name[:-3] |
|
754 |
pyjs.path.append(app_path) |
|
755 |
elif os.path.sep in app_path: |
|
756 |
parser.error("Not a valid module declaration %r" % app_path) |
|
757 |
else: |
|
758 |
app_name = app_path |
|
759 |
||
760 |
for d in options.library_dirs: |
|
761 |
pyjs.path.append(abspath(d)) |
|
762 |
||
763 |
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
|
764 |
app_platforms = options.platforms.split(',') |
371 | 765 |
|
766 |
# this is mostly for getting boilerplate stuff |
|
767 |
data_dir = os.path.abspath(options.data_dir) |
|
768 |
||
769 |
build(app_name, options.output, options.js_includes, |
|
770 |
options.debug, options.dynamic and 1 or 0, data_dir, |
|
771 |
options.cache_buster, options.optimize) |
|
772 |
||
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
|
773 |
|
371 | 774 |
if __name__ == "__main__": |
775 |
main() |