@@ -63,7 +63,7 @@ def get_iscc_exe():
6363 # drive+r'PortableApps\NSISPortableANSI',
6464 #drive+r'PortableApps\NSISPortable',
6565 # osp.join(localdir, 'NSISPortableANSI'),
66- osp .join (localdir , 'NSISPortable ' ),
66+ osp .join (localdir , 'Inno Setup 5 ' ),
6767 ):
6868 for subdirname in ('.' , 'App' ):
6969 exe = osp .join (dirname , subdirname , 'Inno Setup 5' , 'iscc.exe' )
@@ -75,6 +75,23 @@ def get_iscc_exe():
7575
7676ISCC_EXE = get_iscc_exe () # Inno Setup Compiler (iscc.exe)
7777
78+ def get_7zip_exe ():
79+ """Return 7zip executable"""
80+ localdir = osp .join (sys .prefix , os .pardir , os .pardir )
81+ for drive in get_drives ():
82+ for dirname in (r'C:\Program Files' , r'C:\Program Files (x86)' ,
83+ osp .join (localdir , '7-Zip' ),
84+ ):
85+ for subdirname in ('.' , 'App' ):
86+ exe = osp .join (dirname , subdirname , '7-Zip' , '7z.exe' )
87+ # include = osp.join(dirname, subdirname, '7-Zip', 'include')
88+ if osp .isfile (exe ):
89+ return exe
90+ else :
91+ raise RuntimeError ("7-Zip is not installed on this computer." )
92+
93+ SEVENZIP_EXE = get_7zip_exe () # Inno Setup Compiler (iscc.exe)
94+
7895def replace_in_nsis_file (fname , data ):
7996 """Replace text in line starting with *start*, from this position:
8097 data is a list of (start, text) tuples"""
@@ -106,7 +123,25 @@ def replace_in_iss_file(fname, data):
106123 lines [idx ] = line [:len (start )+ 1 ] + ('"%s"' % text ) + '\n '
107124 fd = open (fname , 'w' )
108125 fd .writelines (lines )
109- print ('nsis for ' , fname , 'is' , lines )
126+ print ('Inno Setup for ' , fname , 'is' , lines )
127+ fd .close ()
128+
129+
130+ def replace_in_7zip_file (fname , data ):
131+ """Replace text in line starting with *start*, from this position:
132+ data is a list of (start, text) tuples"""
133+ fd = open (fname , 'U' )
134+ lines = fd .readlines ()
135+ fd .close ()
136+ for idx , line in enumerate (lines ):
137+ for start , text in data :
138+ if start not in ('Icon' , 'OutFile' ) and not start .startswith ('!' ):
139+ start = 'set ' + start
140+ if line .startswith (start + '=' ):
141+ lines [idx ] = line [:len (start )+ 1 ] + ('%s' % text ) + '\n '
142+ fd = open (fname , 'w' )
143+ fd .writelines (lines )
144+ print ('7-zip for ' , fname , 'is' , lines )
110145 fd .close ()
111146
112147
@@ -141,6 +176,24 @@ def build_iss(srcname, dstname, data):
141176 except OSError as e :
142177 print ("Execution failed:" , e , file = sys .stderr )
143178 # os.remove(dstname)
179+
180+ def build_7zip (srcname , dstname , data ):
181+ """7-Zip Setup Script"""
182+ portable_dir = osp .join (osp .dirname (osp .abspath (__file__ )), 'portable' )
183+ shutil .copy (osp .join (portable_dir , srcname ), dstname )
184+ data = [('PORTABLE_DIR' , portable_dir ),('SEVENZIP_EXE' , SEVENZIP_EXE )
185+ ] + list (data )
186+ replace_in_7zip_file (dstname , data )
187+ try :
188+ # insted of a 7zip command line, we launch a script that does it
189+ #retcode = subprocess.call('"%s" "%s"' % (SEVENZIP_EXE, dstname),
190+ retcode = subprocess .call ('"%s" ' % (dstname ),
191+ shell = True , stdout = sys .stderr )
192+ if retcode < 0 :
193+ print ("Child was terminated by signal" , - retcode , file = sys .stderr )
194+ except OSError as e :
195+ print ("Execution failed:" , e , file = sys .stderr )
196+ # os.remove(dstname)
144197
145198
146199class WinPythonDistribution (object ):
@@ -454,6 +507,21 @@ def create_installer_inno(self):
454507 build_iss ('installer_INNO.iss' , fname , data )
455508 self ._print_done ()
456509
510+ def create_installer_7zip (self ):
511+ """Create installer with 7-ZIP"""
512+ self ._print ("Creating WinPython installer 7-ZIP" )
513+ portable_dir = osp .join (osp .dirname (osp .abspath (__file__ )), 'portable' )
514+ fname = osp .join (portable_dir , 'installer_7zip-tmp.bat' )
515+ data = (('DISTDIR' , self .winpydir ),
516+ ('ARCH' , self .winpy_arch ),
517+ ('VERSION' , '%s.%d%s' % (self .python_fullversion ,
518+ self .build_number , self .flavor )),
519+ ('VERSION_INSTALL' , '%s%d' % (self .python_fullversion .replace (
520+ '.' , '' ), self .build_number )),
521+ ('RELEASELEVEL' , self .release_level ),)
522+ build_7zip ('installer_7zip.bat' , fname , data )
523+ self ._print_done ()
524+
457525 def _print (self , text ):
458526 """Print action text indicating progress"""
459527 if self .verbose :
@@ -1572,8 +1640,9 @@ def make_all(build_number, release_level, pyver, architecture,
15721640 my_winpydir = my_winpydir )
15731641 # ,find_links=osp.join(basedir, 'packages.srcreq'))
15741642 if create_installer and not simulation :
1575- # dist.create_installer()
1576- dist .create_installer_inno ()
1643+ #dist.create_installer() # NSIS installer (can't handle big build)
1644+ dist .create_installer_inno () # INNO Setup 5 (not 7zip friendly)
1645+ #dist.create_installer_7zip() # 7-zip (no licence splash screen)
15771646 return dist
15781647
15791648
0 commit comments