Skip to content

Commit

Permalink
Basic package building
Browse files Browse the repository at this point in the history
  • Loading branch information
insolor committed Jun 30, 2024
1 parent bf91ab2 commit 6802176
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 47 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import shutil
from pathlib import Path

import streamlit as st

from package_build.download_parts import download_parts
Expand Down Expand Up @@ -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",
)
5 changes: 5 additions & 0 deletions package_build/download_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def download(url: str) -> bytes:

class DownloadedParts(NamedTuple):
library: bytes
dfhooks: bytes
config: bytes
offsets: bytes
csv_file: bytes
Expand All @@ -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)

Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions package_build/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6802176

Please sign in to comment.