@@ -291,13 +291,53 @@ def encode_string(args: argparse.Namespace) -> int:
291
291
return 0
292
292
293
293
294
+ def probe_iso (args ):
295
+ fs = check_fs (args .src )
296
+ print ('Detected file system:' , fs )
297
+ args .fs = fs
298
+ args .dryrun = True
299
+ args .dir = Path ('testing' )
300
+ args .silent = True
301
+ args .forcemacbinary = False
302
+ args .addmacbinaryext = False
303
+ args .log = 'INFO'
304
+ args .nopunycode = False
305
+ args .japanese = False
306
+ if fs == 'hybrid' or fs == 'iso9660' :
307
+ args .extension = check_extension (args )
308
+ print ('Detected extension:' , args .extension )
309
+ print ('Japanese detected:' , check_japanese (args ))
310
+
311
+
312
+ def check_japanese (args ):
313
+ args .japanese = False
314
+ if args .fs == 'hybrid' :
315
+ fn = extract_volume_hybrid
316
+ elif args .fs == 'iso9660' :
317
+ fn = extract_volume_iso
318
+ else :
319
+ fn = extract_volume_hfs
320
+ try :
321
+ fn (args )
322
+ except Exception as e :
323
+ args .japanese = True
324
+ try :
325
+ fn (args )
326
+ except Exception as e :
327
+ raise Exception ('Could not determine japanese' )
328
+ else :
329
+ return True
330
+ else :
331
+ return False
332
+
333
+
294
334
def check_extension (args ):
295
335
args_copy = copy .copy (args )
296
336
args_copy .dryrun = True
297
337
extensions = ['joliet' , 'rr' , 'udf' ]
298
338
args_copy .dir = args .dir .joinpath ('test' )
299
339
args_copy .fs = 'iso9660'
300
- args .silent = True
340
+ args_copy .silent = True
301
341
for extension in extensions :
302
342
args_copy .extension = extension
303
343
try :
@@ -371,13 +411,15 @@ def extract_volume_hfs(args: argparse.Namespace) -> int:
371
411
"""Extract an HFS volume"""
372
412
source_volume : Path = args .src
373
413
loglevel : str = args .log
414
+ silent : bool = args .silent
374
415
375
416
numeric_level = getattr (logging , loglevel .upper (), None )
376
417
if not isinstance (numeric_level , int ):
377
418
raise ValueError ("Invalid log level: %s" % loglevel )
378
419
logging .basicConfig (format = "%(levelname)s: %(message)s" , level = numeric_level )
379
420
380
- logging .info (f"Loading { source_volume } ..." )
421
+ if not silent :
422
+ logging .info (f"Loading { source_volume } ..." )
381
423
vol = machfs .Volume ()
382
424
partitions = []
383
425
with source_volume .open (mode = "rb" ) as f :
@@ -425,13 +467,15 @@ def extract_volume_iso(args: argparse.Namespace):
425
467
dopunycode : bool = not args .nopunycode
426
468
dryrun : bool = args .dryrun
427
469
japanese : bool = args .japanese
470
+ silent : bool = args .silent
428
471
429
472
numeric_level = getattr (logging , loglevel .upper (), None )
430
473
if not isinstance (numeric_level , int ):
431
474
raise ValueError ("Invalid log level: %s" % loglevel )
432
475
logging .basicConfig (format = "%(levelname)s: %(message)s" , level = numeric_level )
433
476
434
- logging .info (f"Loading { source_volume } ..." )
477
+ if not silent :
478
+ logging .info (f"Loading { source_volume } ..." )
435
479
436
480
iso = pycdlib .PyCdlib ()
437
481
iso .open (source_volume )
@@ -458,7 +502,7 @@ def extract_volume_iso(args: argparse.Namespace):
458
502
joined_path = os .path .join (pwd , dir )
459
503
if not dryrun :
460
504
os .makedirs (joined_path , exist_ok = True )
461
- elif not args . silent :
505
+ elif not silent :
462
506
print (joined_path )
463
507
464
508
if dryrun :
@@ -478,21 +522,25 @@ def extract_volume_iso(args: argparse.Namespace):
478
522
def extract_volume_hybrid (args : argparse .Namespace ):
479
523
source_volume = args .src
480
524
loglevel : str = args .log
525
+ silent : bool = args .silent
481
526
482
527
numeric_level = getattr (logging , loglevel .upper (), None )
483
528
if not isinstance (numeric_level , int ):
484
529
raise ValueError ("Invalid log level: %s" % loglevel )
485
530
logging .basicConfig (format = "%(levelname)s: %(message)s" , level = numeric_level )
486
531
487
- logging .info (f"Loading { source_volume } ..." )
532
+ if not silent :
533
+ logging .info (f"Loading { source_volume } ..." )
488
534
489
535
main_dir = args .dir
490
536
491
- args .dir = main_dir .joinpath ('hfs' )
492
- extract_volume_hfs (args )
537
+ args_copy = copy .copy (args )
538
+
539
+ args_copy .dir = main_dir .joinpath ('hfs' )
540
+ extract_volume_hfs (args_copy )
493
541
494
- args .dir = main_dir .joinpath ('iso9660' )
495
- extract_volume_iso (args )
542
+ args_copy .dir = main_dir .joinpath ('iso9660' )
543
+ extract_volume_iso (args_copy )
496
544
497
545
498
546
def extract_partition (args : argparse .Namespace , vol ) -> int :
@@ -502,6 +550,7 @@ def extract_partition(args: argparse.Namespace, vol) -> int:
502
550
dopunycode : bool = not args .nopunycode
503
551
force_macbinary : bool = args .forcemacbinary
504
552
add_macbinary_ext : bool = args .addmacbinaryext
553
+ silent : bool = args .silent
505
554
506
555
if not dryrun :
507
556
destination_dir .mkdir (parents = True , exist_ok = True )
@@ -529,14 +578,14 @@ def extract_partition(args: argparse.Namespace, vol) -> int:
529
578
530
579
upath /= el
531
580
532
- if might_be_jp and not might_be_jp_warned :
581
+ if might_be_jp and not might_be_jp_warned and not silent :
533
582
logging .warning (
534
583
"Possible Mac-Japanese string detected, did you mean to use --japanese?"
535
584
)
536
585
might_be_jp_warned = True
537
586
538
587
if dryrun :
539
- if not isinstance (obj , machfs .Folder ):
588
+ if not isinstance (obj , machfs .Folder ) and not silent :
540
589
print (upath )
541
590
continue
542
591
@@ -547,7 +596,7 @@ def extract_partition(args: argparse.Namespace, vol) -> int:
547
596
folders .append ((upath , obj .mddate - 2082844800 ))
548
597
continue
549
598
550
- print (upath )
599
+ # print(upath)
551
600
if obj .data and not obj .rsrc and not force_macbinary :
552
601
upath .write_bytes (obj .data )
553
602
@@ -906,6 +955,11 @@ def generate_parser() -> argparse.ArgumentParser:
906
955
action = "store_true" ,
907
956
help = "always encode using MacBinary, even for files with no resource fork" ,
908
957
)
958
+ parser_iso .add_argument (
959
+ "--silent" ,
960
+ action = "store_true" ,
961
+ help = "do not print anything"
962
+ )
909
963
parser_iso .add_argument (
910
964
"--addmacbinaryext" ,
911
965
action = "store_true" ,
@@ -926,6 +980,10 @@ def generate_parser() -> argparse.ArgumentParser:
926
980
parser_dir .add_argument ("directory" , metavar = "directory " , type = Path , help = "Path" )
927
981
parser_dir .set_defaults (func = punyencode_arg )
928
982
983
+ parser_probe = subparsers .add_parser ("probe" , help = "Detect file system and extension of the given ISO" )
984
+ parser_probe .add_argument ("src" , metavar = "INPUT" , type = Path , help = "Disk image" )
985
+ parser_probe .set_defaults (func = probe_iso )
986
+
929
987
parser_str = subparsers .add_parser (
930
988
"str" , help = "Convert strings or standard in to or from punycode"
931
989
)
0 commit comments