@@ -48,7 +48,7 @@ def __init__(self, debug=False, files=None):
48
48
49
49
50
50
class MyClickCommand (click .Command ):
51
- """ Custom click.Command that overrides get_help() to show additional info """
51
+ """Custom click.Command that overrides get_help() to show additional info"""
52
52
53
53
def get_help (self , ctx ):
54
54
help_text = super ().get_help (ctx )
@@ -236,7 +236,7 @@ def get_help(self, ctx):
236
236
"-B" ,
237
237
help = "Backup FILE attributes. "
238
238
"Backup file '.osxmetadata.json' will be created in same folder as FILE. "
239
- "Only backs up attributes known to osxmetadata." ,
239
+ "Only backs up attributes known to osxmetadata unless used with --all ." ,
240
240
is_flag = True ,
241
241
required = False ,
242
242
default = False ,
@@ -245,11 +245,20 @@ def get_help(self, ctx):
245
245
"--restore" ,
246
246
"-R" ,
247
247
help = "Restore FILE attributes from backup file. "
248
- "Restore will look for backup file '.osxmetadata.json' in same folder as FILE." ,
248
+ "Restore will look for backup file '.osxmetadata.json' in same folder as FILE. "
249
+ "Only restores attributes known to osxmetadata unless used with --all." ,
249
250
is_flag = True ,
250
251
required = False ,
251
252
default = False ,
252
253
)
254
+ ALL_OPTION = click .option (
255
+ "--all" ,
256
+ "-A" ,
257
+ "all_" ,
258
+ is_flag = True ,
259
+ help = "Process all extended attributes including those not known to osxmetadata. "
260
+ "Use with --backup/--restore to backup/restore all extended attributes. " ,
261
+ )
253
262
VERBOSE_OPTION = click .option (
254
263
"--verbose" ,
255
264
"-V" ,
@@ -307,6 +316,7 @@ def get_help(self, ctx):
307
316
@MIRROR_OPTION
308
317
@BACKUP_OPTION
309
318
@RESTORE_OPTION
319
+ @ALL_OPTION
310
320
@VERBOSE_OPTION
311
321
@COPY_FROM_OPTION
312
322
@FILES_ONLY_OPTION
@@ -330,12 +340,13 @@ def cli(
330
340
mirror ,
331
341
backup ,
332
342
restore ,
343
+ all_ ,
333
344
verbose ,
334
345
copyfrom ,
335
346
files_only ,
336
347
pattern ,
337
348
):
338
- """ Read/write metadata from file(s). """
349
+ """Read/write metadata from file(s)."""
339
350
340
351
if help_ :
341
352
click .echo_via_pager (ctx .get_help ())
@@ -432,6 +443,7 @@ def cli(
432
443
restore ,
433
444
walk ,
434
445
files_only ,
446
+ all_ ,
435
447
)
436
448
437
449
if walk and os .path .isdir (filename ):
@@ -468,6 +480,7 @@ def cli(
468
480
restore ,
469
481
walk ,
470
482
files_only ,
483
+ all_ ,
471
484
)
472
485
473
486
@@ -490,10 +503,11 @@ def process_files(
490
503
restore ,
491
504
walk ,
492
505
files_only ,
506
+ all_ ,
493
507
):
494
- """ process list of files, calls process_single_file to process each file
495
- options processed in this order: wipe, copyfrom, clear, set, append, remove, mirror, get, list
496
- Note: expects all attributes passed in parameters to be validated as valid attributes
508
+ """process list of files, calls process_single_file to process each file
509
+ options processed in this order: wipe, copyfrom, clear, set, append, remove, mirror, get, list
510
+ Note: expects all attributes passed in parameters to be validated as valid attributes
497
511
"""
498
512
for filename in files :
499
513
fpath = pathlib .Path (filename ).resolve ()
@@ -514,7 +528,7 @@ def process_files(
514
528
if verbose :
515
529
click .echo (f" Restoring attribute data for { fpath } " )
516
530
md = osxmetadata .OSXMetaData (fpath )
517
- md ._restore_attributes (attr_dict )
531
+ md ._restore_attributes (attr_dict , all_ = all_ )
518
532
except FileNotFoundError :
519
533
click .echo (
520
534
f"Missing backup file { backup_file } for { fpath } , skipping restore" ,
@@ -547,12 +561,9 @@ def process_files(
547
561
if verbose :
548
562
click .echo (f" Backing up attribute data for { fpath } " )
549
563
# load the file if it exists, merge new data, then write out the file again
550
- if backup_file .is_file ():
551
- backup_data = load_backup_file (backup_file )
552
- else :
553
- backup_data = {}
554
- json_dict = osxmetadata .OSXMetaData (fpath ).asdict ()
555
- backup_data [pathlib .Path (fpath ).name ] = json_dict
564
+ backup_data = load_backup_file (backup_file ) if backup_file .is_file () else {}
565
+ backup_dict = osxmetadata .OSXMetaData (fpath ).asdict (all_ = all_ )
566
+ backup_data [pathlib .Path (fpath ).name ] = backup_dict
556
567
write_backup_file (backup_file , backup_data )
557
568
558
569
@@ -572,9 +583,9 @@ def process_single_file(
572
583
verbose ,
573
584
copyfrom ,
574
585
):
575
- """ process a single file to apply the options
576
- options processed in this order: wipe, copyfrom, clear, set, append, remove, mirror, get, list
577
- Note: expects all attributes passed in parameters to be validated as valid attributes """
586
+ """process a single file to apply the options
587
+ options processed in this order: wipe, copyfrom, clear, set, append, remove, mirror, get, list
588
+ Note: expects all attributes passed in parameters to be validated as valid attributes"""
578
589
579
590
md = osxmetadata .OSXMetaData (fpath )
580
591
0 commit comments