Commits

Ronny Pfannschmidt committed e62210e

add mapping compression code

  • Participants
  • Parent commits 682b6b6

Comments (0)

Files changed (1)

File genscript/pkgpacker.py

 import py
+import pickle
+import zlib
+import base64
 
 def find_toplevel(name):
     for syspath in py.std.sys.path:
         pkg = pkgname(name, toplevel, pyfile)
         name2src[pkg] = pyfile.read()
     return name2src
+
+
+def compress_mapping(mapping):
+    data = pickle.dumps(mapping, 2)
+    data = zlib.compress(data, 9)
+    data = base64.encodestring(data)
+    data = data.decode('ascii')
+    return data
+
+
+def compress_packages(names):
+    mapping = {}
+    for name in names:
+        mapping.update(pkg_to_mapping(name))
+    return compress_mapping(mapping)
+
+
+