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