-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
92 lines (73 loc) · 2.67 KB
/
setup.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
'''
cd /d z:
cd dropbox/codes/easy_paste
py setup.py --install-now
'''
# Verpatch is needed to supplement PyInstaller's Python 3 version info bug
# Dictionary names and keys are taken from py2exe settings
dict_console = {
'author': 'Shun Sakurai',
'dest_base': 'Easy Paste',
'icon_resources': [(1, './icons/easy_paste_icon.ico')],
'script': 'easy_paste.py',
'version': '2.0.6'
}
dict_options = {
'excludes': [
'_bz2', '_frozen_importlib', '_lzma', 'argparse',
'pdb', 'pickle', 'pydoc', 'pyexpat', 'pyreadline']
}
def print_with_border(message):
border = '='
length = 20
print(border * length, message, border * length)
def zero_pad(str_ver):
list_ver = str_ver.split('.')
str_ver2 = str_ver + '.0' * (4 - len(list_ver))
return str_ver2
if __name__ == "__main__":
import os
import shutil
import subprocess
import sys
folder_dist = 'dist'
list_excluded = []
for lib in dict_options['excludes']:
list_excluded.append('--exclude-module')
list_excluded.append(lib)
list_pyinstaller = [
'pyinstaller', '--onefile',
'--icon', dict_console['icon_resources'][0][1],
'--name', dict_console['dest_base']
] + list_excluded + [dict_console['script']]
list_verpatch = [
'verpatch', ''.join([folder_dist, '/', dict_console['dest_base'], '.exe']),
zero_pad(dict_console['version']),
'/va', '/pv', zero_pad(dict_console['version']),
'/s', 'copyright', '©2016-2018 ' + dict_console['author']
]
list_iscc = ['C:\Program Files (x86)\Inno Setup 5\iscc', 'setup_installer.iss']
if os.path.exists(folder_dist):
shutil.rmtree(folder_dist)
print_with_border('Running PyInstaller')
subprocess.run(list_pyinstaller)
# '--add-data' doesn't work with '--onefile'
print_with_border('Running Verpatch')
subprocess.run(list_verpatch)
print_with_border('Running Inno Setup')
subprocess.run(list_iscc)
print_with_border('Cleaning')
if os.path.exists('__pycache__'):
shutil.rmtree('__pycache__')
if os.path.exists('build'):
shutil.rmtree('build')
if os.path.exists(''.join([dict_console['dest_base'], '.spec'])):
os.remove(''.join([dict_console['dest_base'], '.spec']))
print('Executable and installer for v' + dict_console['version'], 'created.')
if sys.argv[-1] == '--install-now':
subprocess.run([
'start',
''.join([
'Output/easy_paste_installer_',
zero_pad(dict_console['version']), '.exe'
])], shell=True)