Show More
Commit Description:
Add source support to packager.
Commit Description:
Add source support to packager.
References:
File last commit:
Show/Diff file:
Action:
scripts/package.py
112 lines | 3.6 KiB | text/x-python | PythonLexer
112 lines | 3.6 KiB | text/x-python | PythonLexer
r22 | #!/bin/env python3 | |||
import zipfile | ||||
import sys | ||||
import shutil | ||||
r24 | import tempfile | |||
import subprocess | ||||
r22 | import os | |||
import pathlib | ||||
macos_template = "isometric-park-fna/bin/isometric-park-template.app" | ||||
windows_template = "isometric-park-fna/bin/isometric-park-windows-template" | ||||
r23 | sourcedir = "isometric-park-fna/bin/Release" | |||
r22 | ||||
r24 | ||||
r22 | def make_windows(suffix="new"): | |||
r24 | new_name = windows_template[:-9] + "-" + suffix | |||
r23 | # shutil.rmtree(new_name) | |||
shutil.copytree(windows_template, new_name) | ||||
for (dirpath, _dirname, files) in os.walk(sourcedir): | ||||
for file in files: | ||||
source = pathlib.Path(dirpath) / file | ||||
destination = pathlib.Path(new_name) / os.path.relpath(sourcedir, dirpath) / pathlib.Path(file) | ||||
print(source, destination) | ||||
r22 | ||||
r23 | if source.is_dir() and not destination.exists(): | |||
shutil.copytree(source, destination) | ||||
else: | ||||
shutil.copy2(source, destination) | ||||
shutil.move(pathlib.Path(new_name) / "isometric-park-fna.exe", | ||||
pathlib.Path(new_name) / "isometric-park.exe") | ||||
with zipfile.ZipFile(new_name + ".zip", "w", | ||||
#Windows doesn't natively support other formats | ||||
#(besides uncompressed) in my testing: | ||||
compression=zipfile.ZIP_DEFLATED) as f: | ||||
for (dirpath, _dirname, files) in os.walk(sourcedir): | ||||
for file in files: | ||||
source = pathlib.Path(dirpath) / file | ||||
f.write(source) | ||||
r22 | ||||
r24 | ||||
r22 | def make_macos(suffix="new"): | |||
new_name = macos_template[:-4] + "-" + suffix + ".app" + "/" | ||||
r23 | # shutil.rmtree(new_name) | |||
r22 | shutil.copytree(macos_template, new_name) | |||
r23 | for (dirpath, _dirname, files) in os.walk(sourcedir): | |||
r22 | for file in files: | |||
source = pathlib.Path(dirpath) / file | ||||
destination = pathlib.Path(new_name) / "Contents" / "Resources" / pathlib.Path(file) | ||||
print(source, destination) | ||||
if source.is_dir() and not destination.exists(): | ||||
shutil.copytree(source, destination) | ||||
else: | ||||
shutil.copy2(source, destination) | ||||
shutil.move(pathlib.Path(new_name) / "Contents" / "Resources" / "isometric-park-fna.exe", | ||||
pathlib.Path(new_name) / "Contents" / "Resources" / "isometric-park.exe") | ||||
r24 | def make_source(suffix="new"): | |||
new_name = "isometric-park-fna/bin/isometric-park-source" + "-" + suffix | ||||
with tempfile.TemporaryDirectory() as temp: | ||||
print(subprocess.getoutput(f"hg clone . {temp}")) | ||||
with zipfile.ZipFile(new_name + ".zip", "w", | ||||
#Windows doesn't natively support other formats | ||||
#(besides uncompressed) in my testing: | ||||
compression=zipfile.ZIP_DEFLATED) as f: | ||||
for (dirpath, _dirname, files) in os.walk(temp): | ||||
for file in files: | ||||
source = pathlib.Path(dirpath) / file | ||||
print(os.path.relpath(source, temp)) | ||||
f.write(source, os.path.relpath(source, temp) ) | ||||
r22 | def main(): | |||
if len(sys.argv) > 1: | ||||
command = sys.argv[1] | ||||
r23 | if command.lower() == "macos": | |||
r22 | if len(sys.argv) > 2: | |||
make_macos(sys.argv[2]) | ||||
r23 | else: | |||
make_macos() | ||||
elif command.lower() in ("win", "windows"): | ||||
if len(sys.argv) > 2: | ||||
make_windows(sys.argv[2]) | ||||
else: | ||||
make_windows() | ||||
r24 | elif command.lower() == "source": | |||
if len(sys.argv) > 2: | ||||
make_source(sys.argv[2]) | ||||
else: | ||||
make_source() | ||||
r22 | else: | |||
pass | ||||
if __name__ == '__main__': | ||||
main() | ||||