Improved logging and reduced exceptions.
All checks were successful
ydeng/renamebycsv/pipeline/head This commit looks good

Also bumped version.
This commit is contained in:
Harrison Deng 2023-09-11 07:59:56 +00:00
parent d98801dd66
commit 434f969556
3 changed files with 18 additions and 11 deletions

View File

@ -8,6 +8,7 @@ from renamebycsv.renamer import find_all_candidates, rename_by_csv
def run(args): def run(args):
candidates = find_all_candidates(args.input_dir, args.pattern, args.recursive) candidates = find_all_candidates(args.input_dir, args.pattern, args.recursive)
if len(candidates):
rename_by_csv( rename_by_csv(
args.csv, args.csv,
candidates, candidates,

View File

@ -32,6 +32,8 @@ def find_all_candidates(input_dir: str, regex: str, recursive: bool):
regex, regex,
input_dir, input_dir,
) )
else:
logging.info("Collected %d files to rename.", len(results))
return results return results
@ -51,6 +53,10 @@ def rename_by_csv(
become_col_ind = None become_col_ind = None
for row in reader: for row in reader:
if current_col_ind is None and become_col_ind is None: if current_col_ind is None and become_col_ind is None:
if current not in row:
logging.error("\"%s\" not in header %s.", current, list(row))
if become not in row:
logging.error("\"%s\" not in header %s.", become, list(row))
current_col_ind = row.index(current) current_col_ind = row.index(current)
become_col_ind = row.index(become) become_col_ind = row.index(become)
continue continue
@ -80,7 +86,7 @@ def rename_by_csv(
logging.info(f'Will rename "{original}" to "{os.path.basename(objective)}"') logging.info(f'Will rename "{original}" to "{os.path.basename(objective)}"')
if os.path.exists(objective): if os.path.exists(objective):
logging.error( logging.error(
f'Path at "{objective}" exists, not continuing. ' f'Path at "{objective}" already exists, not continuing. '
"Use -f to overwrite instead of stopping." "Use -f to overwrite instead of stopping."
) )
exit(1) exit(1)

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = renamebycsv name = renamebycsv
version = 0.0.7 version = 0.0.8
[options] [options]
packages = renamebycsv packages = renamebycsv