diff --git a/scripts/package.py b/scripts/package.py --- a/scripts/package.py +++ b/scripts/package.py @@ -11,11 +11,46 @@ template_directory = pathlib.Path("PackageTemplates/") macos_template = template_directory / "isometric-park-template.app" windows_template = template_directory / "isometric-park-windows-template" +linux_template = template_directory / "isometric-park-linux-template" sourcedir = "isometric-park-fna/bin/Release" destination_directory = pathlib.Path("isometric-park-fna/bin/") +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 + destination = pathlib.Path(new_name) / os.path.relpath(sourcedir, dirpath) / pathlib.Path(file) + + print(source, destination) + + 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(): + 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") + + 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: + for (dirpath, _dirname, files) in os.walk(sourcedir): + for file in files: + source = pathlib.Path(dirpath) / file + f.write(source) + + def make_windows(suffix="new"): new_name = destination_directory / (windows_template.name[:-9] + "-" + suffix) # shutil.rmtree(new_name) @@ -28,7 +63,10 @@ print(source, destination) - if source.is_dir() and not destination.exists(): + 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(): shutil.copytree(source, destination) else: shutil.copy2(source, destination) @@ -58,11 +96,14 @@ for (dirpath, _dirname, files) in os.walk(sourcedir): for file in files: source = pathlib.Path(dirpath) / file - destination = new_name / "Contents" / "Resources" / pathlib.Path(file) + destination = new_name / "Contents" / "Resources" / os.path.relpath(dirpath, sourcedir) / file print(source, destination) - if source.is_dir() and not destination.exists(): + 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(): shutil.copytree(source, destination) else: shutil.copy2(source, destination)