Apply numbering only to non-normalized files by default
Also add `-f` to force numbering
This commit is contained in:
@@ -190,10 +190,13 @@ def build_plan(files, parse_mode):
|
||||
return plan
|
||||
|
||||
|
||||
def build_number_plan(files, parse_mode):
|
||||
def build_number_plan(files, parse_mode, force=False):
|
||||
"""Build a rename plan using sequential numbering per day."""
|
||||
entries = []
|
||||
for file_path in files:
|
||||
if not force and NORMALIZED.match(file_path.name):
|
||||
entries.append((file_path, None, STATUS_ALREADY))
|
||||
continue
|
||||
date_str = get_date_for_file(file_path, parse_mode)
|
||||
entries.append((file_path, date_str))
|
||||
|
||||
@@ -201,7 +204,11 @@ def build_number_plan(files, parse_mode):
|
||||
plan = []
|
||||
seen_targets = {}
|
||||
|
||||
for file_path, date_str in entries:
|
||||
for entry in entries:
|
||||
if len(entry) == 3:
|
||||
plan.append((entry[0], None, entry[2]))
|
||||
continue
|
||||
file_path, date_str = entry
|
||||
if date_str is None:
|
||||
plan.append((file_path, None, STATUS_NO_MATCH))
|
||||
continue
|
||||
@@ -289,9 +296,16 @@ def main():
|
||||
action='store_true',
|
||||
help=(
|
||||
'Discard original filename stems and number files sequentially '
|
||||
'per day. Combines with --parse to select the date source.'
|
||||
'per day. Combines with --parse to select the date source. '
|
||||
'Skips already-normalized files unless --force is given.'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'-f',
|
||||
'--force',
|
||||
action='store_true',
|
||||
help='Force numbering even for already-normalized files (used with -n).',
|
||||
)
|
||||
parser.add_argument(
|
||||
'files',
|
||||
nargs='*',
|
||||
@@ -306,7 +320,7 @@ def main():
|
||||
sys.exit(0)
|
||||
|
||||
if args.number:
|
||||
plan = build_number_plan(files, args.parse)
|
||||
plan = build_number_plan(files, args.parse, args.force)
|
||||
else:
|
||||
plan = build_plan(files, args.parse)
|
||||
print_preview(plan)
|
||||
|
||||
Reference in New Issue
Block a user