Skip to content

Commit

Permalink
Generate single tapto repo
Browse files Browse the repository at this point in the history
  • Loading branch information
wizzomafizzo committed Jan 21, 2024
1 parent 47d39f3 commit 1342a6f
Showing 1 changed file with 13 additions and 92 deletions.
105 changes: 13 additions & 92 deletions scripts/generate_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,13 @@
from zipfile import ZipFile
from typing import TypedDict, Union, Optional, List

APPS = ["lastplayed", "launchseq", "launchsync", "nfc", "playlog", "random", "remote", "search", "pocketbackup"]
FILES = {
"lastplayed": ["lastplayed.sh"],
"launchseq": ["launchseq.sh"],
"launchsync": ["launchsync.sh"],
"nfc": ["nfc.sh", "nfcui.sh"],
"playlog": ["playlog.sh"],
"random": ["random.sh"],
"remote": ["remote.sh"],
"search": ["search.sh"],
"pocketbackup": ["pocketbackup.sh"],
}
REBOOT = ["remote"]
EXTERNAL_FILES = [
"releases/external/bgm.sh",
"releases/external/favorites.sh",
"releases/external/gamesmenu.sh",
]

DB_ID = "mrext/{}"
RELEASES_FOLDER = "releases"
DB_ID = "mrext/tapto"
DL_URL = "https://github.com/wizzomafizzo/tapto/releases/download/{}"
DL_FOLDER = "_bin/releases"
DL_URL = "https://github.com/wizzomafizzo/mrext/releases/download/{}"
EXTERNAL_URL = "https://github.com/wizzomafizzo/mrext/raw/main/releases/external/{}"
FILES = [
"tapto.sh",
"taptui.sh",
]


class RepoDbFilesItem(TypedDict):
Expand Down Expand Up @@ -62,84 +45,28 @@ class RepoDb(TypedDict):
base_files_url: Optional[str]


def create_app_db(app: str, tag: str) -> RepoDb:
if app not in APPS:
raise ValueError("Invalid app name")

def create_tapto_db(tag: str) -> RepoDb:
folders: RepoDbFolders = {
"Scripts/": RepoDbFoldersItem(tags=None),
}

dl_files = FILES[app]
reboot = app in REBOOT

files: RepoDbFiles = {}
for file in dl_files:
local_path = file
if "/" not in file:
local_path = os.path.join(DL_FOLDER, file)
for file in FILES:
local_path = os.path.join(DL_FOLDER, file)

key = "Scripts/{}".format(os.path.basename(local_path))
size = os.stat(local_path).st_size
md5 = hashlib.md5(open(local_path, "rb").read()).hexdigest()
url = "{}/{}".format(DL_URL.format(tag), os.path.basename(local_path))

file_entry = RepoDbFilesItem(
hash=md5, size=size, url=url, overwrite=None, reboot=reboot, tags=[Path(local_path).stem]
)

files[key] = file_entry

return RepoDb(
db_id=DB_ID.format(app),
timestamp=int(time.time()),
files=files,
folders=folders,
base_files_url=None,
)


def create_all_db(tag: str) -> RepoDb:
folders: RepoDbFolders = {
"Scripts/": RepoDbFoldersItem(tags=None),
}
files: RepoDbFiles = {}

for app in APPS:
dl_files = FILES[app]
reboot = app in REBOOT

for file in dl_files:
local_path = file
if "/" not in file:
local_path = os.path.join(DL_FOLDER, file)

key = "Scripts/{}".format(os.path.basename(local_path))
size = os.stat(local_path).st_size
md5 = hashlib.md5(open(local_path, "rb").read()).hexdigest()
url = "{}/{}".format(DL_URL.format(tag), os.path.basename(local_path))

file_entry = RepoDbFilesItem(
hash=md5, size=size, url=url, overwrite=None, reboot=reboot, tags=[Path(local_path).stem]
)

files[key] = file_entry

for file in EXTERNAL_FILES:
local_path = file
key = "Scripts/{}".format(os.path.basename(local_path))
size = os.stat(local_path).st_size
md5 = hashlib.md5(open(local_path, "rb").read()).hexdigest()
url = EXTERNAL_URL.format(os.path.basename(local_path))

file_entry = RepoDbFilesItem(
hash=md5, size=size, url=url, overwrite=None, reboot=False, tags=[Path(local_path).stem]
hash=md5, size=size, url=url, overwrite=None, reboot=None, tags=[Path(local_path).stem]
)

files[key] = file_entry

return RepoDb(
db_id=DB_ID.format("all"),
db_id=DB_ID,
timestamp=int(time.time()),
files=files,
folders=folders,
Expand All @@ -161,15 +88,9 @@ def generate_json(repo_db: RepoDb) -> str:
def main():
tag = sys.argv[1]

for app in APPS:
repo_db = create_app_db(app, tag)
with open("{}/{}/{}.json".format(RELEASES_FOLDER, app, app), "w") as f:
f.write(generate_json(repo_db))

repo_db = create_all_db(tag)
with open("{}/all.json".format(RELEASES_FOLDER), "w") as f:
repo_db = create_tapto_db(tag)
with open("{}/tapto.json".format(DL_FOLDER), "w") as f:
f.write(generate_json(repo_db))


if __name__ == "__main__":
main()

0 comments on commit 1342a6f

Please sign in to comment.