From 68021762c704ebee713caa9622bffe36471800f6 Mon Sep 17 00:00:00 2001 From: insolor <2442833+insolor@users.noreply.github.com> Date: Sun, 30 Jun 2024 16:55:03 +0300 Subject: [PATCH] Basic package building --- .gitignore | 2 ++ app.py | 47 +++++++++++++++++++++++++++++++++ package_build/download_parts.py | 5 ++++ package_build/models.py | 4 +++ 4 files changed, 58 insertions(+) diff --git a/.gitignore b/.gitignore index 2dc53ca..facf90a 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,5 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ + +*.zip \ No newline at end of file diff --git a/app.py b/app.py index 589fa94..d219e17 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,6 @@ +import shutil +from pathlib import Path + import streamlit as st from package_build.download_parts import download_parts @@ -34,3 +37,47 @@ with st.status("Downloading files...", expanded=True) as status: parts = download_parts(hook_info, dict_entry) status.update(label="Download complete!", state="complete", expanded=False) + + with st.status("Building package...", expanded=True) as status: + root_dir = Path(__file__).parent + build_dir = root_dir / "build" + shutil.rmtree(build_dir) + build_dir.mkdir(parents=True) + + package_name_no_extension = "dfint" + package_path = root_dir / f"{package_name_no_extension}.zip" + package_path.unlink(missing_ok=True) + package_path_without_extension = root_dir / "dfint" + + (build_dir / hook_info.dfhooks_name).write_bytes(parts.dfhooks) + + lib_name = "dfhooks_dfint.dll" if operating_systems.startswith("win") else "libdfhooks_dfint.so" + (build_dir / lib_name).write_bytes(parts.library) + + dfint_data_dir = build_dir / "dfint-data" + dfint_data_dir.mkdir() + + (dfint_data_dir / "config.toml").write_bytes(parts.config) + (dfint_data_dir / "offsets.toml").write_bytes(parts.offsets) + + (dfint_data_dir / "dictionary.csv").write_bytes(parts.csv_file) + (dfint_data_dir / "encoding.toml").write_bytes(parts.encoding_config) + + art_dir = build_dir / "data" / "art" + art_dir.mkdir(parents=True) + (art_dir / "curses_640x300.png").write_bytes(parts.font_file) + + shutil.make_archive( + package_name_no_extension, + format="zip", + base_dir=build_dir.relative_to(root_dir), + ) + + status.update(label="Package ready!", state="complete", expanded=False) + + st.download_button( + label="Download package", + file_name=package_path.name, + data=package_path.read_bytes(), + mime="application/zip", + ) diff --git a/package_build/download_parts.py b/package_build/download_parts.py index 02ac1b2..237ed65 100644 --- a/package_build/download_parts.py +++ b/package_build/download_parts.py @@ -14,6 +14,7 @@ def download(url: str) -> bytes: class DownloadedParts(NamedTuple): library: bytes + dfhooks: bytes config: bytes offsets: bytes csv_file: bytes @@ -26,6 +27,9 @@ def download_parts(hook_info: HookInfoEntry, dict_info: DictInfoEntry) -> Downlo st.write("Download library...") library = download(hook_info.lib) + st.write("Download dfhooks library...") + dfhooks = download(hook_info.dfhooks) + st.write("Download config...") config = download(hook_info.config) @@ -43,6 +47,7 @@ def download_parts(hook_info: HookInfoEntry, dict_info: DictInfoEntry) -> Downlo return DownloadedParts( library=library, + dfhooks=dfhooks, config=config, offsets=offsets, csv_file=csv_file, diff --git a/package_build/models.py b/package_build/models.py index d31becf..eef76c0 100644 --- a/package_build/models.py +++ b/package_build/models.py @@ -13,6 +13,10 @@ class HookInfoEntry(BaseConfiguredModel): offsets: str dfhooks: str + @property + def dfhooks_name(self) -> str: + return self.dfhooks.rpartition("/")[-1] + class DictInfoEntry(BaseConfiguredModel): language: str