2016-10-22 15:40:11 +00:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
2018-01-13 17:54:06 +00:00
|
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
|
|
|
|
print "ROOT: ", ROOT
|
|
|
|
|
2018-08-09 08:54:09 +00:00
|
|
|
PATCHES = os.path.join(ROOT, 'pupy', 'library_patches')
|
2016-11-29 16:53:39 +00:00
|
|
|
|
|
|
|
sys.path.insert(0, PATCHES)
|
2018-01-13 17:54:06 +00:00
|
|
|
sys.path.append(os.path.join(ROOT, 'pupy'))
|
|
|
|
sys.path.append(os.path.join(ROOT, 'pupy', 'pupylib'))
|
|
|
|
|
2018-06-19 18:12:06 +00:00
|
|
|
|
|
|
|
sys.path.append(os.path.join(ROOT, 'pupy', 'packages', 'all'))
|
|
|
|
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
sys.path.append(os.path.join(ROOT, 'pupy', 'packages', 'windows', 'all'))
|
|
|
|
elif sys.platform.startswith('linux'):
|
|
|
|
sys.path.append(os.path.join(ROOT, 'pupy', 'packages', 'linux', 'all'))
|
|
|
|
sys.path.append(os.path.join(ROOT, 'pupy', 'packages', 'posix', 'all'))
|
|
|
|
else:
|
|
|
|
sys.path.append(os.path.join(ROOT, 'pupy', 'packages', 'posix', 'all'))
|
|
|
|
|
2018-01-13 17:54:06 +00:00
|
|
|
from PupyCompile import pupycompile
|
2016-10-22 15:40:11 +00:00
|
|
|
|
|
|
|
import additional_imports
|
|
|
|
import Crypto
|
2018-09-23 20:03:04 +00:00
|
|
|
import idna
|
2016-10-22 15:40:11 +00:00
|
|
|
import pp
|
2016-11-29 16:53:39 +00:00
|
|
|
import site
|
2018-01-13 17:54:06 +00:00
|
|
|
import marshal
|
2016-11-29 16:53:39 +00:00
|
|
|
|
2016-12-02 17:29:14 +00:00
|
|
|
sys_modules = [
|
|
|
|
(x,sys.modules[x]) for x in sys.modules.keys()
|
|
|
|
]
|
|
|
|
|
2018-01-13 17:54:06 +00:00
|
|
|
fileid = 0
|
|
|
|
compile_map = {}
|
|
|
|
|
|
|
|
def compile_py(path):
|
|
|
|
global compile_map
|
|
|
|
global fileid
|
|
|
|
|
|
|
|
compile_map[fileid] = path
|
2018-02-28 21:12:26 +00:00
|
|
|
data = pupycompile(path, 'f:{:x}'.format(fileid), path=True)
|
|
|
|
print "[C] {} -> f:{:x}".format(path, fileid)
|
2018-01-13 17:54:06 +00:00
|
|
|
fileid += 1
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
2016-10-22 15:40:11 +00:00
|
|
|
all_dependencies=set(
|
|
|
|
[
|
2016-12-02 17:29:14 +00:00
|
|
|
x.split('.')[0] for x,m in sys_modules \
|
2017-04-04 07:51:56 +00:00
|
|
|
if not '(built-in)' in str(m) and x != '__main__'
|
2016-10-22 15:40:11 +00:00
|
|
|
] + [
|
2018-09-23 20:03:04 +00:00
|
|
|
'Crypto', 'rpyc', 'pyasn1', 'rsa', 'stringprep'
|
2016-10-22 15:40:11 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2016-11-29 16:53:39 +00:00
|
|
|
all_dependencies.add('site')
|
|
|
|
|
|
|
|
all_dependencies = sorted(list(set(all_dependencies)))
|
2016-10-22 15:40:11 +00:00
|
|
|
all_dependencies.remove('pupy')
|
|
|
|
all_dependencies.remove('additional_imports')
|
2018-02-14 10:16:14 +00:00
|
|
|
|
|
|
|
ignore = {
|
|
|
|
'_cffi_backend.so', '_cffi_backend.pyd',
|
|
|
|
'network/lib/picocmd/server.py',
|
|
|
|
'network/lib/transports/cryptoutils/pyaes/__init__.py',
|
|
|
|
'network/lib/transports/cryptoutils/pyaes/aes.py',
|
|
|
|
'network/lib/transports/cryptoutils/pyaes/blockfeeder.py',
|
|
|
|
'network/lib/transports/cryptoutils/pyaes/util.py',
|
|
|
|
'rpyc/utils/teleportation.py',
|
|
|
|
'rpyc/utils/zerodeploy.py',
|
|
|
|
'rpyc/experemental/__init__.py',
|
|
|
|
'rpyc/experemental/retunnel.py',
|
|
|
|
'rpyc/experemental/splitbrain.py',
|
|
|
|
'json/tool.py',
|
|
|
|
'rsa/cli.py',
|
|
|
|
}
|
|
|
|
|
|
|
|
if sys.platform.startswith('linux'):
|
|
|
|
ignore.update({
|
|
|
|
'psutil/_pswindows.py'
|
|
|
|
})
|
|
|
|
elif sys.platform.startswith('win'):
|
|
|
|
ignore.update({
|
|
|
|
'_psaix.py',
|
|
|
|
'_psbsd.py',
|
|
|
|
'_pslinux.py',
|
|
|
|
'_psosx.py',
|
|
|
|
'_pssunos.py'
|
|
|
|
})
|
|
|
|
|
|
|
|
for dep in ('cffi', 'pycparser', 'pyaes'):
|
|
|
|
if dep in all_dependencies:
|
|
|
|
all_dependencies.remove(dep)
|
2016-10-22 15:40:11 +00:00
|
|
|
|
|
|
|
print "ALLDEPS: ", all_dependencies
|
|
|
|
|
|
|
|
from distutils.core import setup
|
|
|
|
from glob import glob
|
|
|
|
import zipfile
|
|
|
|
import shutil
|
2016-11-29 16:53:39 +00:00
|
|
|
|
2017-07-03 19:55:03 +00:00
|
|
|
zf = zipfile.ZipFile(sys.argv[1], mode='w', compression=zipfile.ZIP_DEFLATED)
|
2016-10-22 15:40:11 +00:00
|
|
|
|
|
|
|
if 'win' in sys.platform:
|
2017-02-11 01:08:32 +00:00
|
|
|
for root, _, files in os.walk(r'C:\Python27\Lib\site-packages'):
|
|
|
|
for file in files:
|
|
|
|
if file.lower() == 'pywintypes27.dll':
|
|
|
|
zf.write(os.path.join(root, file), 'pywintypes27.dll')
|
2016-10-22 15:40:11 +00:00
|
|
|
|
|
|
|
try:
|
2018-02-14 10:16:14 +00:00
|
|
|
content = set(ignore)
|
2016-10-22 15:40:11 +00:00
|
|
|
for dep in all_dependencies:
|
|
|
|
mdep = __import__(dep)
|
|
|
|
print "DEPENDENCY: ", dep, mdep
|
2016-11-29 15:27:04 +00:00
|
|
|
if hasattr(mdep, '__path__') and getattr(mdep, '__path__'):
|
|
|
|
print('adding package %s / %s'%(dep, mdep.__path__))
|
2016-10-22 15:40:11 +00:00
|
|
|
path, root = os.path.split(mdep.__path__[0])
|
|
|
|
for root, dirs, files in os.walk(mdep.__path__[0]):
|
|
|
|
for f in list(set([x.rsplit('.',1)[0] for x in files])):
|
|
|
|
found=False
|
2018-03-12 15:08:23 +00:00
|
|
|
need_compile=True
|
2018-01-13 17:54:06 +00:00
|
|
|
for ext in ('.dll', '.so', '.pyd', '.py', '.pyc', '.pyo'):
|
|
|
|
if ( ext == '.pyc' or ext == '.pyo' ) and found:
|
2016-10-22 15:40:11 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
pypath = os.path.join(root,f+ext)
|
|
|
|
if os.path.exists(pypath):
|
2018-03-12 15:08:23 +00:00
|
|
|
ziproot = root[len(path)+1:].replace('\\', '/')
|
|
|
|
zipname = '/'.join([ziproot, f.split('.', 1)[0] + ext])
|
|
|
|
found = True
|
|
|
|
|
|
|
|
if ziproot.startswith('site-packages'):
|
|
|
|
ziproot = ziproot[14:]
|
2016-10-22 15:40:11 +00:00
|
|
|
|
2017-04-04 07:51:56 +00:00
|
|
|
if zipname.startswith('network/transports/') and \
|
|
|
|
not zipname.startswith('network/transports/__init__.py'):
|
|
|
|
continue
|
|
|
|
|
2016-10-22 15:40:11 +00:00
|
|
|
# Remove various testcases if any
|
2016-10-25 05:51:37 +00:00
|
|
|
if any([ '/'+x+'/' in zipname for x in [
|
2017-04-20 21:01:06 +00:00
|
|
|
'tests', 'test', 'SelfTest', 'SelfTests', 'examples',
|
|
|
|
'experimental'
|
2016-10-25 05:51:37 +00:00
|
|
|
]
|
|
|
|
]):
|
2016-10-22 15:40:11 +00:00
|
|
|
continue
|
|
|
|
|
2016-11-20 21:07:00 +00:00
|
|
|
if zipname in content:
|
|
|
|
continue
|
2018-01-13 17:54:06 +00:00
|
|
|
|
2018-03-12 15:08:23 +00:00
|
|
|
file_root = root
|
|
|
|
|
2018-01-13 17:54:06 +00:00
|
|
|
if os.path.exists(os.path.join(PATCHES, f+'.py')):
|
|
|
|
print('found [PATCH] for {}'.format(f))
|
2018-03-12 15:08:23 +00:00
|
|
|
file_root = PATCHES
|
|
|
|
ext = '.py'
|
|
|
|
elif os.path.exists(os.path.sep.join([PATCHES] + zipname.split('/'))):
|
|
|
|
print('found [PATCH ZROOT] for {}'.format(f))
|
|
|
|
file_root = os.path.sep.join([PATCHES] + ziproot.split('/'))
|
2018-01-13 17:54:06 +00:00
|
|
|
ext = '.py'
|
2016-11-29 16:53:39 +00:00
|
|
|
|
2016-10-22 15:40:11 +00:00
|
|
|
print('adding file : {}'.format(zipname))
|
2016-11-20 21:07:00 +00:00
|
|
|
content.add(zipname)
|
2018-01-13 17:54:06 +00:00
|
|
|
|
2018-03-12 15:08:23 +00:00
|
|
|
if ext == '.py' and need_compile:
|
2018-01-13 17:54:06 +00:00
|
|
|
zf.writestr(
|
|
|
|
zipname+'o',
|
2018-03-12 15:08:23 +00:00
|
|
|
compile_py(os.path.join(file_root,f+ext)))
|
2018-01-13 17:54:06 +00:00
|
|
|
else:
|
2018-03-12 15:08:23 +00:00
|
|
|
zf.write(os.path.join(file_root,f+ext), zipname)
|
|
|
|
|
|
|
|
break
|
2016-10-22 15:40:11 +00:00
|
|
|
else:
|
|
|
|
if '<memimport>' in mdep.__file__:
|
|
|
|
continue
|
|
|
|
|
2016-11-29 16:53:39 +00:00
|
|
|
found_patch = None
|
2018-01-13 17:54:06 +00:00
|
|
|
for extp in ( '.py', '.pyc', '.pyo' ):
|
2016-11-29 16:53:39 +00:00
|
|
|
if os.path.exists(os.path.join(PATCHES, dep+extp)):
|
|
|
|
found_patch = (os.path.join(PATCHES, dep+extp), extp)
|
|
|
|
break
|
|
|
|
|
|
|
|
if found_patch:
|
2017-04-12 13:03:33 +00:00
|
|
|
if dep+found_patch[1] in content:
|
|
|
|
continue
|
|
|
|
|
2016-11-29 16:53:39 +00:00
|
|
|
print('adding [PATCH] %s -> %s'%(found_patch[0], dep+found_patch[1]))
|
2018-01-13 17:54:06 +00:00
|
|
|
if found_patch[0].endswith('.py'):
|
|
|
|
zf.writestr(
|
|
|
|
dep+found_patch[1]+'o',
|
|
|
|
compile_py(found_patch[0]))
|
|
|
|
else:
|
|
|
|
zf.write(found_patch[0], dep+found_patch[1])
|
|
|
|
|
2016-11-29 16:53:39 +00:00
|
|
|
else:
|
|
|
|
_, ext = os.path.splitext(mdep.__file__)
|
2017-04-12 13:03:33 +00:00
|
|
|
if dep+ext in content:
|
|
|
|
continue
|
|
|
|
|
2016-11-29 16:53:39 +00:00
|
|
|
print('adding %s -> %s'%(mdep.__file__, dep+ext))
|
2018-01-13 17:54:06 +00:00
|
|
|
if mdep.__file__.endswith(('.pyc', '.pyo', '.py')):
|
|
|
|
srcfile = mdep.__file__
|
|
|
|
if srcfile.endswith(('.pyc', '.pyo')):
|
|
|
|
srcfile = srcfile[:-1]
|
|
|
|
|
|
|
|
zf.writestr(dep+'.pyo', compile_py(srcfile))
|
|
|
|
else:
|
|
|
|
zf.write(mdep.__file__, dep+ext)
|
2016-10-22 15:40:11 +00:00
|
|
|
|
|
|
|
finally:
|
2018-01-13 17:54:06 +00:00
|
|
|
zf.writestr('fid.toc', marshal.dumps(compile_map))
|
2016-10-22 15:40:11 +00:00
|
|
|
zf.close()
|