From ec7cb1063fc1d28e46c2e8b181f73e41e11ee128 Mon Sep 17 00:00:00 2001 From: NinjaCheetah <58050615+NinjaCheetah@users.noreply.github.com> Date: Thu, 7 Nov 2024 13:57:33 -0500 Subject: [PATCH] Restructured command files, updated U8 command syntax to match others --- {modules => commands}/archive/ash.py | 2 +- commands/archive/theme.py | 4 ++ commands/archive/u8.py | 38 +++++++++++++++++++ {modules => commands}/nand/emunand.py | 2 +- {modules => commands}/nand/setting.py | 2 +- {modules => commands}/title/ciosbuild.py | 8 ++-- {modules => commands}/title/fakesign.py | 2 +- {modules => commands}/title/info.py | 2 +- {modules => commands}/title/iospatcher.py | 2 +- {modules => commands}/title/nus.py | 2 +- {modules => commands}/title/tmd.py | 2 +- {modules => commands}/title/wad.py | 2 +- modules/archive/u8.py | 37 ------------------- requirements.txt | 2 +- wiipy.py | 45 +++++++++++++---------- 15 files changed, 82 insertions(+), 70 deletions(-) rename {modules => commands}/archive/ash.py (94%) create mode 100644 commands/archive/theme.py create mode 100644 commands/archive/u8.py rename {modules => commands}/nand/emunand.py (97%) rename {modules => commands}/nand/setting.py (98%) rename {modules => commands}/title/ciosbuild.py (96%) rename {modules => commands}/title/fakesign.py (95%) rename {modules => commands}/title/info.py (99%) rename {modules => commands}/title/iospatcher.py (98%) rename {modules => commands}/title/nus.py (99%) rename {modules => commands}/title/tmd.py (97%) rename {modules => commands}/title/wad.py (99%) delete mode 100644 modules/archive/u8.py diff --git a/modules/archive/ash.py b/commands/archive/ash.py similarity index 94% rename from modules/archive/ash.py rename to commands/archive/ash.py index b1661d1..4e2f916 100644 --- a/modules/archive/ash.py +++ b/commands/archive/ash.py @@ -1,4 +1,4 @@ -# "modules/archive/ash.py" from WiiPy by NinjaCheetah +# "commands/archive/ash.py" from WiiPy by NinjaCheetah # https://github.com/NinjaCheetah/WiiPy import pathlib diff --git a/commands/archive/theme.py b/commands/archive/theme.py new file mode 100644 index 0000000..612dd6b --- /dev/null +++ b/commands/archive/theme.py @@ -0,0 +1,4 @@ +# "commands/archive/theme.py" from WiiPy by NinjaCheetah +# https://github.com/NinjaCheetah/WiiPy + + diff --git a/commands/archive/u8.py b/commands/archive/u8.py new file mode 100644 index 0000000..ef1a602 --- /dev/null +++ b/commands/archive/u8.py @@ -0,0 +1,38 @@ +# "commands/archive/u8.py" from WiiPy by NinjaCheetah +# https://github.com/NinjaCheetah/WiiPy + +import pathlib +import libWiiPy + + +def handle_u8_pack(args): + input_path = pathlib.Path(args.input) + output_path = pathlib.Path(args.output) + + try: + u8_data = libWiiPy.archive.pack_u8(input_path) + except ValueError: + print("Error: Specified input file/folder does not exist!") + return + + out_file = open(output_path, "wb") + out_file.write(u8_data) + out_file.close() + + print("U8 archive packed!") + + +def handle_u8_unpack(args): + input_path = pathlib.Path(args.input) + output_path = pathlib.Path(args.output) + + if not input_path.exists(): + raise FileNotFoundError(args.input) + + u8_data = open(input_path, "rb").read() + + # Output path is deliberately not checked in any way because libWiiPy already has those checks, and it's easier + # and cleaner to only have one component doing all the checks. + libWiiPy.archive.extract_u8(u8_data, str(output_path)) + + print("U8 archive unpacked!") diff --git a/modules/nand/emunand.py b/commands/nand/emunand.py similarity index 97% rename from modules/nand/emunand.py rename to commands/nand/emunand.py index 2da4ed5..2db011c 100644 --- a/modules/nand/emunand.py +++ b/commands/nand/emunand.py @@ -1,4 +1,4 @@ -# "modules/nand/emunand.py" from WiiPy by NinjaCheetah +# "commands/nand/emunand.py" from WiiPy by NinjaCheetah # https://github.com/NinjaCheetah/WiiPy import pathlib diff --git a/modules/nand/setting.py b/commands/nand/setting.py similarity index 98% rename from modules/nand/setting.py rename to commands/nand/setting.py index cbc18f5..0a01896 100644 --- a/modules/nand/setting.py +++ b/commands/nand/setting.py @@ -1,4 +1,4 @@ -# "modules/nand/setting.py" from WiiPy by NinjaCheetah +# "commands/nand/setting.py" from WiiPy by NinjaCheetah # https://github.com/NinjaCheetah/WiiPy import pathlib diff --git a/modules/title/ciosbuild.py b/commands/title/ciosbuild.py similarity index 96% rename from modules/title/ciosbuild.py rename to commands/title/ciosbuild.py index db5d671..e142941 100644 --- a/modules/title/ciosbuild.py +++ b/commands/title/ciosbuild.py @@ -1,4 +1,4 @@ -# "modules/title/ciosbuild.py" from WiiPy by NinjaCheetah +# "commands/title/ciosbuild.py" from WiiPy by NinjaCheetah # https://github.com/NinjaCheetah/WiiPy import io @@ -59,7 +59,7 @@ def build_cios(args): # We're ready to begin building the cIOS now. Find all the tags that have tags, and then apply # the patches listed in them to the content. - print("Patching existing modules...") + print("Patching existing commands...") for content in target_base.findall("content"): patches = content.findall("patch") if patches: @@ -91,8 +91,8 @@ def build_cios(args): # Set the content in the title to the newly-patched content, and set the type to normal. title.set_content(dec_content, content_index, content_type=libWiiPy.title.ContentType.NORMAL) - # Next phase of cIOS building is to add the required extra modules. - print("Adding required additional modules...") + # Next phase of cIOS building is to add the required extra commands. + print("Adding required additional commands...") for content in target_base.findall("content"): target_module = content.get("module") if target_module is not None: diff --git a/modules/title/fakesign.py b/commands/title/fakesign.py similarity index 95% rename from modules/title/fakesign.py rename to commands/title/fakesign.py index 15b3879..990cd66 100644 --- a/modules/title/fakesign.py +++ b/commands/title/fakesign.py @@ -1,4 +1,4 @@ -# "modules/title/fakesign.py" from WiiPy by NinjaCheetah +# "commands/title/fakesign.py" from WiiPy by NinjaCheetah # https://github.com/NinjaCheetah/WiiPy import pathlib diff --git a/modules/title/info.py b/commands/title/info.py similarity index 99% rename from modules/title/info.py rename to commands/title/info.py index 7bc3366..eb4217f 100644 --- a/modules/title/info.py +++ b/commands/title/info.py @@ -1,4 +1,4 @@ -# "modules/title/info.py" from WiiPy by NinjaCheetah +# "commands/title/info.py" from WiiPy by NinjaCheetah # https://github.com/NinjaCheetah/WiiPy import pathlib diff --git a/modules/title/iospatcher.py b/commands/title/iospatcher.py similarity index 98% rename from modules/title/iospatcher.py rename to commands/title/iospatcher.py index 75536c8..270e85f 100644 --- a/modules/title/iospatcher.py +++ b/commands/title/iospatcher.py @@ -1,4 +1,4 @@ -# "modules/title/iospatcher.py" from WiiPy by NinjaCheetah +# "commands/title/iospatcher.py" from WiiPy by NinjaCheetah # https://github.com/NinjaCheetah/WiiPy import pathlib diff --git a/modules/title/nus.py b/commands/title/nus.py similarity index 99% rename from modules/title/nus.py rename to commands/title/nus.py index 8f598c8..4c1dc8a 100644 --- a/modules/title/nus.py +++ b/commands/title/nus.py @@ -1,4 +1,4 @@ -# "modules/title/nus.py" from WiiPy by NinjaCheetah +# "commands/title/nus.py" from WiiPy by NinjaCheetah # https://github.com/NinjaCheetah/WiiPy import hashlib diff --git a/modules/title/tmd.py b/commands/title/tmd.py similarity index 97% rename from modules/title/tmd.py rename to commands/title/tmd.py index e3be086..0901105 100644 --- a/modules/title/tmd.py +++ b/commands/title/tmd.py @@ -1,4 +1,4 @@ -# "modules/title/tmd.py" from WiiPy by NinjaCheetah +# "commands/title/tmd.py" from WiiPy by NinjaCheetah # https://github.com/NinjaCheetah/WiiPy import pathlib diff --git a/modules/title/wad.py b/commands/title/wad.py similarity index 99% rename from modules/title/wad.py rename to commands/title/wad.py index 99feee5..236acf6 100644 --- a/modules/title/wad.py +++ b/commands/title/wad.py @@ -1,4 +1,4 @@ -# "modules/title/wad.py" from WiiPy by NinjaCheetah +# "commands/title/wad.py" from WiiPy by NinjaCheetah # https://github.com/NinjaCheetah/WiiPy import pathlib diff --git a/modules/archive/u8.py b/modules/archive/u8.py deleted file mode 100644 index 3ac5e84..0000000 --- a/modules/archive/u8.py +++ /dev/null @@ -1,37 +0,0 @@ -# "modules/archive/u8.py" from WiiPy by NinjaCheetah -# https://github.com/NinjaCheetah/WiiPy - -import pathlib -import libWiiPy - - -def handle_u8(args): - input_path = pathlib.Path(args.input) - output_path = pathlib.Path(args.output) - - # Code for if the --pack argument was passed. - if args.pack: - try: - u8_data = libWiiPy.archive.pack_u8(input_path) - except ValueError: - print("Error: Specified input file/folder does not exist!") - return - - out_file = open(output_path, "wb") - out_file.write(u8_data) - out_file.close() - - print("U8 archive packed!") - - # Code for if the --unpack argument was passed. - elif args.unpack: - if not input_path.exists(): - raise FileNotFoundError(args.input) - - u8_data = open(input_path, "rb").read() - - # Output path is deliberately not checked in any way because libWiiPy already has those checks, and it's easier - # and cleaner to only have one component doing all the checks. - libWiiPy.archive.extract_u8(u8_data, str(output_path)) - - print("U8 archive unpacked!") diff --git a/requirements.txt b/requirements.txt index 769d23e..61850f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ git+https://github.com/NinjaCheetah/libWiiPy -nuitka==2.3.11 +nuitka diff --git a/wiipy.py b/wiipy.py index f13868a..99520da 100644 --- a/wiipy.py +++ b/wiipy.py @@ -4,17 +4,17 @@ import argparse from importlib.metadata import version -from modules.archive.ash import * -from modules.archive.u8 import * -from modules.nand.emunand import * -from modules.nand.setting import * -from modules.title.ciosbuild import * -from modules.title.fakesign import * -from modules.title.info import * -from modules.title.iospatcher import * -from modules.title.nus import * -from modules.title.tmd import * -from modules.title.wad import * +from commands.archive.ash import * +from commands.archive.u8 import * +from commands.nand.emunand import * +from commands.nand.setting import * +from commands.title.ciosbuild import * +from commands.title.fakesign import * +from commands.title.info import * +from commands.title.iospatcher import * +from commands.title.nus import * +from commands.title.tmd import * +from commands.title.wad import * wiipy_ver = "1.4.0" @@ -64,8 +64,8 @@ if __name__ == "__main__": cios_parser.add_argument("output", metavar="OUT", type=str, help="file to output the cIOS to") cios_parser.add_argument("-c", "--cios-ver", metavar="CIOS", type=str, help="cIOS version from the map to build", required=True) - cios_parser.add_argument("-m", "--modules", metavar="MODULES", type=str, - help="directory to look for cIOS modules in (optional, defaults to current directory)") + cios_parser.add_argument("-m", "--commands", metavar="MODULES", type=str, + help="directory to look for cIOS commands in (optional, defaults to current directory)") cios_parser.add_argument("-s", "--slot", metavar="SLOT", type=int, help="slot that this cIOS will install to (optional, defaults to 249)", default=249) cios_parser.add_argument("-v", "--version", metavar="VERSION", type=int, @@ -218,12 +218,19 @@ if __name__ == "__main__": # Argument parser for the U8 subcommand. u8_parser = subparsers.add_parser("u8", help="pack/unpack a U8 archive", description="pack/unpack a U8 archive") - u8_parser.set_defaults(func=handle_u8) - u8_group = u8_parser.add_mutually_exclusive_group(required=True) - u8_group.add_argument("-p", "--pack", help="pack a directory to a U8 archive", action="store_true") - u8_group.add_argument("-u", "--unpack", help="unpack a U8 archive to a directory", action="store_true") - u8_parser.add_argument("input", metavar="IN", type=str, help="input file") - u8_parser.add_argument("output", metavar="OUT", type=str, help="output file") + u8_subparsers = u8_parser.add_subparsers(dest="subcommand", required=True) + # Pack U8 subcommand. + u8_pack_parser = u8_subparsers.add_parser("pack", help="pack a folder into U8 archive", + description="pack a folder into U8 archive") + u8_pack_parser.set_defaults(func=handle_u8_pack) + u8_pack_parser.add_argument("input", metavar="IN", type=str, help="folder to pack") + u8_pack_parser.add_argument("output", metavar="OUT", type=str, help="output U8 archive") + # Unpack U8 subcommand. + u8_unpack_parser = u8_subparsers.add_parser("unpack", help="unpack a U8 archive into a folder", + description="unpack a U8 archive into a folder") + u8_unpack_parser.set_defaults(func=handle_u8_unpack) + u8_unpack_parser.add_argument("input", metavar="IN", type=str, help="U8 archive to unpack") + u8_unpack_parser.add_argument("output", metavar="OUT", type=str, help="folder to output to") # Argument parser for the WAD subcommand. wad_parser = subparsers.add_parser("wad", help="pack/unpack a WAD file",