aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-06-18 16:27:29 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-06-18 16:27:29 -0700
commit0b2ef820afa027b66358d9cf4b535af25136c606 (patch)
tree1b9286758c5ac7bd7169aabac00e32db32d43126 /tools
parentb72e2aaedfc3df159312fda3b2ecd355584e7281 (diff)
do not recrunch if dds is unchanged
Diffstat (limited to 'tools')
-rw-r--r--tools/file_packager.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/tools/file_packager.py b/tools/file_packager.py
index 1e96361c..4a3d8030 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -18,6 +18,8 @@ Notes:
be added to convert the crn to dds in the browser.
crunch-worker.js will be generated in the current directory. You should include that file when
packaging your site.
+ DDS files will not be crunched if the .crn is more recent than the .dds. This prevents a lot of
+ unneeded computation.
TODO: You can also provide .crn files yourself, pre-crunched. With this option, they will be decompressed
to dds files in the browser, exactly the same as if this tool compressed them.
@@ -156,9 +158,13 @@ if crunch:
for file_ in data_files:
if file_['name'].endswith(CRUNCH_INPUT_SUFFIX):
- # TODO: do not crunch if crunched version exists and is more recent than dds source
- Popen([CRUNCH, '-file', file_['name'], '-quality', crunch], stdout=sys.stderr).communicate()
+ # Do not crunch if crunched version exists and is more recent than dds source
crunch_name = unsuffixed(file_['name']) + CRUNCH_OUTPUT_SUFFIX
+ crunch_time = os.stat(crunch_name).st_mtime
+ dds_time = os.stat(file_['name']).st_mtime
+ if dds_time < crunch_time: continue
+
+ Popen([CRUNCH, '-file', file_['name'], '-quality', crunch], stdout=sys.stderr).communicate()
shutil.move(os.path.basename(crunch_name), crunch_name) # crunch places files in the current dir
# prepend the dds header
crunched = open(crunch_name, 'rb').read()