-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_standalone.py
141 lines (102 loc) · 3.4 KB
/
build_standalone.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
"""
Build the standalone installer
"""
# Standard Library Imports
import argparse
from itertools import chain
import logging
import os
import platform
import posixpath
from subprocess import check_call, CalledProcessError
# In House
from tools import Pushd, data_files, restore_icon
DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)))
LOG = logging.getLogger(__name__)
def _build_standalone_installer(name, entrypoint, icon, one_file=True):
"""
Build a standalone installer using pyinstaller
"""
with Pushd(DIR):
add_data = list(chain(*[
('--add-data',
data_file + ';' + posixpath.normpath(posixpath.dirname(data_file)))
for data_file in data_files()
]))
# Either file or directory outputs from pyinstaller
output_type = '-F' if one_file else '-D'
paths = r"--paths=src\panoptoindexconnector;src\panoptoindexconnector\implementations"
cmd = [
'pyinstaller',
entrypoint,
'--name', name,
'--icon', icon,
paths,
output_type,
'--version-file', 'version_info',
'--clean', '-y',
] + add_data
return_code = 0
print('Using pyinstaller found at')
check_call(['where', 'pyinstaller'])
print('Running:', ' '.join(cmd))
try:
check_call(cmd)
except CalledProcessError as cpe:
LOG.exception(cpe)
return_code = cpe.returncode
return return_code
#################################
#
# Script handling
#
#################################
def build_verb(args):
# pylint: disable=unused-argument
"""
Verb to build the standalone installer.
Assumes pre-requisites have been installed outside of this.
"""
# Fetch panopto icon
icon = restore_icon()
# Run PyInstaller
return _build_standalone_installer(
name='panopto-connector',
entrypoint='src/panoptoindexconnector/connector.py',
icon=icon,
one_file=args.one_file
)
def main():
"""
Entrypoint
"""
major, minor = map(int, platform.python_version_tuple()[:2])
assert major >= 3 and minor >= 4, "Only supports python >= 3.4"
args = parse_args()
set_logger(args)
return_code = build_verb(args)
if return_code:
raise SystemExit(return_code)
def parse_args():
"""Parse commandline arguments."""
# Description
parser = argparse.ArgumentParser(description='Build the standalone Windows Search DB Installer.')
# Logging level
parser.add_argument('-d', '--debug', help='Set debug level logging.', action='store_true')
# Add new arguments here: https://docs.python.org/2/howto/argparse.html
parser.add_argument('--one-file', choices=['on', 'off'], default='on',
help='Enable or disable one-file distribution build.')
args = parser.parse_args()
args.one_file = args.one_file == 'on'
return args
def set_logger(args):
"""Set the logging level and format"""
# Add logging setup here
log_format = '%(asctime)s %(levelname)-8s%(module)25s - %(message)s'
log_date_format = '%H:%M:%S' # briefs
logging_level = logging.DEBUG if args.debug else logging.INFO
# Set main level
logging.basicConfig(format=log_format, level=logging_level, datefmt=log_date_format)
if __name__ == '__main__':
main()