mirror of https://gitlab.com/bashrc2/epicyon
Exception handling
parent
9cc8a2fb00
commit
876e2eeb91
|
|
@ -1860,8 +1860,12 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
|||
else:
|
||||
if os.path.isfile(filename):
|
||||
new_filename = filename.replace('.temp', '')
|
||||
os.rename(filename, new_filename)
|
||||
filename = new_filename
|
||||
try:
|
||||
os.rename(filename, new_filename)
|
||||
filename = new_filename
|
||||
except OSError:
|
||||
print('EX: POST could not rename ' +
|
||||
filename + ' -> ' + new_filename)
|
||||
|
||||
fields = \
|
||||
extract_text_fields_in_post(post_bytes, boundary, debug, None)
|
||||
|
|
|
|||
16
filters.py
16
filters.py
|
|
@ -79,8 +79,12 @@ def remove_filter(base_dir: str, nickname: str, domain: str,
|
|||
filters_filename + ' ' + str(ex))
|
||||
return False
|
||||
if os.path.isfile(new_filters_filename):
|
||||
os.rename(new_filters_filename, filters_filename)
|
||||
return True
|
||||
try:
|
||||
os.rename(new_filters_filename, filters_filename)
|
||||
return True
|
||||
except OSError:
|
||||
print('EX: remove_filter could not rename ' +
|
||||
new_filters_filename + ' -> ' + filters_filename)
|
||||
return False
|
||||
|
||||
|
||||
|
|
@ -105,8 +109,12 @@ def remove_global_filter(base_dir: str, words: str) -> bool:
|
|||
filters_filename + ' ' + str(ex))
|
||||
return False
|
||||
if os.path.isfile(new_filters_filename):
|
||||
os.rename(new_filters_filename, filters_filename)
|
||||
return True
|
||||
try:
|
||||
os.rename(new_filters_filename, filters_filename)
|
||||
return True
|
||||
except OSError:
|
||||
print('EX: remove_global_filter could not rename ' +
|
||||
new_filters_filename + ' -> ' + filters_filename)
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -159,7 +159,13 @@ def _remove_from_follow_base(base_dir: str,
|
|||
print('EX: _remove_from_follow_base ' +
|
||||
approve_follows_filename + ' ' + str(ex))
|
||||
|
||||
os.rename(approve_follows_filename + '.new', approve_follows_filename)
|
||||
try:
|
||||
os.rename(approve_follows_filename + '.new',
|
||||
approve_follows_filename)
|
||||
except OSError:
|
||||
print('EX: _remove_from_follow_base could not rename ' +
|
||||
approve_follows_filename + '.new' + ' -> ' +
|
||||
approve_follows_filename)
|
||||
|
||||
|
||||
def remove_from_follow_requests(base_dir: str,
|
||||
|
|
|
|||
|
|
@ -363,7 +363,13 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
|
|||
# mark this handle as approved for following
|
||||
_approve_follower_handle(account_dir, approve_handle)
|
||||
# update the follow requests with the handles not yet approved
|
||||
os.rename(approve_follows_filename + '.new', approve_follows_filename)
|
||||
try:
|
||||
os.rename(approve_follows_filename + '.new',
|
||||
approve_follows_filename)
|
||||
except OSError:
|
||||
print('EX: manual_approve_follow_request could not rename ' +
|
||||
approve_follows_filename + '.new' + ' -> ' +
|
||||
approve_follows_filename)
|
||||
# remove the .follow file
|
||||
if follow_activity_filename:
|
||||
if os.path.isfile(follow_activity_filename):
|
||||
|
|
|
|||
7
media.py
7
media.py
|
|
@ -454,7 +454,12 @@ def convert_image_to_low_bandwidth(image_filename: str) -> None:
|
|||
except OSError:
|
||||
print('EX: convert_image_to_low_bandwidth unable to delete ' +
|
||||
image_filename)
|
||||
os.rename(low_bandwidth_filename, image_filename)
|
||||
try:
|
||||
os.rename(low_bandwidth_filename, image_filename)
|
||||
except OSError:
|
||||
print('EX: convert_image_to_low_bandwidth could not rename ' +
|
||||
low_bandwidth_filename + ' -> ' + image_filename)
|
||||
|
||||
if os.path.isfile(image_filename):
|
||||
print('Image converted to low bandwidth ' + image_filename)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -481,7 +481,11 @@ def post_message_to_outbox(session, translate: {},
|
|||
create_media_dirs(base_dir, mpath)
|
||||
media_filename = base_dir + '/' + media_path
|
||||
# move the uploaded image to its new path
|
||||
os.rename(upload_media_filename, media_filename)
|
||||
try:
|
||||
os.rename(upload_media_filename, media_filename)
|
||||
except OSError:
|
||||
print('EX: post_message_to_outbox unable to rename ' +
|
||||
upload_media_filename + ' -> ' + media_filename)
|
||||
# convert dictionary to list if needed
|
||||
if isinstance(message_json['object']['attachment'], dict):
|
||||
message_json['object']['attachment'] = \
|
||||
|
|
|
|||
|
|
@ -178,7 +178,11 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
|
|||
# move to the outbox
|
||||
outbox_post_filename = \
|
||||
post_filename.replace('/scheduled/', '/outbox/')
|
||||
os.rename(post_filename, outbox_post_filename)
|
||||
try:
|
||||
os.rename(post_filename, outbox_post_filename)
|
||||
except OSError:
|
||||
print('EX: _update_post_schedule unable to rename ' +
|
||||
post_filename + ' -> ' + outbox_post_filename)
|
||||
|
||||
print('Scheduled post sent ' + post_id)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue