forked from LaughingLeader/BG3ModManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildRelease.py
60 lines (50 loc) · 1.44 KB
/
BuildRelease.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
import os
import sys
from pathlib import Path
import shutil
import zipfile
from zipfile import ZipFile
import contextlib
def get_arg(arg, fallback):
if len(sys.argv) > arg:
val = sys.argv[arg]
if val != None:
return val
return fallback
script_dir = Path(os.path.dirname(os.path.abspath(__file__)))
os.chdir(script_dir)
version = get_arg(1, None)
file_name = "BG3ModManager_v{}.zip".format(version)
export_file = "BG3ModManager_Latest.zip"
print("Writing release zip:{}".format(file_name))
def zipdir(src, zip_name):
ziph = zipfile.ZipFile(zip_name, 'w')
for root, dirs, files in os.walk(src):
for file in files:
ziph.write(os.path.join(root, file), arcname=os.path.join(root.replace(src, ""), file), compress_type=zipfile.ZIP_DEFLATED)
ziph.close()
def SilentRemove(f):
try:
if Path(f).is_dir():
shutil.rmtree(f, ignore_errors=True)
else:
os.remove(f)
print("Removed {}".format(f))
except Exception as e:
print(e)
def SilentCopyAndRemove(source, dest):
with contextlib.suppress(FileNotFoundError, PermissionError):
shutil.copy(source, dest)
if Path(source).is_dir():
shutil.rmtree(source, ignore_errors=True)
else:
os.remove(source)
print("Removed {}".format(source))
import time
time.sleep(3)
SilentRemove("bin/Publish/Data")
SilentRemove("bin/Publish/Orders")
SilentRemove("bin/Publish/_Logs")
SilentRemove(file_name)
zipdir("bin/Publish", file_name)
shutil.copy(file_name, export_file)