-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpack.py
More file actions
71 lines (65 loc) · 2.24 KB
/
Copy pathpack.py
File metadata and controls
71 lines (65 loc) · 2.24 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
import info
skip = (
"export_config.txt",
"pack-server.py",
".gitignore",
"README.md",
"title.png",
"info.py",
)
if __name__ == "__main__":
import zipfile
import os
os.chdir(os.path.dirname(__file__))
if os.path.isfile("Create-Applied-Machine.jar"):
import subprocess
print("改用本地打包方式")
if not os.path.isdir("./dist"):
os.mkdir("./dist")
with zipfile.ZipFile(f"./dist/{info.out}", "w") as zf:
for path in (
subprocess.run(
("git", "ls-files"), capture_output=True, text=True, check=True
)
.stdout.strip()
.split("\n")
):
# 简化打包内容
if (
".github" in path
or ".gitignore" in path
or "LICENSE" in path
or ".md" in path in path
or ".py" in path
or "export_config.txt" in path
):
continue
zf.write(
path,
(
None
if path == "modrinth.index.json"
else os.path.join("overrides", path)
),
)
print(f"完成!\n已保存至: ./dist/Create-Applied-Machine-{info.out}")
else:
import pathlib
import shutil
os.mkdir("./output")
shutil.move("./src/modrinth.index.json", "./output/modrinth.index.json")
shutil.move("./src/CHANGELOG.md", "./output/CHANGELOG.md")
shutil.move("./src/LICENSE", "./output/LICENSE")
for root, _, files in os.walk("./src"):
if ".git" in root or ".github" in root or "__pycache__" in root:
continue
for file in files:
if file in skip:
continue
path = os.path.join(root, file)
to = os.path.join(
"./output/overrides",
pathlib.Path().joinpath(*pathlib.Path(path).parts[1:]),
)
os.makedirs(os.path.dirname(to), exist_ok=True)
shutil.move(path, to)