This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
106 lines (85 loc) · 2.9 KB
/
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
"""Script to automate build of BGForce releases.
Intended only for the framework releases, CAN be safely deleted on your game!"""
import os
from pathlib import Path
import shutil
import glob
PROJECT = "bgforce"
VERSION = [0, 1, 0]
curPath = Path(__file__).parent.resolve()
releaseTarget = curPath / ("release/" + PROJECT + "-v" + ".".join([str(i) for i in VERSION]))
def deletePath(_path):
# type: (Path) -> None
if _path.is_file():
_path.unlink()
elif _path.is_dir():
shutil.rmtree(_path)
if releaseTarget.exists():
shutil.rmtree(releaseTarget)
releaseTarget.mkdir(parents=True)
data = {
"OverwriteString": "$COMMENT\n{\n \n}\n",
"CreatePaths": [
"./sounds/sfx/DELETE-ME",
],
"CopyPaths": [
"./database",
"./lang",
"./fonts",
"./scripts",
"./sounds/bgm",
"./textures",
"./.gitignore",
"./LibBgf.blend",
"./Game.blend",
"./ScnMenu.blend",
],
"OverwritePaths": [],
"Ignore": [
"__pycache__",
".git",
]
} # type: dict[str, list[str]]
for pathStr in data["CreatePaths"]:
source = Path(pathStr)
target = releaseTarget / source
os.makedirs((releaseTarget / source).parent, exist_ok=True)
if target.exists():
target.unlink()
target.touch()
for pathStr in data["CopyPaths"]:
source = Path(pathStr)
if source.exists():
if source.is_file():
os.makedirs((releaseTarget / source).parent, exist_ok=True)
shutil.copy2(source, releaseTarget / source)
print("> Copied:", source)
elif source.is_dir():
shutil.copytree(curPath / source, releaseTarget / source)
print(" > Copied:", source)
else:
print("X Copy path do not exist:", source)
for path in data["OverwritePaths"]:
source = Path(path)
target = releaseTarget / source
target.unlink(missing_ok=True)
if source.exists() and source.is_file():
os.makedirs((releaseTarget / source).parent, exist_ok=True)
targetFileContent = data["OverwriteString"] # type: str
with open(source.as_posix(), "r", encoding="utf-8") as openedFile:
comment = ""
sourceFileContent = openedFile.read().splitlines(keepends=True)
for line in sourceFileContent:
if line.strip().startswith("//"):
comment += line
else:
break
targetFileContent = targetFileContent.replace("$COMMENT", comment)
with open(target.as_posix(), "w", encoding="utf-8") as openedFile:
openedFile.write(targetFileContent)
for pattern in data["Ignore"]:
ignoredPath = releaseTarget / ("**/" + pattern)
ignoredPaths = glob.glob(ignoredPath.as_posix(), recursive=True)
for ignored in ignoredPaths:
deletePath(Path(ignored))
print("X Removed ignored:", ignored)