X Tutup
Skip to content

Commit 2e9fd3e

Browse files
committed
include 7zip installer logic
1 parent 6d07f54 commit 2e9fd3e

File tree

4 files changed

+132
-6
lines changed

4 files changed

+132
-6
lines changed

make.py

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

7676
ISCC_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+
7895
def 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

146199
class 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

portable/installer.nsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
WinPython installer script
44
5-
Copyright © 2012 Pierre Raybaut
5+
Copyright © 2012 Pierre Raybaut, 2016+ WinPython team
66
Licensed under the terms of the MIT License
77
(see winpython/__init__.py for details)
88

portable/installer_7zip.bat

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
rem Copyright © 2018 WinPython team
2+
rem Licensed under the terms of the MIT License
3+
rem (see winpython/__init__.py for details)
4+
5+
rem This is to do a 7-zip installer
6+
7+
rem ================================================================
8+
rem These lines are automatically replaced when creating installer:
9+
rem (see winpython/make.py)
10+
set SEVENZIP_EXE=C:\Program Files (x86)\7-Zip\7z
11+
set DISTDIR=C:\WinP\bd36\buPs2\winp64-3.6.x.0
12+
set ARCH=64
13+
set VERSION=3.6.7.0Ps2
14+
15+
rem 2018-04-04 need to minimize path length of installation further: remove flavor in install path
16+
17+
set VERSION_INSTALL=3670
18+
19+
set RELEASELEVEL=beta3
20+
set PORTABLE_DIR=C:\WinPython-64bit-3.4.3.7Qt5\winpython_github20181029\portable
21+
22+
rem ================================================================
23+
rem these lines are static definitions
24+
set ID=Winpython
25+
set ID_INSTALL=WPy
26+
set FILE_DESCRIPTION=%ID% Installer
27+
set COMPANY=%ID%
28+
set BRANDING=%ID%, the portable Python Distribution for Scientists
29+
set COPYRIGHT=Copyright © 2018+ WinPython Team
30+
set MyAppPublisher=WinPython team
31+
set MyAppURL=https://winpython.github.io/
32+
33+
rem OutputBaseFilename "{#ID}{#ARCH}-{#VERSION}{#RELEASELEVEL}"
34+
35+
rem ================================================================ [Setup]
36+
rem OutFile "${DISTDIR}\..\${ID}${ARCH}-${VERSION}${RELEASELEVEL}.exe"
37+
set MyBinaryOutputDir=%DISTDIR%\..
38+
set OutputBaseFilename=%ID%%ARCH%-%VERSION%%RELEASELEVEL%
39+
40+
rem 7-zip uncompress the directory compressed %DISTDIR% (no option to change it in gui)
41+
42+
43+
echo %time%
44+
45+
rem compression + include auto_extract in GUI mode
46+
"%SEVENZIP_EXE%" -mx5 a "%MyBinaryOutputDir%\%OutputBaseFilename%.exe" %DISTDIR% -sfx7z.sfx
47+
48+
49+
50+
echo autoextract using command line options
51+
echo "%MyBinaryOutputDir%\%OutputBaseFilename%.exe" -y -o%MyBinaryOutputDir%\zz > NUL
52+
53+
rem -mx1 = speed fastest
54+
rem -mx3 = speed fast
55+
rem -mx5 = speed normal
56+
rem -mx7 = compress maximum
57+
rem -mx9 = compress ultra

winpython/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
OTHER DEALINGS IN THE SOFTWARE.
2929
"""
3030

31-
__version__ = '1.11.20181031'
31+
__version__ = '1.11.20181222'
3232
__license__ = __doc__
3333
__project_url__ = 'http://winpython.github.io/'

0 commit comments

Comments
 (0)
X Tutup