-
Notifications
You must be signed in to change notification settings - Fork 294
/
Copy pathcodepuppy.spec
145 lines (137 loc) · 4.73 KB
/
codepuppy.spec
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
142
143
144
145
# -*- mode: python -*-
'''
pyinstaller script to package the codepuppy
usage: pyinstaller codepuppy.spec
'''
import os
import sys
import platform
#--------------------------------------------------------------------------------------------
# 1st step: get path set
path_set = []
path_set.append(os.path.abspath(os.curdir))
# --------------------------------------------------------------------------------------------
# 2nd step: get module set
def get_file_list(path, prefix=None):
import os
path_set = []
for root,dirs,files in os.walk(path):
for filename in files:
if filename.startswith('_'):
continue
if filename.endswith('.py'):
path_set.append(os.path.join(root, filename))
for dirname in dirs:
if dirname.startswith('_'):
continue
if root.find('.'):
continue
path_set.append(os.path.join(root, dirname))
module_set = []
for file_path in path_set:
file_path = os.path.relpath(file_path, path)
file_path = file_path.replace('.py', '').replace('/', '.').replace('\\', '.')
if prefix:
prefix = prefix.replace('\\', '.').replace('/', '.')
file_path = '%s.%s' % (prefix, file_path)
module_set.append(file_path)
return module_set
def get_cpython_suffix():
if sys.platform.startswith("linux"):
if platform.machine() == "aarch64":
return "-aarch64-linux-gnu.so"
else:
return "-x86_64-linux-gnu.so"
elif sys.platform.startswith(("win32", "cygwin")):
return ".pyd"
elif sys.platform.startswith("darwin"):
return "-darwin.so"
else:
return ".so"
def get_cpython_file_list(root_dir, suffix=None):
root_dir = os.path.abspath(root_dir)
if type(suffix) == str:
suffix = [suffix]
binary_set = []
for root, dirs, files in os.walk(root_dir):
for filename in files:
if filename.endswith(tuple(suffix)):
path = os.path.join(root, filename)
rel_dirpath = os.path.relpath(os.path.dirname(path), start=root_dir)
prefix = rel_dirpath.replace('\\', '.').replace('/', '.')
binary_set.append("%s.%s" % (prefix, filename.split('.')[0]))
return binary_set
block_cipher = None
self_tool_module = get_file_list('tool','tool')
self_setting_module = get_file_list('settings','settings')
self_util_module = get_file_list('util', 'util')
self_task_module = get_file_list('task', 'task')
self_node_module = get_file_list('node', 'node')
third_party_module = ['psutil', 'yaml', 'html5lib', 'pyaes', 'pymongo', 'openpyxl', 'rsa', 'tqdm']
cpython_files = get_cpython_file_list('.', suffix=get_cpython_suffix())
total_set = []
total_set.extend(self_tool_module)
total_set.extend(self_setting_module)
total_set.extend(self_util_module)
total_set.extend(self_task_module)
total_set.extend(self_node_module)
total_set.extend(third_party_module)
total_set.extend(cpython_files)
# ------------------------------------------------------------------------------------------------
# 3th step: pack task.puppytask bin
a = Analysis(['task/puppytask.py'],
pathex=path_set,
binaries=[],
datas=[],
hiddenimports=total_set,
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='scantask',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )
# ------------------------------------------------------------------------------------------------
# 4th step: pack codepuppy bin
a = Analysis(['codepuppy.py'],
pathex=path_set,
binaries=[],
datas=[],
hiddenimports=total_set,
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='codepuppy',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )