Skip to content

Commit 22d22e9

Browse files
committed
feat(cli): add simple cli interface for updating the tpk file
1 parent dd91598 commit 22d22e9

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

UnityPy/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if __name__ == "__main__":
2+
from UnityPy.cli import main
3+
4+
main()

UnityPy/cli/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from argparse import ArgumentParser
2+
3+
from UnityPy.cli.update_tpk import update_tpk
4+
5+
6+
def main():
7+
parser = ArgumentParser(
8+
prog="UnityPy",
9+
description="UnityPy cli utility",
10+
)
11+
12+
subparsers = parser.add_subparsers(title="utils")
13+
14+
update_tpk_parser = subparsers.add_parser("update_tpk", help="Updates TPK (typetree dump) file")
15+
update_tpk_parser.set_defaults(func=update_tpk)
16+
17+
args = parser.parse_args()
18+
19+
if not hasattr(args, "func"):
20+
parser.print_help()
21+
return
22+
23+
operands = getattr(args, "operands", [])
24+
args.func(*operands)
25+
26+
27+
if __name__ == "__main__":
28+
main()

UnityPy/cli/update_tpk.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
from io import BytesIO
3+
from urllib.request import urlopen
4+
from zipfile import ZipFile
5+
6+
URL = "https://nightly.link/AssetRipper/Tpk/workflows/type_tree_tpk/master/uncompressed_file.zip"
7+
RESOURCE_PATH = os.path.join(os.path.dirname(__file__), "..", "resources")
8+
9+
10+
def update_tpk():
11+
print("Updating TPK file...")
12+
print("\tDownloading...")
13+
with urlopen(URL) as response:
14+
zip_data = response.read()
15+
print("\tExtracting...")
16+
with ZipFile(BytesIO(zip_data)) as zip_file:
17+
zip_file.extract("uncompressed.tpk", path=RESOURCE_PATH)
18+
print("\tDone.")
19+
20+
21+
__all__ = ["update_tpk"]

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ dependencies = [
5454
]
5555
dynamic = ["version"]
5656

57+
[project.scripts]
58+
UnityPy = "UnityPy.cli:main"
59+
5760
[project.optional-dependencies]
5861
# optional dependencies must be lowercase/normalized
5962
ttgen = ["typetreegeneratorapi>=0.0.5"]

0 commit comments

Comments
 (0)