-
Notifications
You must be signed in to change notification settings - Fork 3
/
makemsi.py
73 lines (63 loc) · 2.23 KB
/
makemsi.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!python
import argparse
import os
import subprocess
import sys
def invoke(command):
_command = ' '.join(command)
print(_command)
p = subprocess.Popen(_command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
stdout, stderr = p.communicate()
if p.returncode:
print('%s failed:' % command[0])
if stderr:
print(stderr.decode('utf-8'))
if stdout:
print(stdout.decode('utf-8'))
sys.exit(p.returncode)
def main(args=None):
parser = argparse.ArgumentParser()
parser.add_argument('-o', dest='output')
parser.add_argument('-x', dest='extensions', action='store_true',
help='Use UI, Util extensions')
parser.add_argument('options', nargs='*', metavar='OPTION',
help='An option in the form NAME or NAME=VALUE')
parser.add_argument('wxsname', metavar='WXSNAME',
help='The base name of the WiX source file')
cmdline = parser.parse_args(args)
wxsname = cmdline.wxsname
if cmdline.output:
msiname = cmdline.output
else:
msiname = wxsname
wxsfn = '%s.wxs' % wxsname
objfn = '%s.wixobj' % wxsname
opts = cmdline.options
plats = [opt for opt in opts if opt.startswith('Platform=')]
if not plats:
opts.append('Platform=x86')
if 'Platform=x64' in plats:
msifn = '%s.amd64.msi' % msiname
pdbfn = '%s.amd64.wixpdb' % msiname
else:
msifn = '%s.msi' % msiname
pdbfn = '%s.wixpdb' % msiname
if opts:
opts = ['-d %s' % opt for opt in opts]
# We use WiX v4
if cmdline.extensions:
opts.extend([
'-ext', 'WixToolset.UI.wixext',
'-ext', 'WixToolset.Util.wixext'
]) # '-cultures:en-us'
invoke(['wix', 'build', '-o', msifn] + opts + [wxsfn])
os.remove(pdbfn)
pwd = os.environ.get('SIGNPWD', '').strip()
if pwd:
invoke(['sign', '/d', 'Python Launcher Installer', msifn])
return 0
if __name__ == '__main__':
sys.exit(main())