Show More
Commit Description:
Add timers for Simulation and various engines...
Commit Description:
Add timers for Simulation and various engines
Starting to add additional timers for different stages of the process of
updating in order to get more insight into what is slowing it down.
The update takes 9ms, which is much longer than it used to.
Engine-specific timers are coming later.
References:
File last commit:
Show/Diff file:
Action:
scripts/package.py
187 lines | 6.9 KiB | text/x-python | PythonLexer
187 lines | 6.9 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 | ||||
r271 | import datetime | |||
r22 | ||||
r25 | template_directory = pathlib.Path("PackageTemplates/") | |||
macos_template = template_directory / "isometric-park-template.app" | ||||
windows_template = template_directory / "isometric-park-windows-template" | ||||
r26 | linux_template = template_directory / "isometric-park-linux-template" | |||
r22 | ||||
r23 | sourcedir = "isometric-park-fna/bin/Release" | |||
r25 | destination_directory = pathlib.Path("isometric-park-fna/bin/") | |||
r22 | ||||
r24 | ||||
r271 | start_date = datetime.datetime(2019, 1, 1) | |||
def months_betweeen(start, end): | ||||
return ((end.year - start.year) * 12) + (end.month - start.month) | ||||
def create_version_string(): | ||||
today = datetime.datetime.today() | ||||
months = months_betweeen(start_date, today) + 1 | ||||
version_string = f"0.{months}.{today.strftime('%d')}" | ||||
print(f"Version string: {version_string}") | ||||
r26 | def make_linux(suffix="new"): | |||
new_name = destination_directory / (linux_template.name[:-9] + "-" + suffix) | ||||
# shutil.rmtree(new_name) | ||||
shutil.copytree(linux_template, new_name) | ||||
for (dirpath, _dirname, files) in os.walk(sourcedir): | ||||
for file in files: | ||||
source = pathlib.Path(dirpath) / file | ||||
r41 | destination = pathlib.Path(new_name) / os.path.relpath(dirpath, sourcedir) / pathlib.Path(file) | |||
r26 | ||||
print(source, destination) | ||||
r41 | os.makedirs(destination.parent, exist_ok=True) | |||
if destination.parent.is_dir() and not destination.parent.exists(): | ||||
r26 | os.mkdir(destination.parent) | |||
elif source.is_dir() and not destination.exists(): | ||||
r41 | print("Copying whole directory!") | |||
r26 | shutil.copytree(source, destination) | |||
else: | ||||
shutil.copy2(source, destination) | ||||
r41 | print(pathlib.Path(new_name) / "isometric-park-fna.exe", | |||
pathlib.Path(new_name) / "isometric-park.exe") | ||||
r26 | shutil.move(pathlib.Path(new_name) / "isometric-park-fna.exe", | |||
pathlib.Path(new_name) / "isometric-park.exe") | ||||
new_zip_name = new_name.parent / (new_name.name + ".zip") | ||||
with zipfile.ZipFile(new_zip_name, "w", | ||||
#May be able to use something better on Linux: | ||||
compression=zipfile.ZIP_DEFLATED) as f: | ||||
r41 | for (dirpath, _dirname, files) in os.walk(new_name): | |||
r26 | for file in files: | |||
source = pathlib.Path(dirpath) / file | ||||
r41 | f.write(source, pathlib.Path(os.path.relpath(sourcedir, dirpath)) / os.path.relpath(dirpath, sourcedir) / pathlib.Path(file)) | |||
# f.write(source, pathlib.Path(os.path.relpath(sourcedir, dirpath)) / os.path.relpath(dirpath, sourcedir) / pathlib.Path(file)) | ||||
r26 | ||||
r22 | def make_windows(suffix="new"): | |||
r25 | new_name = destination_directory / (windows_template.name[:-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 | ||||
r41 | destination = pathlib.Path(new_name) / os.path.relpath(dirpath, sourcedir) / pathlib.Path(file) | |||
r23 | ||||
print(source, destination) | ||||
r22 | ||||
r41 | os.makedirs(destination.parent, exist_ok=True) | |||
r26 | if source.parent.is_dir() and not destination.parent.exists(): | |||
# shutil.copytree(source.parent, destination.parent) | ||||
os.mkdir(destination.parent) | ||||
elif source.is_dir() and not destination.exists(): | ||||
r23 | 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") | ||||
r25 | new_zip_name = new_name.parent / (new_name.name + ".zip") | |||
with zipfile.ZipFile(new_zip_name, "w", | ||||
r23 | #Windows doesn't natively support other formats | |||
#(besides uncompressed) in my testing: | ||||
compression=zipfile.ZIP_DEFLATED) as f: | ||||
r41 | for (dirpath, _dirname, files) in os.walk(new_name): | |||
r23 | for file in files: | |||
source = pathlib.Path(dirpath) / file | ||||
r41 | f.write(source, pathlib.Path(os.path.relpath(sourcedir, dirpath)) / os.path.relpath(dirpath, sourcedir) / pathlib.Path(file)) | |||
r22 | ||||
r24 | ||||
r22 | def make_macos(suffix="new"): | |||
r30 | new_name = destination_directory / (macos_template.name[:-13] + "-" + suffix + ".app" + "/") | |||
r22 | ||||
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 | ||||
r26 | destination = new_name / "Contents" / "Resources" / os.path.relpath(dirpath, sourcedir) / file | |||
r22 | ||||
print(source, destination) | ||||
r26 | if source.parent.is_dir() and not destination.parent.exists(): | |||
# shutil.copytree(source.parent, destination.parent) | ||||
os.mkdir(destination.parent) | ||||
elif source.is_dir() and not destination.exists(): | ||||
r22 | 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"): | |||
r25 | new_name = destination_directory / ("isometric-park-source" + "-" + suffix | |||
+ ".zip") | ||||
r24 | ||||
with tempfile.TemporaryDirectory() as temp: | ||||
print(subprocess.getoutput(f"hg clone . {temp}")) | ||||
r25 | with zipfile.ZipFile(new_name, "w", | |||
r24 | #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)) | ||||
r25 | f.write(source, os.path.relpath(source, temp)) | |||
r24 | ||||
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() | ||||
r41 | elif command.lower() == "linux": | |||
if len(sys.argv) > 2: | ||||
make_linux(sys.argv[2]) | ||||
else: | ||||
make_linux() | ||||
r24 | elif command.lower() == "source": | |||
if len(sys.argv) > 2: | ||||
make_source(sys.argv[2]) | ||||
else: | ||||
make_source() | ||||
r271 | elif command.lower() == "version": | |||
create_version_string() | ||||
r22 | else: | |||
pass | ||||
if __name__ == '__main__': | ||||
main() | ||||