-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsgapack-incre.py
More file actions
81 lines (75 loc) · 2.71 KB
/
sgapack-incre.py
File metadata and controls
81 lines (75 loc) · 2.71 KB
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
import subprocess
from os import path, chdir, walk, makedirs
import shutil
import sys
import hashlib
def calculate_file_hash(filepath, hash_algorithm='md5', buffer_size=65536):
"""计算文件的哈希值"""
hash_func = hashlib.new(hash_algorithm)
with open(filepath, 'rb') as f:
while True:
data = f.read(buffer_size)
if not data:
break
hash_func.update(data)
return hash_func.hexdigest()
if path.exists("dist"):
shutil.rmtree("dist")
# 启动进程
cmdline = [sys.executable, "-m", "PyInstaller", "SGAv3.spec"]
result = subprocess.run(cmdline, shell=True, capture_output=True, text=True)
print("stdout, stderr, 返回码:", result.stdout, result.stderr, result.returncode)
if result.returncode:
raise RuntimeError
if not path.exists("release/SGAv3"):
print("未找到参照包体")
exit()
lis = [["dist/SGAv3/_internal", "release/SGAv3/_internal"],
["resources", "release/SGAv3/resources"],
["update.txt", "release/SGAv3/update.txt"],
["readme.md", "release/SGAv3/readme.md"],
["mdpic", "release/SGAv3/mdpic"]]
lis2 = []
for src, drc in lis:
if path.isdir(src):
for root, _, files in walk(src):
# print(root, _, files)
for file in files:
s0 = path.join(root, file)
d0 = s0.replace(src, drc)
if path.exists(s0):
if path.exists(d0) and calculate_file_hash(s0) == calculate_file_hash(d0):
continue
lis2.append([s0, d0])
else:
if path.exists(src):
if path.exists(drc) and calculate_file_hash(src) == calculate_file_hash(drc):
continue
lis2.append([src, drc])
if lis2:
version = "3.1.2"
_str = f"/SGAv3-{version}-replace/"
if not path.exists(f"release/SGAv3-{version}-replace"):
makedirs(f"release/SGAv3-{version}-replace")
else:
shutil.rmtree(f"release/SGAv3-{version}-replace")
# print(lis2)
for src, drc in lis2:
drc = drc.replace("/SGAv3/", _str)
drcdir = path.split(drc)[0]
if not path.exists(drcdir):
makedirs(drcdir)
shutil.copyfile(src, drc)
chdir("release")
rar_path = "D:/Program Files/WinRAR/WinRAR.exe"
cmdline = [rar_path, "a", f"SGAv3-{version}-replace.zip", f"SGAv3-{version}-replace"]
result = subprocess.run(cmdline, shell=True, capture_output=True, text=True)
print("stdout, stderr, 返回码:", result.stdout, result.stderr, result.returncode)
if result.returncode:
raise RuntimeError
chdir("..")
print("sgapack-replace完成")
else:
print("sgapack-replace无更新内容")
if __name__ == "__main__":
...