cptemplate,error.py: Add handling for when target file already exists

This commit is contained in:
Eric Torres 2020-10-24 17:49:19 -07:00
parent 48ca334377
commit b2925bfd23
2 changed files with 8 additions and 4 deletions

View File

@ -78,9 +78,12 @@ if __name__ == "__main__":
try: try:
dest_file.touch(mode=0o600, exist_ok=False) dest_file.touch(mode=0o600, exist_ok=False)
except FileExistsError: except FileExistsError as e:
# force_overwrite true: overwrite if args.force_overwrite:
# force_overwrite false: print error message dest_file.touch(mode=0o600, exist_ok=True)
raise NotImplementedError("Implement if file already exists") dest_file.write_bytes(selected_file.read_bytes())
else:
print(e)
exit(error.E_FILE_EXISTS)
else: else:
dest_file.write_bytes(selected_file.read_bytes()) dest_file.write_bytes(selected_file.read_bytes())

View File

@ -12,6 +12,7 @@ E_NOFILESELECTED = 2
E_NOEDITORFOUND = 3 E_NOEDITORFOUND = 3
E_NO_RESULTS = 4 E_NO_RESULTS = 4
E_USER_RESPONSE_NO = 5 E_USER_RESPONSE_NO = 5
E_FILE_EXISTS = 6
# ----- Messages ----- # ----- Messages -----
NO_FILE_SELECTED_MESSAGE = "No file was selected." NO_FILE_SELECTED_MESSAGE = "No file was selected."