2015-09-21 19:53:37 +00:00
|
|
|
#!/usr/bin/env python
|
2016-10-21 16:21:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-07-03 19:55:03 +00:00
|
|
|
import StringIO, zipfile, os.path, imp, sys, os
|
2015-09-21 19:53:37 +00:00
|
|
|
import marshal
|
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
|
|
|
|
2017-07-03 19:55:03 +00:00
|
|
|
def get_encoded_library_string(filepath):
|
|
|
|
dest = os.path.dirname(filepath)
|
|
|
|
if not os.path.exists(dest):
|
|
|
|
os.makedirs(dest)
|
2016-10-21 16:21:54 +00:00
|
|
|
|
2015-09-21 19:53:37 +00:00
|
|
|
f = StringIO.StringIO()
|
2017-07-03 19:55:03 +00:00
|
|
|
f.write(open(filepath, 'rb').read())
|
2015-09-21 19:53:37 +00:00
|
|
|
|
|
|
|
zip = zipfile.ZipFile(f)
|
|
|
|
|
2016-10-21 16:21:54 +00:00
|
|
|
modules = dict([
|
|
|
|
(z.filename, zip.open(z.filename,).read()) for z in zip.infolist() \
|
|
|
|
if os.path.splitext(z.filename)[1] in [
|
2018-01-13 17:54:06 +00:00
|
|
|
'.py', '.pyd', '.dll', '.pyc', '.pyo', '.so', '.toc'
|
2016-10-21 16:21:54 +00:00
|
|
|
]
|
|
|
|
])
|
2015-09-21 19:53:37 +00:00
|
|
|
|
2016-11-29 16:53:39 +00:00
|
|
|
return marshal.dumps(modules)
|
2016-10-21 16:21:54 +00:00
|
|
|
|
2017-07-03 19:55:03 +00:00
|
|
|
with open(sys.argv[1],'wb') as w:
|
|
|
|
w.write(get_encoded_library_string(sys.argv[2]))
|