-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_win_installer.py
55 lines (47 loc) · 1.6 KB
/
create_win_installer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import os.path
import subprocess
import shutil
pyfile = os.path.join(os.curdir, 'biostata.py')
if not os.path.exists(pyfile):
raise Exception("The script should be run within project root directory")
if os.name != 'nt':
raise Exception("The script should be run on windows platform only")
# get version number
fn = os.path.join(os.curdir, 'prog', '__init__.py')
fid = open(fn, 'r')
version = None
for line in fid.readlines():
if line.find('version = ') >= 0:
exec(line)
break
fid.close()
if version is None:
raise Exception("Failed to detect version from prog/bopts.py file")
print("Detected version is ", version)
# write version number to nsi file
fn = os.path.join(os.curdir, 'make_installer.nsi')
fid = open(fn, 'r')
lines = fid.readlines()
fid.close()
for i, line in enumerate(lines):
if line.find('!define VERSION ') >= 0:
lines[i] = '!define VERSION "{}"\r\n'.format(version)
break
else:
raise Exception("Version string was not found in make_installer.nsi")
fid = open(fn, 'w')
fid.writelines(lines)
fid.close()
# run pyinstaller
subprocess.call(["python", "-O", "-m", "PyInstaller",
"-y", "-w", "--clean", "-i"
'{}'.format(os.path.join(os.curdir,
'resources',
'biostata256.ico')),
"biostata.py"])
# rename biostata.exe to Biostata.exe
shutil.move('dist\\biostata\\biostata.exe', 'dist\\biostata\\Biostata.exe')
# run nsis
subprocess.call(["C:\\Program Files (x86)\\NSIS\\makensis.exe",
"make_installer.nsi"])