@@ -44,8 +44,10 @@ def main(argv, syserr_handler):
44
44
raise FatalException (message )
45
45
46
46
parser = ArgumentParser (
47
- description = "Normalizes filenames by prefixing a date to them. "
48
- "See https://github.com/andrewferrier/normfn for more information." ,
47
+ description = (
48
+ "Normalizes filenames by prefixing a date to them. "
49
+ "See https://github.com/andrewferrier/normfn for more information."
50
+ ),
49
51
add_help = False ,
50
52
)
51
53
@@ -54,7 +56,7 @@ def main(argv, syserr_handler):
54
56
"--verbose" ,
55
57
action = "count" ,
56
58
default = 0 ,
57
- help = "Add debugging output. " " Using this twice makes it doubly verbose." ,
59
+ help = "Add debugging output. Using this twice makes it doubly verbose." ,
58
60
)
59
61
60
62
_ = parser .add_argument (
@@ -69,8 +71,10 @@ def main(argv, syserr_handler):
69
71
"--dry-run" ,
70
72
action = "store_true" ,
71
73
dest = "dry_run" ,
72
- help = "Don't actually make any changes, just show them. Forces "
73
- "a single level of verbosity (-v)." ,
74
+ help = (
75
+ "Don't actually make any changes, just show them. Forces "
76
+ "a single level of verbosity (-v)."
77
+ ),
74
78
)
75
79
76
80
_ = parser .add_argument (
@@ -94,9 +98,11 @@ def main(argv, syserr_handler):
94
98
"--force" ,
95
99
action = "store_true" ,
96
100
dest = "force" ,
97
- help = "Overwrite target files if they already "
98
- "exist (USE WITH CAUTION, consider using --dry-run "
99
- "first)." ,
101
+ help = (
102
+ "Overwrite target files if they already "
103
+ "exist (USE WITH CAUTION, consider using --dry-run "
104
+ "first)."
105
+ ),
100
106
)
101
107
102
108
_ = parser .add_argument (
@@ -121,26 +127,32 @@ def main(argv, syserr_handler):
121
127
action = "store_true" ,
122
128
dest = "recursive" ,
123
129
default = False ,
124
- help = "Recurse into directories specified on the command line. The default is "
125
- "not to do this, and simply look at the name of the directory itself." ,
130
+ help = (
131
+ "Recurse into directories specified on the command line. The default is "
132
+ "not to do this, and simply look at the name of the directory itself."
133
+ ),
126
134
)
127
135
128
136
_ = parser .add_argument (
129
137
"--max-years-ahead" ,
130
138
type = int ,
131
139
dest = "max_years_ahead" ,
132
140
default = 5 ,
133
- help = "Consider years further ahead from now than this not "
134
- "to be valid years. Defaults to 5." ,
141
+ help = (
142
+ "Consider years further ahead from now than this not "
143
+ "to be valid years. Defaults to 5."
144
+ ),
135
145
)
136
146
137
147
_ = parser .add_argument (
138
148
"--max-years-behind" ,
139
149
type = int ,
140
150
dest = "max_years_behind" ,
141
151
default = 30 ,
142
- help = "Consider years further behind from now than this not "
143
- "to be valid years. Defaults to 30." ,
152
+ help = (
153
+ "Consider years further behind from now than this not "
154
+ "to be valid years. Defaults to 30."
155
+ ),
144
156
)
145
157
146
158
log_option = parser .add_mutually_exclusive_group ()
@@ -149,10 +161,12 @@ def main(argv, syserr_handler):
149
161
"--undo-log-file" ,
150
162
type = str ,
151
163
dest = "undo_log_file" ,
152
- help = "The name of the shell script to log "
153
- "'undo commands' for normfn; see the "
154
- "instructions in the file to use. "
155
- f"Defaults to { get_default_log_file ()} " ,
164
+ help = (
165
+ "The name of the shell script to log "
166
+ "'undo commands' for normfn; see the "
167
+ "instructions in the file to use. "
168
+ f"Defaults to { get_default_log_file ()} "
169
+ ),
156
170
)
157
171
158
172
_ = log_option .add_argument (
@@ -169,8 +183,10 @@ def main(argv, syserr_handler):
169
183
action = "store_const" ,
170
184
dest = "time_option" ,
171
185
const = "now" ,
172
- help = "Use date and time now as the default "
173
- "file prefix for filenames without them." ,
186
+ help = (
187
+ "Use date and time now as the default "
188
+ "file prefix for filenames without them."
189
+ ),
174
190
)
175
191
176
192
_ = time_option .add_argument (
@@ -179,11 +195,13 @@ def main(argv, syserr_handler):
179
195
action = "store_const" ,
180
196
dest = "time_option" ,
181
197
const = "latest" ,
182
- help = "Use the latest of ctime and mtime "
183
- "to define a file prefix for files without them. "
184
- "Note: ctime is *not* "
185
- "file creation on Linux/OS X; see "
186
- "http://lwn.net/Articles/397442/." ,
198
+ help = (
199
+ "Use the latest of ctime and mtime "
200
+ "to define a file prefix for files without them. "
201
+ "Note: ctime is *not* "
202
+ "file creation on Linux/OS X; see "
203
+ "http://lwn.net/Articles/397442/."
204
+ ),
187
205
)
188
206
189
207
_ = time_option .add_argument (
@@ -192,9 +210,11 @@ def main(argv, syserr_handler):
192
210
action = "store_const" ,
193
211
dest = "time_option" ,
194
212
const = "earliest" ,
195
- help = "Use earliest of ctime and mtime "
196
- "to define a file prefix for files without them. "
197
- "This is the default." ,
213
+ help = (
214
+ "Use earliest of ctime and mtime "
215
+ "to define a file prefix for files without them. "
216
+ "This is the default."
217
+ ),
198
218
)
199
219
200
220
parser .set_defaults (time_option = "earliest" , undo_log_file = get_default_log_file ())
@@ -443,9 +463,9 @@ def datetime_prefix(args, non_extension: str, filename: str):
443
463
+ r"(?P<hour>"
444
464
+ HOUR
445
465
+ r")"
446
- r"(" + HMS_SEPARATOR_FIRST + r"(?P<minute>" + MINUTE + r")"
447
- r"(" + HMS_SEPARATOR_FOLLOWING + r"(?P<second>" + SECOND + r"))?)?)?"
448
- r"(?P<suffix>.*)$"
466
+ + ( r"(" + HMS_SEPARATOR_FIRST + r"(?P<minute>" + MINUTE + r")" )
467
+ + ( r"(" + HMS_SEPARATOR_FOLLOWING + r"(?P<second>" + SECOND + r"))?)?)?" )
468
+ + r"(?P<suffix>.*)$"
449
469
)
450
470
451
471
logger .debug ("Complete regex used against " + non_extension + ": " + REGEX )
@@ -606,26 +626,26 @@ def shiftfile(args, source: str, target: str):
606
626
if args .undo_log_file :
607
627
check_undo_log_file_header (args )
608
628
with open (args .undo_log_file , "a" , encoding = "utf-8" ) as log_file :
609
- log_file .write (f"# { dt_now } : moving { source } to { target } \n " )
610
- log_file .write (f"mv { shlex .quote (target )} { shlex .quote (source )} \n " )
629
+ _ = log_file .write (f"# { dt_now } : moving { source } to { target } \n " )
630
+ _ = log_file .write (f"mv { shlex .quote (target )} { shlex .quote (source )} \n " )
611
631
logger .info (source + " moved to " + target )
612
632
613
633
614
634
def check_undo_log_file_header (args ):
615
635
if not os .path .exists (args .undo_log_file ):
616
636
with open (args .undo_log_file , "w" ) as log_file :
617
637
wrapper = textwrap .TextWrapper (initial_indent = "# " , subsequent_indent = "# " )
618
- log_file .write ("#!/bin/sh\n " )
619
- log_file .write (
638
+ _ = log_file .write ("#!/bin/sh\n " )
639
+ _ = log_file .write (
620
640
wrapper .fill (
621
641
"File generated by normfn "
622
642
"(see http://www.github.com/andrewferrier/normfn). This file is "
623
643
"utf-8 encoded)"
624
644
)
625
645
+ "\n "
626
646
)
627
- log_file .write ("#\n " )
628
- log_file .write (
647
+ _ = log_file .write ("#\n " )
648
+ _ = log_file .write (
629
649
wrapper .fill (
630
650
"This file contains shell commands which can be run to invert (undo) the effects of "
631
651
"running normfn. They must be run in *reverse order*. You can achieve "
@@ -636,16 +656,16 @@ def check_undo_log_file_header(args):
636
656
)
637
657
+ "\n "
638
658
)
639
- log_file .write ("#\n " )
640
- log_file .write (
659
+ _ = log_file .write ("#\n " )
660
+ _ = log_file .write (
641
661
wrapper .fill (
642
662
"(Specific note for MacOS: tac may not be installed. You can install gtac, the "
643
663
"equivalent command, using `brew install coreutils`. You will need Homebrew - "
644
664
"http://brew.sh/ - installed)"
645
665
)
646
666
+ "\n "
647
667
)
648
- log_file .write ("\n " )
668
+ _ = log_file .write ("\n " )
649
669
650
670
651
671
def ask_yes_no (prompt : str ):
0 commit comments