Skip to content

Commit c3b9435

Browse files
committed
fix: Python syntax issues
1 parent 4f6db66 commit c3b9435

File tree

1 file changed

+60
-40
lines changed

1 file changed

+60
-40
lines changed

normfn

+60-40
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ def main(argv, syserr_handler):
4444
raise FatalException(message)
4545

4646
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+
),
4951
add_help=False,
5052
)
5153

@@ -54,7 +56,7 @@ def main(argv, syserr_handler):
5456
"--verbose",
5557
action="count",
5658
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.",
5860
)
5961

6062
_ = parser.add_argument(
@@ -69,8 +71,10 @@ def main(argv, syserr_handler):
6971
"--dry-run",
7072
action="store_true",
7173
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+
),
7478
)
7579

7680
_ = parser.add_argument(
@@ -94,9 +98,11 @@ def main(argv, syserr_handler):
9498
"--force",
9599
action="store_true",
96100
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+
),
100106
)
101107

102108
_ = parser.add_argument(
@@ -121,26 +127,32 @@ def main(argv, syserr_handler):
121127
action="store_true",
122128
dest="recursive",
123129
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+
),
126134
)
127135

128136
_ = parser.add_argument(
129137
"--max-years-ahead",
130138
type=int,
131139
dest="max_years_ahead",
132140
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+
),
135145
)
136146

137147
_ = parser.add_argument(
138148
"--max-years-behind",
139149
type=int,
140150
dest="max_years_behind",
141151
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+
),
144156
)
145157

146158
log_option = parser.add_mutually_exclusive_group()
@@ -149,10 +161,12 @@ def main(argv, syserr_handler):
149161
"--undo-log-file",
150162
type=str,
151163
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+
),
156170
)
157171

158172
_ = log_option.add_argument(
@@ -169,8 +183,10 @@ def main(argv, syserr_handler):
169183
action="store_const",
170184
dest="time_option",
171185
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+
),
174190
)
175191

176192
_ = time_option.add_argument(
@@ -179,11 +195,13 @@ def main(argv, syserr_handler):
179195
action="store_const",
180196
dest="time_option",
181197
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+
),
187205
)
188206

189207
_ = time_option.add_argument(
@@ -192,9 +210,11 @@ def main(argv, syserr_handler):
192210
action="store_const",
193211
dest="time_option",
194212
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+
),
198218
)
199219

200220
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):
443463
+ r"(?P<hour>"
444464
+ HOUR
445465
+ 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>.*)$"
449469
)
450470

451471
logger.debug("Complete regex used against " + non_extension + ": " + REGEX)
@@ -606,26 +626,26 @@ def shiftfile(args, source: str, target: str):
606626
if args.undo_log_file:
607627
check_undo_log_file_header(args)
608628
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")
611631
logger.info(source + " moved to " + target)
612632

613633

614634
def check_undo_log_file_header(args):
615635
if not os.path.exists(args.undo_log_file):
616636
with open(args.undo_log_file, "w") as log_file:
617637
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(
620640
wrapper.fill(
621641
"File generated by normfn "
622642
"(see http://www.github.com/andrewferrier/normfn). This file is "
623643
"utf-8 encoded)"
624644
)
625645
+ "\n"
626646
)
627-
log_file.write("#\n")
628-
log_file.write(
647+
_ = log_file.write("#\n")
648+
_ = log_file.write(
629649
wrapper.fill(
630650
"This file contains shell commands which can be run to invert (undo) the effects of "
631651
"running normfn. They must be run in *reverse order*. You can achieve "
@@ -636,16 +656,16 @@ def check_undo_log_file_header(args):
636656
)
637657
+ "\n"
638658
)
639-
log_file.write("#\n")
640-
log_file.write(
659+
_ = log_file.write("#\n")
660+
_ = log_file.write(
641661
wrapper.fill(
642662
"(Specific note for MacOS: tac may not be installed. You can install gtac, the "
643663
"equivalent command, using `brew install coreutils`. You will need Homebrew - "
644664
"http://brew.sh/ - installed)"
645665
)
646666
+ "\n"
647667
)
648-
log_file.write("\n")
668+
_ = log_file.write("\n")
649669

650670

651671
def ask_yes_no(prompt: str):

0 commit comments

Comments
 (0)