2015-09-21 19:53:37 +00:00
|
|
|
#!/usr/bin/env python
|
2016-10-21 16:21:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2020-01-02 07:00:26 +00:00
|
|
|
|
2020-05-01 17:35:36 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import zipfile
|
2016-11-26 09:20:33 +00:00
|
|
|
import struct
|
2015-09-21 19:53:37 +00:00
|
|
|
|
2020-01-02 07:00:26 +00:00
|
|
|
from io import open
|
|
|
|
|
|
|
|
|
2018-03-02 19:49:51 +00:00
|
|
|
def get_encoded_library_string(filepath, out):
|
2020-05-01 17:35:36 +00:00
|
|
|
dest = os.path.dirname(filepath)
|
|
|
|
if not os.path.exists(dest):
|
|
|
|
os.makedirs(dest)
|
2016-10-21 16:21:54 +00:00
|
|
|
|
2020-05-01 17:35:36 +00:00
|
|
|
zip = zipfile.ZipFile(open(filepath, 'rb'))
|
2015-09-21 19:53:37 +00:00
|
|
|
|
2020-05-01 17:35:36 +00:00
|
|
|
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
|
|
|
|
2020-05-01 17:35:36 +00:00
|
|
|
ks = len(modules)
|
|
|
|
out.write(struct.pack('>I', ks))
|
|
|
|
for module in modules:
|
|
|
|
content = modules[module]
|
2015-09-21 19:53:37 +00:00
|
|
|
|
2020-05-01 17:35:36 +00:00
|
|
|
out.write(struct.pack('>II', len(module), len(content)))
|
|
|
|
out.write(module)
|
|
|
|
out.write(content)
|
2016-10-21 16:21:54 +00:00
|
|
|
|
2020-01-02 07:00:26 +00:00
|
|
|
|
2020-05-01 17:35:36 +00:00
|
|
|
with open(sys.argv[1], 'wb') as w:
|
|
|
|
get_encoded_library_string(sys.argv[2], w)
|