Skip to content

Commit dfc4b3e

Browse files
Darkhood148TiCoKH
authored andcommitted
DEVTOOLS: DUMPERCOMPANION: support puny encoding, japanese and dry run for iso9660
Add optional arguments '--japanese', '--no-punyencode' and '--dryrun' for dealing with 'shift_jis' encoded filenames, disregarding puny encoding and dry running the script respectively
1 parent 6e6405e commit dfc4b3e

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

devtools/dumper-companion.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ def extract_volume_iso(args: argparse.Namespace):
345345
"""Extract an ISO volume"""
346346
source_volume = args.src
347347
loglevel: str = args.log
348+
dopunycode: bool = not args.nopunycode
349+
dryrun: bool = args.dryrun
350+
japanese: bool = args.japanese
348351

349352
numeric_level = getattr(logging, loglevel.upper(), None)
350353
if not isinstance(numeric_level, int):
@@ -363,24 +366,35 @@ def extract_volume_iso(args: argparse.Namespace):
363366
elif args.extension == 'joliet':
364367
path_type = 'joliet_path'
365368
elif args.extension == 'rr':
366-
path_type = 'rr_type'
369+
path_type = 'rr_path'
367370
else:
368371
path_type = 'udf_path'
369372

370373
arg = {path_type: '/'}
371374

375+
if japanese:
376+
arg['encoding'] = 'shift_jis'
377+
372378
for dirname, dirlist, filelist in iso.walk(**arg):
373379
pwd = output_dir + dirname
374380
for dir in dirlist:
375381
joined_path = os.path.join(pwd, dir)
376-
os.makedirs(joined_path, exist_ok=True)
382+
if not dryrun:
383+
os.makedirs(joined_path, exist_ok=True)
384+
else:
385+
print(joined_path)
386+
387+
if dryrun:
388+
continue
389+
377390
for file in filelist:
378391
filename = file.split(';')[0]
379392
iso_file_path = os.path.join(dirname, filename)
380393
with open(os.path.join(pwd, filename), 'wb') as f:
381394
arg[path_type] = iso_file_path
382395
iso.get_file_from_iso_fp(outfp=f, **arg)
383-
396+
if dopunycode:
397+
punyencode_dir(Path(output_dir))
384398
iso.close()
385399

386400

@@ -834,6 +848,15 @@ def generate_parser() -> argparse.ArgumentParser:
834848
"--log", metavar="LEVEL", help="set logging level", default="INFO"
835849
)
836850
parser_iso9660.add_argument("--extension", choices=['joliet', 'rr', 'udf'], metavar="EXTENSION", help="Use if the iso9660 has an extension")
851+
parser_iso9660.add_argument(
852+
"--nopunycode", action="store_true", help="never encode pathnames into punycode"
853+
)
854+
parser_iso9660.add_argument(
855+
"--dryrun", action="store_true", help="do not write any files"
856+
)
857+
parser_iso9660.add_argument(
858+
"--japanese", action="store_true", help="read MacJapanese HFS"
859+
)
837860
parser_iso9660.add_argument("src", metavar="INPUT", type=Path, help="Disk image")
838861
parser_iso9660.add_argument(
839862
"dir", metavar="OUTPUT", type=Path, help="Destination folder"

0 commit comments

Comments
 (0)