forked from iWangJiaxiang/autosub
-
Notifications
You must be signed in to change notification settings - Fork 246
/
create_release.py
187 lines (170 loc) · 6.8 KB
/
create_release.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Defines release creation scripts.
"""
# Import built-in modules
import os
import sys
import shlex
import shutil
import subprocess
# Import third-party modules
# Any changes to the path and your own modules
def copytree(src,
dst,
symlinks=False,
ignore=None,
exts=None,
is_recursive=False):
if not exts:
for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
if is_recursive:
shutil.copytree(s, d, symlinks, ignore)
else:
os.makedirs(os.path.join(dst, s))
else:
shutil.copy2(s, d)
else:
path_stack = [src, ]
while len(path_stack) > 0:
path = path_stack.pop()
if os.path.isdir(path):
for item in os.listdir(path):
abs_path = os.path.join(path, item)
if os.path.isdir(item):
if is_recursive:
path_stack.append(abs_path)
else:
continue
else:
path_stack.append(abs_path)
else:
rel_path = os.path.relpath(path, src)
for ext in exts:
if path.endswith(ext):
dst_path = os.path.join(dst, rel_path)
rel_dir = os.path.dirname(dst_path)
if not os.path.isdir(rel_dir):
os.makedirs(rel_dir)
shutil.copy2(path, dst_path)
if __name__ == "__main__":
release_name = "autosub"
package_name = release_name
here = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
os.chdir(here)
pyinstaller_dist_path = ".build_and_dist/pyinstaller.build"
dist_path = ".build_and_dist"
if not os.path.isdir(dist_path):
os.makedirs(dist_path)
metadata = {}
with open(os.path.join(here, package_name, "metadata.py"), encoding='utf-8') as metafile:
exec(metafile.read(), metadata)
target = os.path.join(here, ".release", package_name)
target_nuitka = os.path.join(target, package_name)
target_data = os.path.join(target_nuitka, "data")
target_pyi = target + "_pyinstaller"
target_data_pyi = os.path.join(target_pyi, "data")
if os.path.isdir(target):
shutil.rmtree(target)
os.makedirs(target)
if os.path.isdir(target_pyi):
shutil.rmtree(target_pyi)
os.makedirs(target_pyi)
# command = "pipreqs --encoding=utf-8 --force --savepath requirements.txt {}".format(package_name)
# print(command)
# if sys.platform.startswith('win'):
# args = command
# else:
# args = shlex.split(command)
# p = subprocess.Popen(args,
# stdout=subprocess.PIPE,
# stderr=subprocess.PIPE)
# out, err = p.communicate()
# if out:
# print(out.decode(sys.stdout.encoding))
# if err:
# print(err.decode(sys.stdout.encoding))
copytree(src=here, dst=target, exts=[".md", ".txt"])
target_docs = os.path.join(target, "docs")
os.makedirs(target_docs)
copytree(src="docs", dst=target_docs, is_recursive=True)
shutil.copy2("LICENSE", target)
copytree(src=target, dst=target_pyi, is_recursive=True)
shutil.copy2(".build_and_dist/pyinstaller.build/{}.exe".format(release_name), target_pyi)
copytree(src="scripts/release_files_pyi", dst=target_pyi, is_recursive=True)
copytree(src="scripts/release_files", dst=target, is_recursive=True)
os.makedirs(target_data)
os.makedirs(target_data_pyi)
copytree(src="{}/data".format(package_name), dst=target_data, exts=[".mo"],
is_recursive=True)
copytree(src="{}/data".format(package_name), dst=target_data_pyi, exts=[".mo"],
is_recursive=True)
copytree(src=".build_and_dist/{}.dist".format(release_name), dst=target_nuitka,
is_recursive=True)
exe_dir = "binaries"
if os.path.isdir(exe_dir):
ffmpeg_norm_nuitka = os.path.join(exe_dir, "ffmpeg-normalize-Nuitka",
"ffmpeg-normalize.exe")
ffmpeg_norm_pyinstaller = os.path.join(exe_dir, "ffmpeg-normalize-pyinstaller",
"ffmpeg-normalize.exe")
if os.path.isfile(ffmpeg_norm_nuitka) and os.path.isfile(ffmpeg_norm_pyinstaller):
shutil.copy2(ffmpeg_norm_nuitka, target_nuitka)
shutil.copy2(ffmpeg_norm_pyinstaller, target_pyi)
shutil.copy2("binaries/ffmpeg.exe", target_nuitka)
shutil.copy2("binaries/ffprobe.exe", target_nuitka)
shutil.copy2("binaries/ffmpeg.exe", target_pyi)
shutil.copy2("binaries/ffprobe.exe", target_pyi)
command = "7z a -sdel \".release/{release_name}-{version}-win-x64-nuitka.7z\" \"{target}\"".format(
release_name=release_name,
version=metadata['VERSION'],
target=target)
print(command)
if sys.platform.startswith('win'):
args = command
else:
args = shlex.split(command)
p = subprocess.Popen(args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
if out:
print(out.decode(sys.stdout.encoding))
if err:
print(err.decode(sys.stdout.encoding))
command = "7z a -sdel \".release/{release_name}-{version}-win-x64-pyinstaller.7z\"" \
" \"{target_pyi}\"".format(
release_name=release_name,
version=metadata['VERSION'],
target_pyi=target_pyi)
print(command)
if sys.platform.startswith('win'):
args = command
else:
args = shlex.split(command)
p = subprocess.Popen(args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
if out:
print(out.decode(sys.stdout.encoding))
if err:
print(err.decode(sys.stdout.encoding))
command = "python scripts/generate_sha256.py .release"
print(command)
if sys.platform.startswith('win'):
args = command
else:
args = shlex.split(command)
p = subprocess.Popen(args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
if out:
print(out.decode(sys.stdout.encoding))
if err:
print(err.decode(sys.stdout.encoding))
input("输入任何字符以退出:")