Added check for non-existing keys in CSV dictionary
This commit is contained in:
parent
7b7f6438d4
commit
f31b1b2705
@ -50,10 +50,17 @@ def rename(
|
|||||||
raise Exception("Duplicate current key.")
|
raise Exception("Duplicate current key.")
|
||||||
replacement_dict[row[current_col_ind]] = row[become_col_ind]
|
replacement_dict[row[current_col_ind]] = row[become_col_ind]
|
||||||
for subitem_path, subitem, match in candidates:
|
for subitem_path, subitem, match in candidates:
|
||||||
|
if match.group(1) not in replacement_dict:
|
||||||
|
logging.warning(
|
||||||
|
'Group "%s" was not matched to any row in the provided CSV. '
|
||||||
|
"Skipping...",
|
||||||
|
match.group(1)
|
||||||
|
)
|
||||||
|
continue
|
||||||
original = subitem_path
|
original = subitem_path
|
||||||
objective = os.path.join(
|
objective = os.path.join(
|
||||||
os.path.dirname(subitem_path),
|
os.path.dirname(subitem_path),
|
||||||
re.sub(match.re, replacement_dict[match.group(1)], subitem),
|
re.sub(match.re, replacement_dict[match.group(1)], subitem.strip()),
|
||||||
)
|
)
|
||||||
if keep_extension:
|
if keep_extension:
|
||||||
objective += os.path.splitext(subitem_path)[1]
|
objective += os.path.splitext(subitem_path)[1]
|
||||||
|
Loading…
Reference in New Issue
Block a user