many pep8 improvements
This commit is contained in:
1 parent
71ec15190b
commit
6aa5edc7ff
117 files changed
+7160
-5670
No files matched your search
@@ -14,24 +14,27 @@ import os
|
||||
import hashlib
|
||||
import re
|
||||
|
||||
|
||||
def read_binary_file(filename):
|
||||
f = open(filename,'rb')
|
||||
f = open(filename, 'rb')
|
||||
data = f.read()
|
||||
f.close()
|
||||
return data
|
||||
|
||||
def write_binary_file(filename,data):
|
||||
f =open(filename,'wb')
|
||||
|
||||
def write_binary_file(filename, data):
|
||||
f = open(filename, 'wb')
|
||||
f.write(data)
|
||||
f.close()
|
||||
|
||||
def fix_links(css,static_path):
|
||||
|
||||
def fix_links(css, static_path):
|
||||
return re.sub(r'url\((["\'])\.\./', 'url(\\1' + static_path, css)
|
||||
|
||||
|
||||
|
||||
|
||||
def minify(files, path_info, folder, optimize_css, optimize_js,
|
||||
ignore_concat = [],
|
||||
ignore_minify = ['/jquery.js', '/anytime.js']):
|
||||
ignore_concat=[],
|
||||
ignore_minify=['/jquery.js', '/anytime.js']):
|
||||
|
||||
"""
|
||||
Input:
|
||||
@@ -45,7 +48,7 @@ def minify(files, path_info, folder, optimize_css, optimize_js,
|
||||
Returns a new list of:
|
||||
- filename (absolute or relative, css or js, actual or temporary) or
|
||||
- ('css:inline','...css..')
|
||||
- ('js:inline','...js..')
|
||||
- ('js:inline','...js..')
|
||||
"""
|
||||
optimize_css = optimize_css or ''
|
||||
optimize_js = optimize_js or ''
|
||||
@@ -55,27 +58,27 @@ def minify(files, path_info, folder, optimize_css, optimize_js,
|
||||
concat_js = 'concat' in optimize_js
|
||||
minify_js = 'minify' in optimize_js
|
||||
inline_js = 'inline' in optimize_js
|
||||
static_path,temp = path_info.rsplit('/',1)
|
||||
static_path, temp = path_info.rsplit('/', 1)
|
||||
new_files = []
|
||||
css = []
|
||||
js = []
|
||||
processed = []
|
||||
for k,filename in enumerate(files):
|
||||
for k, filename in enumerate(files):
|
||||
if not filename.startswith('/') or \
|
||||
any(filename.endswith(x) \
|
||||
for x in ignore_concat):
|
||||
any(filename.endswith(x)
|
||||
for x in ignore_concat):
|
||||
new_files.append(filename)
|
||||
continue
|
||||
|
||||
abs_filename = os.path.join(
|
||||
folder,'static', filename[len(static_path)+1:])
|
||||
folder, 'static', filename[len(static_path) + 1:])
|
||||
|
||||
if filename.lower().endswith('.css'):
|
||||
processed.append(filename)
|
||||
spath_info, sfilename = \
|
||||
path_info.split('/'), filename.split('/')
|
||||
u = 0
|
||||
for i,a in enumerate(sfilename):
|
||||
for i, a in enumerate(sfilename):
|
||||
try:
|
||||
if a != spath_info[i]:
|
||||
u = i
|
||||
@@ -99,8 +102,8 @@ def minify(files, path_info, folder, optimize_css, optimize_js,
|
||||
|
||||
if minify_js and \
|
||||
not filename.endswith('.min.js') and \
|
||||
not any(filename.endswith(x) \
|
||||
for x in ignore_minify):
|
||||
not any(filename.endswith(x)
|
||||
for x in ignore_minify):
|
||||
js.append(jsmin.jsmin(contents))
|
||||
else:
|
||||
js.append(contents)
|
||||
@@ -110,32 +113,31 @@ def minify(files, path_info, folder, optimize_css, optimize_js,
|
||||
if css and concat_css:
|
||||
css = '\n\n'.join(contents for contents in css)
|
||||
if not inline_css:
|
||||
temppath = os.path.join(folder,'static',temp)
|
||||
temppath = os.path.join(folder, 'static', temp)
|
||||
if not os.path.exists(temppath):
|
||||
os.mkdir(temppath)
|
||||
dest = "compressed_%s.css" % dest_key
|
||||
tempfile = os.path.join(temppath, dest)
|
||||
write_binary_file(tempfile,css)
|
||||
css = path_info+'/%s' % dest
|
||||
write_binary_file(tempfile, css)
|
||||
css = path_info + '/%s' % dest
|
||||
new_files.append(css)
|
||||
else:
|
||||
new_files.append(('css:inline',css))
|
||||
new_files.append(('css:inline', css))
|
||||
else:
|
||||
new_files += css
|
||||
if js and concat_js:
|
||||
js = '\n'.join(contents for contents in js)
|
||||
if inline_js:
|
||||
js = ('js:inline',js)
|
||||
js = ('js:inline', js)
|
||||
else:
|
||||
temppath = os.path.join(folder,'static',temp)
|
||||
if not os.path.exists(temppath):
|
||||
temppath = os.path.join(folder, 'static', temp)
|
||||
if not os.path.exists(temppath):
|
||||
os.mkdir(temppath)
|
||||
dest = "compressed_%s.js" % dest_key
|
||||
tempfile = os.path.join(folder,'static',temp,dest)
|
||||
write_binary_file(tempfile,js)
|
||||
js = path_info+'/%s' % dest
|
||||
tempfile = os.path.join(folder, 'static', temp, dest)
|
||||
write_binary_file(tempfile, js)
|
||||
js = path_info + '/%s' % dest
|
||||
new_files.append(js)
|
||||
else:
|
||||
new_files += js
|
||||
return new_files
|
||||
|
||||
Reference in new issue
Block a user