diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-06-11 12:50:53 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-06-11 13:19:25 -0700 |
commit | 4fe6e47928fa1f095a0f35a230cda4a9e9cb448b (patch) | |
tree | 75555f293eeab257de208c9b2c2c32bc28397eaf /tools/shared.py | |
parent | 3eac624d13e8edfe3a3d141b12beb2b43fb657e1 (diff) |
refactor file packaging into standalone tool
Diffstat (limited to 'tools/shared.py')
-rw-r--r-- | tools/shared.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/shared.py b/tools/shared.py index f71bec72..3e2ce04e 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -131,6 +131,7 @@ BINDINGS_GENERATOR = path_from_root('tools', 'bindings_generator.py') EXEC_LLVM = path_from_root('tools', 'exec_llvm.py') VARIABLE_ELIMINATOR = path_from_root('tools', 'eliminator', 'eliminator.coffee') JS_OPTIMIZER = path_from_root('tools', 'js-optimizer.js') +FILE_PACKAGER = path_from_root('tools', 'file_packager.py') # Temp dir. Create a random one, unless EMCC_DEBUG is set, in which case use TEMP_DIR/emscripten_temp @@ -932,3 +933,28 @@ class Cache: shutil.copyfile(creator(), cachename) return cachename +# Compression of code and data for smaller downloads +class Compression: + on = False + + @staticmethod + def compressed_name(filename): + return filename + '.compress' + + @staticmethod + def compress(filename): + execute(Compression.encoder, stdin=open(filename, 'rb'), stdout=open(Compression.compressed_name(filename), 'wb')) + + @staticmethod + def worth_it(original, compressed): + return compressed < original - 1500 # save at least one TCP packet or so + +def execute(cmd, *args, **kw): + try: + return subprocess.Popen(cmd, *args, **kw).communicate() # let compiler frontend print directly, so colors are saved (PIPE kills that) + except: + if not isinstance(cmd, str): + cmd = ' '.join(cmd) + print >> sys.stderr, 'Invoking Process failed: <<< ' + cmd + ' >>>' + raise + |