better zip_static_files.py, thanks Niphlod
This commit is contained in:
1 parent
afbbfd7e46
commit
358ec48d8a
2 files changed
+20
-7
No files matched your search
@@ -1 +1 @@
|
||||
Version 2.0.9 (2012-09-20 11:16:45) stable
|
||||
Version 2.0.9 (2012-09-20 11:19:07) stable
|
||||
@@ -3,14 +3,11 @@
|
||||
|
||||
## launch with python web2py.py -S myapp -R scripts/zip_static_files.py
|
||||
|
||||
ALLOWED_EXTS = ['.css', '.js']
|
||||
|
||||
import os
|
||||
import gzip
|
||||
static_path = os.path.abspath(os.path.join(request.folder, 'static'))
|
||||
filelist = []
|
||||
for root, dir, files in os.walk(static_path):
|
||||
for file in files:
|
||||
filelist.append(os.path.join(root, file))
|
||||
|
||||
def zip_static(filelist=[]):
|
||||
tsave = 0
|
||||
for fi in filelist:
|
||||
extension = os.path.splitext(fi)
|
||||
@@ -21,6 +18,12 @@ for fi in filelist:
|
||||
fstats = os.stat(fi)
|
||||
atime, mtime = fstats.st_atime, fstats.st_mtime
|
||||
gfi = fi + '.gz'
|
||||
if os.path.isfile(gfi):
|
||||
zstats = os.stat(gfi)
|
||||
zatime, zmtime = zstats.st_atime, zstats.st_mtime
|
||||
if zatime == atime and zmtime == mtime:
|
||||
print 'skipping %s, already gzipped to the latest version' % os.path.basename(fi)
|
||||
continue
|
||||
print 'gzipping %s to %s' % (os.path.basename(fi), os.path.basename(gfi))
|
||||
f_in = open(fi, 'rb')
|
||||
f_out = gzip.open(gfi, 'wb')
|
||||
@@ -32,3 +35,13 @@ for fi in filelist:
|
||||
tsave+= saved
|
||||
|
||||
print 'saved %s KB' % (int(tsave)/1000.0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
ALLOWED_EXTS = ['.css', '.js']
|
||||
static_path = os.path.abspath(os.path.join(request.folder, 'static'))
|
||||
filelist = []
|
||||
for root, dir, files in os.walk(static_path):
|
||||
for file in files:
|
||||
filelist.append(os.path.join(root, file))
|
||||
|
||||
zip_static(filelist)
|
||||
Reference in new issue
Block a user