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,15 +8,16 @@ from renamebycsv.renamer import find_all_candidates, rename_by_csv
def run(args):
candidates = find_all_candidates(args.input_dir, args.pattern, args.recursive)
rename_by_csv(
args.csv,
candidates,
args.current,
args.become,
args.dry,
args.extension,
args.keep_extension,
)
if len(candidates):
rename_by_csv(
args.csv,
candidates,
args.current,
args.become,
args.dry,
args.extension,
args.keep_extension,
)
def main():

View File

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

View File

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