cptemplate,error.py: Add handling for when target file already exists
This commit is contained in:
parent
48ca334377
commit
b2925bfd23
@ -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())
|
||||||
|
@ -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."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user