2015-09-21 19:53:37 +00:00
import sys
from distutils . core import setup
import py2exe
import os
from glob import glob
2015-09-23 20:35:04 +00:00
import zipfile
import shutil
2015-09-21 19:53:37 +00:00
"""
This setup is not meant to build pupy stubs , but only to generate an adequate library . zip to embed in the real exe / dll stub
please don ' t use this if you don ' t want to recompile from sources
NOTE : I had to manually change pyreadline / console / console . py to console2 . py and edit __init__ . py to change the import because I had a conflict
2015-10-25 12:18:25 +00:00
"""
print " NOTE: you must install the following packages before proceeding: "
print """
- pywin32
- pycrypto
- pyaml ( scramblesuit dependency )
2015-09-21 19:53:37 +00:00
"""
2015-09-23 20:35:04 +00:00
if not ( len ( sys . argv ) == 3 and sys . argv [ 1 ] == " genzip " ) :
2015-09-21 19:53:37 +00:00
exit ( " This setup is not meant to build pupy stubs, but only to generate an adequate library.zip to embed in the real exe/dll stub \n please don ' t use this if you don ' t want to recompile from sources " )
2015-09-23 20:35:04 +00:00
if sys . argv [ 2 ] == ' x86 ' :
outname = ' x86 '
2015-10-23 17:16:11 +00:00
platform = ' 32 '
2015-09-23 20:35:04 +00:00
elif sys . argv [ 2 ] == ' x64 ' :
outname = ' x64 '
2015-10-23 17:16:11 +00:00
platform = ' -amd64 '
2015-09-23 20:35:04 +00:00
else :
exit ( ' unsupported platform ' )
2015-09-21 19:53:37 +00:00
sys . argv = [ sys . argv [ 0 ] , " py2exe " ]
2015-10-01 20:10:56 +00:00
# put necessary library patches/includes/whatever in this directory
2015-10-23 17:16:11 +00:00
sys . path . insert ( 0 , os . path . join ( " sources " , " resources " , " library_patches " ) )
sys . path . insert ( 0 , os . path . join ( " .. " , " pupy " ) )
2015-10-01 20:10:56 +00:00
2015-09-21 19:53:37 +00:00
setup (
2015-10-23 17:16:11 +00:00
#data_files = [(".", glob(r'.\RESOURCES_x86\msvcr90.dll'))],
console = [ ' .. \\ pupy \\ pp.py ' ] ,
2015-09-21 19:53:37 +00:00
#windows=['reverse_ssl.py'],
#zipfile=None,
options = { " py2exe " : {
2016-01-08 21:50:14 +00:00
" packages " : [ ' additional_imports ' , ' Crypto ' ] ,
2015-09-21 19:53:37 +00:00
" compressed " : True ,
2015-09-23 20:35:04 +00:00
" bundle_files " : 3 , #3 = don't bundle (default) 2 = bundle everything but the Python interpreter 1 = bundle everything
2016-01-08 21:50:14 +00:00
" excludes " : [ " Tkinter " , " pyreadline " , " IPython " , " readline " ]
2015-09-21 19:53:37 +00:00
}
}
)
2015-09-23 20:35:04 +00:00
excluded_files = [
' crypt32.dll ' ,
' library.zip ' ,
' mswsock.dll ' ,
' python27.dll ' ,
2015-10-23 17:16:11 +00:00
' pp.exe ' ,
' w9xpopen.exe ' ,
2015-09-23 20:35:04 +00:00
]
2015-10-23 17:16:11 +00:00
2015-09-23 20:35:04 +00:00
def zwalk ( path , zf ) :
for root , dirs , files in os . walk ( path ) :
for file in files :
if file . lower ( ) in excluded_files :
pass
2015-10-23 17:16:11 +00:00
elif file . endswith ( ' .pyd ' ) and " . " in file . rsplit ( " . " , 1 ) [ 0 ] :
arch_path = " / " . join ( file . rsplit ( " . " , 1 ) [ 0 ] . split ( ' . ' ) )
zf . write ( os . path . join ( root , file ) , arcname = arch_path + " .pyd " )
2015-09-23 20:35:04 +00:00
else :
zf . write ( os . path . join ( root , file ) )
with zipfile . ZipFile ( ' sources/resources/library %s .zip ' % outname , ' w ' , zipfile . ZIP_DEFLATED ) as zf :
root = os . getcwd ( )
2015-10-23 17:16:11 +00:00
os . chdir ( ' build/bdist.win %s /winexe/collect-2.7 ' % platform )
2015-09-23 20:35:04 +00:00
zwalk ( ' . ' , zf )
os . chdir ( ' %s /dist ' % root )
zwalk ( ' . ' , zf )
print ' cleaning up '
os . chdir ( root )
shutil . rmtree ( ' build ' )
shutil . rmtree ( ' dist ' )