mirror of https://gitlab.com/bashrc2/epicyon
Add exception handling when saving files
parent
966ec3389f
commit
83d5dde8ec
|
@ -190,8 +190,8 @@ def _mark_post_as_read(actor: str, post_id: str, post_category: str) -> None:
|
||||||
read_file.write(post_id + content)
|
read_file.write(post_id + content)
|
||||||
except OSError as ex:
|
except OSError as ex:
|
||||||
print('EX: Failed to mark post as read 1 ' + str(ex))
|
print('EX: Failed to mark post as read 1 ' + str(ex))
|
||||||
else
|
else:
|
||||||
try::
|
try:
|
||||||
with open(read_posts_filename, 'w+',
|
with open(read_posts_filename, 'w+',
|
||||||
encoding='utf-8') as read_file:
|
encoding='utf-8') as read_file:
|
||||||
read_file.write(post_id + '\n')
|
read_file.write(post_id + '\n')
|
||||||
|
|
17
migrate.py
17
migrate.py
|
@ -158,24 +158,38 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
|
||||||
|
|
||||||
# save the new handles to the refollow list
|
# save the new handles to the refollow list
|
||||||
if os.path.isfile(refollow_filename):
|
if os.path.isfile(refollow_filename):
|
||||||
|
try:
|
||||||
with open(refollow_filename, 'a+',
|
with open(refollow_filename, 'a+',
|
||||||
encoding='utf-8') as refoll:
|
encoding='utf-8') as refoll:
|
||||||
refoll.write(moved_to_handle + '\n')
|
refoll.write(moved_to_handle + '\n')
|
||||||
|
except OSError:
|
||||||
|
print('EX: ' +
|
||||||
|
'_update_moved_handle unable to append ' +
|
||||||
|
refollow_filename)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
with open(refollow_filename, 'w+',
|
with open(refollow_filename, 'w+',
|
||||||
encoding='utf-8') as refoll:
|
encoding='utf-8') as refoll:
|
||||||
refoll.write(moved_to_handle + '\n')
|
refoll.write(moved_to_handle + '\n')
|
||||||
|
except OSError:
|
||||||
|
print('EX: _update_moved_handle unable to write ' +
|
||||||
|
refollow_filename)
|
||||||
|
|
||||||
followers_filename = \
|
followers_filename = \
|
||||||
acct_dir(base_dir, nickname, domain) + '/followers.txt'
|
acct_dir(base_dir, nickname, domain) + '/followers.txt'
|
||||||
if os.path.isfile(followers_filename):
|
if os.path.isfile(followers_filename):
|
||||||
follower_handles = []
|
follower_handles = []
|
||||||
|
try:
|
||||||
with open(followers_filename, 'r', encoding='utf-8') as foll3:
|
with open(followers_filename, 'r', encoding='utf-8') as foll3:
|
||||||
follower_handles = foll3.readlines()
|
follower_handles = foll3.readlines()
|
||||||
|
except OSError:
|
||||||
|
print('EX: _update_moved_handle unable to read ' +
|
||||||
|
followers_filename)
|
||||||
|
|
||||||
handle_lower = handle.lower()
|
handle_lower = handle.lower()
|
||||||
|
|
||||||
# remove followers who have moved
|
# remove followers who have moved
|
||||||
|
try:
|
||||||
with open(followers_filename, 'w+', encoding='utf-8') as foll4:
|
with open(followers_filename, 'w+', encoding='utf-8') as foll4:
|
||||||
for follower_handle in follower_handles:
|
for follower_handle in follower_handles:
|
||||||
if follower_handle.strip("\n").strip("\r").lower() != \
|
if follower_handle.strip("\n").strip("\r").lower() != \
|
||||||
|
@ -184,6 +198,9 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
|
||||||
else:
|
else:
|
||||||
ctr += 1
|
ctr += 1
|
||||||
print('Removed follower who has moved ' + handle)
|
print('Removed follower who has moved ' + handle)
|
||||||
|
except OSError:
|
||||||
|
print('EX: _update_moved_handle unable to remove moved follower ' +
|
||||||
|
handle)
|
||||||
|
|
||||||
return ctr
|
return ctr
|
||||||
|
|
||||||
|
|
|
@ -43,20 +43,32 @@ def _notify_on_post_arrival(base_dir: str, nickname: str, domain: str,
|
||||||
following_handles = ''
|
following_handles = ''
|
||||||
if os.path.isfile(notify_on_post_filename):
|
if os.path.isfile(notify_on_post_filename):
|
||||||
print('notify file exists')
|
print('notify file exists')
|
||||||
|
try:
|
||||||
with open(notify_on_post_filename, 'r',
|
with open(notify_on_post_filename, 'r',
|
||||||
encoding='utf-8') as calendar_file:
|
encoding='utf-8') as calendar_file:
|
||||||
following_handles = calendar_file.read()
|
following_handles = calendar_file.read()
|
||||||
|
except OSError:
|
||||||
|
print('EX: _notify_on_post_arrival unable to read 1 ' +
|
||||||
|
notify_on_post_filename)
|
||||||
else:
|
else:
|
||||||
# create a new notifyOnPost file from the following file
|
# create a new notifyOnPost file from the following file
|
||||||
print('Creating notifyOnPost file ' + notify_on_post_filename)
|
print('Creating notifyOnPost file ' + notify_on_post_filename)
|
||||||
following_handles = ''
|
following_handles = ''
|
||||||
|
try:
|
||||||
with open(following_filename, 'r',
|
with open(following_filename, 'r',
|
||||||
encoding='utf-8') as following_file:
|
encoding='utf-8') as following_file:
|
||||||
following_handles = following_file.read()
|
following_handles = following_file.read()
|
||||||
|
except OSError:
|
||||||
|
print('EX: _notify_on_post_arrival unable to read 2 ' +
|
||||||
|
following_filename)
|
||||||
if add:
|
if add:
|
||||||
|
try:
|
||||||
with open(notify_on_post_filename, 'w+',
|
with open(notify_on_post_filename, 'w+',
|
||||||
encoding='utf-8') as fp_notify:
|
encoding='utf-8') as fp_notify:
|
||||||
fp_notify.write(following_handles + handle + '\n')
|
fp_notify.write(following_handles + handle + '\n')
|
||||||
|
except OSError:
|
||||||
|
print('EX: _notify_on_post_arrival unable to write 1' +
|
||||||
|
notify_on_post_filename)
|
||||||
|
|
||||||
# already in the notifyOnPost file?
|
# already in the notifyOnPost file?
|
||||||
if handle + '\n' in following_handles or \
|
if handle + '\n' in following_handles or \
|
||||||
|
@ -74,18 +86,26 @@ def _notify_on_post_arrival(base_dir: str, nickname: str, domain: str,
|
||||||
new_following_handles += followed + '\n'
|
new_following_handles += followed + '\n'
|
||||||
following_handles = new_following_handles
|
following_handles = new_following_handles
|
||||||
|
|
||||||
|
try:
|
||||||
with open(notify_on_post_filename, 'w+',
|
with open(notify_on_post_filename, 'w+',
|
||||||
encoding='utf-8') as fp_notify:
|
encoding='utf-8') as fp_notify:
|
||||||
fp_notify.write(following_handles)
|
fp_notify.write(following_handles)
|
||||||
|
except OSError:
|
||||||
|
print('EX: _notify_on_post_arrival unable to write 2' +
|
||||||
|
notify_on_post_filename)
|
||||||
else:
|
else:
|
||||||
print(handle + ' not in notifyOnPost.txt')
|
print(handle + ' not in notifyOnPost.txt')
|
||||||
# not already in the notifyOnPost file
|
# not already in the notifyOnPost file
|
||||||
if add:
|
if add:
|
||||||
# append to the list of handles
|
# append to the list of handles
|
||||||
following_handles += handle + '\n'
|
following_handles += handle + '\n'
|
||||||
|
try:
|
||||||
with open(notify_on_post_filename, 'w+',
|
with open(notify_on_post_filename, 'w+',
|
||||||
encoding='utf-8') as fp_notify:
|
encoding='utf-8') as fp_notify:
|
||||||
fp_notify.write(following_handles)
|
fp_notify.write(following_handles)
|
||||||
|
except OSError:
|
||||||
|
print('EX: _notify_on_post_arrival unable to write 3' +
|
||||||
|
notify_on_post_filename)
|
||||||
|
|
||||||
|
|
||||||
def add_notify_on_post(base_dir: str, nickname: str, domain: str,
|
def add_notify_on_post(base_dir: str, nickname: str, domain: str,
|
||||||
|
@ -118,7 +138,11 @@ def notify_when_person_posts(base_dir: str, nickname: str, domain: str,
|
||||||
handle = following_nickname + '@' + following_domain
|
handle = following_nickname + '@' + following_domain
|
||||||
if not os.path.isfile(notify_on_post_filename):
|
if not os.path.isfile(notify_on_post_filename):
|
||||||
# create a new notifyOnPost file
|
# create a new notifyOnPost file
|
||||||
|
try:
|
||||||
with open(notify_on_post_filename, 'w+',
|
with open(notify_on_post_filename, 'w+',
|
||||||
encoding='utf-8') as fp_notify:
|
encoding='utf-8') as fp_notify:
|
||||||
fp_notify.write('')
|
fp_notify.write('')
|
||||||
|
except OSError:
|
||||||
|
print('EX: notify_when_person_posts unable to write ' +
|
||||||
|
notify_on_post_filename)
|
||||||
return text_in_file(handle + '\n', notify_on_post_filename, False)
|
return text_in_file(handle + '\n', notify_on_post_filename, False)
|
||||||
|
|
27
posts.py
27
posts.py
|
@ -2786,13 +2786,21 @@ def thread_send_post(session, post_json_str: str, federation_list: [],
|
||||||
# save the log file
|
# save the log file
|
||||||
post_log_filename = base_dir + '/post.log'
|
post_log_filename = base_dir + '/post.log'
|
||||||
if os.path.isfile(post_log_filename):
|
if os.path.isfile(post_log_filename):
|
||||||
|
try:
|
||||||
with open(post_log_filename, 'a+',
|
with open(post_log_filename, 'a+',
|
||||||
encoding='utf-8') as log_file:
|
encoding='utf-8') as log_file:
|
||||||
log_file.write(log_str + '\n')
|
log_file.write(log_str + '\n')
|
||||||
|
except OSError:
|
||||||
|
print('EX: thread_send_post unable to append ' +
|
||||||
|
post_log_filename)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
with open(post_log_filename, 'w+',
|
with open(post_log_filename, 'w+',
|
||||||
encoding='utf-8') as log_file:
|
encoding='utf-8') as log_file:
|
||||||
log_file.write(log_str + '\n')
|
log_file.write(log_str + '\n')
|
||||||
|
except OSError:
|
||||||
|
print('EX: thread_send_post unable to write ' +
|
||||||
|
post_log_filename)
|
||||||
|
|
||||||
if post_result:
|
if post_result:
|
||||||
_remove_send_block(base_dir, nickname, domain, inbox_url)
|
_remove_send_block(base_dir, nickname, domain, inbox_url)
|
||||||
|
@ -5108,16 +5116,25 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
|
||||||
index_ctr = 0
|
index_ctr = 0
|
||||||
# get the existing index entries as a string
|
# get the existing index entries as a string
|
||||||
new_index = ''
|
new_index = ''
|
||||||
|
try:
|
||||||
with open(index_filename, 'r', encoding='utf-8') as index_file:
|
with open(index_filename, 'r', encoding='utf-8') as index_file:
|
||||||
for post_id in index_file:
|
for post_id in index_file:
|
||||||
new_index += post_id
|
new_index += post_id
|
||||||
index_ctr += 1
|
index_ctr += 1
|
||||||
if index_ctr >= max_posts_in_box:
|
if index_ctr >= max_posts_in_box:
|
||||||
break
|
break
|
||||||
|
except OSError as ex:
|
||||||
|
print('EX: archive_posts_for_person unable to read ' +
|
||||||
|
index_filename + ' ' + str(ex))
|
||||||
# save the new index file
|
# save the new index file
|
||||||
if len(new_index) > 0:
|
if len(new_index) > 0:
|
||||||
with open(index_filename, 'w+', encoding='utf-8') as index_file:
|
try:
|
||||||
|
with open(index_filename, 'w+',
|
||||||
|
encoding='utf-8') as index_file:
|
||||||
index_file.write(new_index)
|
index_file.write(new_index)
|
||||||
|
except OSError:
|
||||||
|
print('EX: archive_posts_for_person unable to write ' +
|
||||||
|
index_filename)
|
||||||
|
|
||||||
posts_in_box_dict = {}
|
posts_in_box_dict = {}
|
||||||
posts_ctr = 0
|
posts_ctr = 0
|
||||||
|
@ -5559,9 +5576,13 @@ def check_domains(session, base_dir: str,
|
||||||
update_follower_warnings = True
|
update_follower_warnings = True
|
||||||
|
|
||||||
if update_follower_warnings and follower_warning_str:
|
if update_follower_warnings and follower_warning_str:
|
||||||
|
try:
|
||||||
with open(follower_warning_filename, 'w+',
|
with open(follower_warning_filename, 'w+',
|
||||||
encoding='utf-8') as fp_warn:
|
encoding='utf-8') as fp_warn:
|
||||||
fp_warn.write(follower_warning_str)
|
fp_warn.write(follower_warning_str)
|
||||||
|
except OSError:
|
||||||
|
print('EX: check_domains unable to write ' +
|
||||||
|
follower_warning_filename)
|
||||||
if not single_check:
|
if not single_check:
|
||||||
print(follower_warning_str)
|
print(follower_warning_str)
|
||||||
|
|
||||||
|
@ -5640,9 +5661,13 @@ def _reject_announce(announce_filename: str,
|
||||||
|
|
||||||
# reject the post referenced by the announce activity object
|
# reject the post referenced by the announce activity object
|
||||||
if not os.path.isfile(announce_filename + '.reject'):
|
if not os.path.isfile(announce_filename + '.reject'):
|
||||||
|
try:
|
||||||
with open(announce_filename + '.reject', 'w+',
|
with open(announce_filename + '.reject', 'w+',
|
||||||
encoding='utf-8') as reject_announce_file:
|
encoding='utf-8') as reject_announce_file:
|
||||||
reject_announce_file.write('\n')
|
reject_announce_file.write('\n')
|
||||||
|
except OSError:
|
||||||
|
print('EX: _reject_announce unable to write ' +
|
||||||
|
announce_filename + '.reject')
|
||||||
|
|
||||||
|
|
||||||
def download_announce(session, base_dir: str, http_prefix: str,
|
def download_announce(session, base_dir: str, http_prefix: str,
|
||||||
|
|
|
@ -179,9 +179,14 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
|
||||||
# write the new schedule index file
|
# write the new schedule index file
|
||||||
schedule_index_file = \
|
schedule_index_file = \
|
||||||
acct_handle_dir(base_dir, handle) + '/schedule.index'
|
acct_handle_dir(base_dir, handle) + '/schedule.index'
|
||||||
with open(schedule_index_file, 'w+', encoding='utf-8') as schedule_file:
|
try:
|
||||||
|
with open(schedule_index_file, 'w+',
|
||||||
|
encoding='utf-8') as schedule_file:
|
||||||
for line in index_lines:
|
for line in index_lines:
|
||||||
schedule_file.write(line)
|
schedule_file.write(line)
|
||||||
|
except OSError:
|
||||||
|
print('EX: _update_post_schedule unable to write ' +
|
||||||
|
schedule_index_file)
|
||||||
|
|
||||||
|
|
||||||
def run_post_schedule(base_dir: str, httpd, max_scheduled_posts: int):
|
def run_post_schedule(base_dir: str, httpd, max_scheduled_posts: int):
|
||||||
|
|
|
@ -1781,8 +1781,12 @@ def _generate_next_shares_token_update(base_dir: str,
|
||||||
next_update_sec = curr_time + next_update_interval
|
next_update_sec = curr_time + next_update_interval
|
||||||
updated = True
|
updated = True
|
||||||
if updated:
|
if updated:
|
||||||
|
try:
|
||||||
with open(token_update_filename, 'w+', encoding='utf-8') as fp_tok:
|
with open(token_update_filename, 'w+', encoding='utf-8') as fp_tok:
|
||||||
fp_tok.write(str(next_update_sec))
|
fp_tok.write(str(next_update_sec))
|
||||||
|
except OSError:
|
||||||
|
print('EX: _generate_next_shares_token_update unable to write' +
|
||||||
|
token_update_filename)
|
||||||
|
|
||||||
|
|
||||||
def _regenerate_shares_token(base_dir: str, domain_full: str,
|
def _regenerate_shares_token(base_dir: str, domain_full: str,
|
||||||
|
|
34
theme.py
34
theme.py
|
@ -397,8 +397,11 @@ def _set_theme_from_dict(base_dir: str, name: str,
|
||||||
css = set_css_param(css, 'language-direction', 'rtl')
|
css = set_css_param(css, 'language-direction', 'rtl')
|
||||||
|
|
||||||
filename = base_dir + '/' + filename
|
filename = base_dir + '/' + filename
|
||||||
|
try:
|
||||||
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
||||||
cssfile.write(css)
|
cssfile.write(css)
|
||||||
|
except OSError:
|
||||||
|
print('EX: _set_theme_from_dict unable to write ' + filename)
|
||||||
|
|
||||||
screen_name = (
|
screen_name = (
|
||||||
'login', 'follow', 'options', 'search', 'welcome'
|
'login', 'follow', 'options', 'search', 'welcome'
|
||||||
|
@ -417,11 +420,14 @@ def _set_background_format(base_dir: str,
|
||||||
css_filename = base_dir + '/' + background_type + '.css'
|
css_filename = base_dir + '/' + background_type + '.css'
|
||||||
if not os.path.isfile(css_filename):
|
if not os.path.isfile(css_filename):
|
||||||
return
|
return
|
||||||
|
try:
|
||||||
with open(css_filename, 'r', encoding='utf-8') as cssfile:
|
with open(css_filename, 'r', encoding='utf-8') as cssfile:
|
||||||
css = cssfile.read()
|
css = cssfile.read()
|
||||||
css = css.replace('background.jpg', 'background.' + extension)
|
css = css.replace('background.jpg', 'background.' + extension)
|
||||||
with open(css_filename, 'w+', encoding='utf-8') as cssfile2:
|
with open(css_filename, 'w+', encoding='utf-8') as cssfile2:
|
||||||
cssfile2.write(css)
|
cssfile2.write(css)
|
||||||
|
except OSError as ex:
|
||||||
|
print('EX: _set_background_format ' + css_filename + ' ' + str(ex))
|
||||||
|
|
||||||
|
|
||||||
def enable_grayscale(base_dir: str) -> None:
|
def enable_grayscale(base_dir: str) -> None:
|
||||||
|
@ -432,19 +438,28 @@ def enable_grayscale(base_dir: str) -> None:
|
||||||
template_filename = base_dir + '/' + filename
|
template_filename = base_dir + '/' + filename
|
||||||
if not os.path.isfile(template_filename):
|
if not os.path.isfile(template_filename):
|
||||||
continue
|
continue
|
||||||
|
try:
|
||||||
with open(template_filename, 'r', encoding='utf-8') as cssfile:
|
with open(template_filename, 'r', encoding='utf-8') as cssfile:
|
||||||
css = cssfile.read()
|
css = cssfile.read()
|
||||||
if 'grayscale' not in css:
|
if 'grayscale' not in css:
|
||||||
css = \
|
css = \
|
||||||
css.replace('body, html {',
|
css.replace('body, html {',
|
||||||
'body, html {\n filter: grayscale(100%);')
|
'body, html {\n' +
|
||||||
|
' filter: grayscale(100%);')
|
||||||
filename = base_dir + '/' + filename
|
filename = base_dir + '/' + filename
|
||||||
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
||||||
cssfile.write(css)
|
cssfile.write(css)
|
||||||
|
except OSError as ex:
|
||||||
|
print('EX: enable_grayscale unable to read ' +
|
||||||
|
template_filename + ' ' + str(ex))
|
||||||
grayscale_filename = base_dir + '/accounts/.grayscale'
|
grayscale_filename = base_dir + '/accounts/.grayscale'
|
||||||
if not os.path.isfile(grayscale_filename):
|
if not os.path.isfile(grayscale_filename):
|
||||||
|
try:
|
||||||
with open(grayscale_filename, 'w+', encoding='utf-8') as grayfile:
|
with open(grayscale_filename, 'w+', encoding='utf-8') as grayfile:
|
||||||
grayfile.write(' ')
|
grayfile.write(' ')
|
||||||
|
except OSError as ex:
|
||||||
|
print('EX: enable_grayscale unable to write ' +
|
||||||
|
grayscale_filename + ' ' + str(ex))
|
||||||
|
|
||||||
|
|
||||||
def disable_grayscale(base_dir: str) -> None:
|
def disable_grayscale(base_dir: str) -> None:
|
||||||
|
@ -455,6 +470,7 @@ def disable_grayscale(base_dir: str) -> None:
|
||||||
template_filename = base_dir + '/' + filename
|
template_filename = base_dir + '/' + filename
|
||||||
if not os.path.isfile(template_filename):
|
if not os.path.isfile(template_filename):
|
||||||
continue
|
continue
|
||||||
|
try:
|
||||||
with open(template_filename, 'r', encoding='utf-8') as cssfile:
|
with open(template_filename, 'r', encoding='utf-8') as cssfile:
|
||||||
css = cssfile.read()
|
css = cssfile.read()
|
||||||
if 'grayscale' in css:
|
if 'grayscale' in css:
|
||||||
|
@ -463,6 +479,9 @@ def disable_grayscale(base_dir: str) -> None:
|
||||||
filename = base_dir + '/' + filename
|
filename = base_dir + '/' + filename
|
||||||
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
||||||
cssfile.write(css)
|
cssfile.write(css)
|
||||||
|
except OSError as ex:
|
||||||
|
print('EX: disable_grayscale unable to read ' +
|
||||||
|
template_filename + ' ' + str(ex))
|
||||||
grayscale_filename = base_dir + '/accounts/.grayscale'
|
grayscale_filename = base_dir + '/accounts/.grayscale'
|
||||||
if os.path.isfile(grayscale_filename):
|
if os.path.isfile(grayscale_filename):
|
||||||
try:
|
try:
|
||||||
|
@ -488,8 +507,11 @@ def _set_dyslexic_font(base_dir: str) -> bool:
|
||||||
"') format('woff2')")
|
"') format('woff2')")
|
||||||
css = set_css_param(css, "*font-family", "'OpenDyslexic'")
|
css = set_css_param(css, "*font-family", "'OpenDyslexic'")
|
||||||
filename = base_dir + '/' + filename
|
filename = base_dir + '/' + filename
|
||||||
|
try:
|
||||||
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
||||||
cssfile.write(css)
|
cssfile.write(css)
|
||||||
|
except OSError:
|
||||||
|
print('EX: _set_dyslexic_font unable to write ' + filename)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -528,8 +550,11 @@ def _set_custom_font(base_dir: str):
|
||||||
css = set_css_param(css, "*font-family", "'CustomFont'")
|
css = set_css_param(css, "*font-family", "'CustomFont'")
|
||||||
css = set_css_param(css, "header-font", "'CustomFont'")
|
css = set_css_param(css, "header-font", "'CustomFont'")
|
||||||
filename = base_dir + '/' + filename
|
filename = base_dir + '/' + filename
|
||||||
|
try:
|
||||||
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
||||||
cssfile.write(css)
|
cssfile.write(css)
|
||||||
|
except OSError:
|
||||||
|
print('EX: _set_custom_font unable to write ' + filename)
|
||||||
|
|
||||||
|
|
||||||
def set_theme_from_designer(base_dir: str, theme_name: str, domain: str,
|
def set_theme_from_designer(base_dir: str, theme_name: str, domain: str,
|
||||||
|
@ -863,8 +888,11 @@ def _set_clear_cache_flag(base_dir: str) -> None:
|
||||||
if not os.path.isdir(base_dir + '/accounts'):
|
if not os.path.isdir(base_dir + '/accounts'):
|
||||||
return
|
return
|
||||||
flag_filename = base_dir + '/accounts/.clear_cache'
|
flag_filename = base_dir + '/accounts/.clear_cache'
|
||||||
|
try:
|
||||||
with open(flag_filename, 'w+', encoding='utf-8') as fp_flag:
|
with open(flag_filename, 'w+', encoding='utf-8') as fp_flag:
|
||||||
fp_flag.write('\n')
|
fp_flag.write('\n')
|
||||||
|
except OSError:
|
||||||
|
print('EX: _set_clear_cache_flag unable to write ' + flag_filename)
|
||||||
|
|
||||||
|
|
||||||
def set_theme(base_dir: str, name: str, domain: str,
|
def set_theme(base_dir: str, name: str, domain: str,
|
||||||
|
@ -942,9 +970,13 @@ def update_default_themes_list(base_dir: str) -> None:
|
||||||
"""
|
"""
|
||||||
theme_names = get_themes_list(base_dir)
|
theme_names = get_themes_list(base_dir)
|
||||||
default_themes_filename = base_dir + '/defaultthemes.txt'
|
default_themes_filename = base_dir + '/defaultthemes.txt'
|
||||||
|
try:
|
||||||
with open(default_themes_filename, 'w+', encoding='utf-8') as fp_def:
|
with open(default_themes_filename, 'w+', encoding='utf-8') as fp_def:
|
||||||
for name in theme_names:
|
for name in theme_names:
|
||||||
fp_def.write(name + '\n')
|
fp_def.write(name + '\n')
|
||||||
|
except OSError:
|
||||||
|
print('EX: update_default_themes_list unable to write ' +
|
||||||
|
default_themes_filename)
|
||||||
|
|
||||||
|
|
||||||
def scan_themes_for_scripts(base_dir: str) -> bool:
|
def scan_themes_for_scripts(base_dir: str) -> bool:
|
||||||
|
|
45
utils.py
45
utils.py
|
@ -485,9 +485,13 @@ def refresh_newswire(base_dir: str):
|
||||||
refresh_newswire_filename = base_dir + '/accounts/.refresh_newswire'
|
refresh_newswire_filename = base_dir + '/accounts/.refresh_newswire'
|
||||||
if os.path.isfile(refresh_newswire_filename):
|
if os.path.isfile(refresh_newswire_filename):
|
||||||
return
|
return
|
||||||
|
try:
|
||||||
with open(refresh_newswire_filename, 'w+',
|
with open(refresh_newswire_filename, 'w+',
|
||||||
encoding='utf-8') as refresh_file:
|
encoding='utf-8') as refresh_file:
|
||||||
refresh_file.write('\n')
|
refresh_file.write('\n')
|
||||||
|
except OSError:
|
||||||
|
print('EX: refresh_newswire unable to write ' +
|
||||||
|
refresh_newswire_filename)
|
||||||
|
|
||||||
|
|
||||||
def get_sha_256(msg: str):
|
def get_sha_256(msg: str):
|
||||||
|
@ -1731,8 +1735,13 @@ def _set_default_pet_name(base_dir: str, nickname: str, domain: str,
|
||||||
follow_nickname + '@' + follow_domain + '\n'
|
follow_nickname + '@' + follow_domain + '\n'
|
||||||
if not os.path.isfile(petnames_filename):
|
if not os.path.isfile(petnames_filename):
|
||||||
# if there is no existing petnames lookup file
|
# if there is no existing petnames lookup file
|
||||||
with open(petnames_filename, 'w+', encoding='utf-8') as petnames_file:
|
try:
|
||||||
|
with open(petnames_filename, 'w+',
|
||||||
|
encoding='utf-8') as petnames_file:
|
||||||
petnames_file.write(petname_lookup_entry)
|
petnames_file.write(petname_lookup_entry)
|
||||||
|
except OSError:
|
||||||
|
print('EX: _set_default_pet_name unable to write ' +
|
||||||
|
petnames_filename)
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(petnames_filename, 'r', encoding='utf-8') as petnames_file:
|
with open(petnames_filename, 'r', encoding='utf-8') as petnames_file:
|
||||||
|
@ -1792,15 +1801,23 @@ def follow_person(base_dir: str, nickname: str, domain: str,
|
||||||
if text_in_file(handle_to_follow, unfollowed_filename):
|
if text_in_file(handle_to_follow, unfollowed_filename):
|
||||||
# remove them from the unfollowed file
|
# remove them from the unfollowed file
|
||||||
new_lines = ''
|
new_lines = ''
|
||||||
|
try:
|
||||||
with open(unfollowed_filename, 'r',
|
with open(unfollowed_filename, 'r',
|
||||||
encoding='utf-8') as unfoll_file:
|
encoding='utf-8') as unfoll_file:
|
||||||
lines = unfoll_file.readlines()
|
lines = unfoll_file.readlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if handle_to_follow not in line:
|
if handle_to_follow not in line:
|
||||||
new_lines += line
|
new_lines += line
|
||||||
|
except OSError:
|
||||||
|
print('EX: follow_person unable to read ' +
|
||||||
|
unfollowed_filename)
|
||||||
|
try:
|
||||||
with open(unfollowed_filename, 'w+',
|
with open(unfollowed_filename, 'w+',
|
||||||
encoding='utf-8') as unfoll_file:
|
encoding='utf-8') as unfoll_file:
|
||||||
unfoll_file.write(new_lines)
|
unfoll_file.write(new_lines)
|
||||||
|
except OSError:
|
||||||
|
print('EX: follow_person unable to write ' +
|
||||||
|
unfollowed_filename)
|
||||||
|
|
||||||
if not os.path.isdir(base_dir + '/accounts'):
|
if not os.path.isdir(base_dir + '/accounts'):
|
||||||
os.mkdir(base_dir + '/accounts')
|
os.mkdir(base_dir + '/accounts')
|
||||||
|
@ -1831,8 +1848,11 @@ def follow_person(base_dir: str, nickname: str, domain: str,
|
||||||
' creating new following file to follow ' +
|
' creating new following file to follow ' +
|
||||||
handle_to_follow +
|
handle_to_follow +
|
||||||
', filename is ' + filename)
|
', filename is ' + filename)
|
||||||
|
try:
|
||||||
with open(filename, 'w+', encoding='utf-8') as foll_file:
|
with open(filename, 'w+', encoding='utf-8') as foll_file:
|
||||||
foll_file.write(handle_to_follow + '\n')
|
foll_file.write(handle_to_follow + '\n')
|
||||||
|
except OSError:
|
||||||
|
print('EX: follow_person unable to write ' + filename)
|
||||||
|
|
||||||
if follow_file.endswith('following.txt'):
|
if follow_file.endswith('following.txt'):
|
||||||
# Default to adding new follows to the calendar.
|
# Default to adding new follows to the calendar.
|
||||||
|
@ -2126,6 +2146,7 @@ def remove_moderation_post_from_index(base_dir: str, post_url: str,
|
||||||
return
|
return
|
||||||
post_id = remove_id_ending(post_url)
|
post_id = remove_id_ending(post_url)
|
||||||
if text_in_file(post_id, moderation_index_file):
|
if text_in_file(post_id, moderation_index_file):
|
||||||
|
try:
|
||||||
with open(moderation_index_file, 'r',
|
with open(moderation_index_file, 'r',
|
||||||
encoding='utf-8') as file1:
|
encoding='utf-8') as file1:
|
||||||
lines = file1.readlines()
|
lines = file1.readlines()
|
||||||
|
@ -2138,6 +2159,9 @@ def remove_moderation_post_from_index(base_dir: str, post_url: str,
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: removed ' + post_id +
|
print('DEBUG: removed ' + post_id +
|
||||||
' from moderation index')
|
' from moderation index')
|
||||||
|
except OSError as ex:
|
||||||
|
print('EX: remove_moderation_post_from_index unable to read ' +
|
||||||
|
moderation_index_file + ' ' + str(ex))
|
||||||
|
|
||||||
|
|
||||||
def _is_reply_to_blog_post(base_dir: str, nickname: str, domain: str,
|
def _is_reply_to_blog_post(base_dir: str, nickname: str, domain: str,
|
||||||
|
@ -2295,9 +2319,13 @@ def _remove_post_id_from_tag_index(tag_index_filename: str,
|
||||||
'unable to delete tag index ' + str(tag_index_filename))
|
'unable to delete tag index ' + str(tag_index_filename))
|
||||||
else:
|
else:
|
||||||
# write the new hashtag index without the given post in it
|
# write the new hashtag index without the given post in it
|
||||||
|
try:
|
||||||
with open(tag_index_filename, 'w+',
|
with open(tag_index_filename, 'w+',
|
||||||
encoding='utf-8') as index_file:
|
encoding='utf-8') as index_file:
|
||||||
index_file.write(newlines)
|
index_file.write(newlines)
|
||||||
|
except OSError:
|
||||||
|
print('EX: _remove_post_id_from_tag_index unable to write ' +
|
||||||
|
tag_index_filename)
|
||||||
|
|
||||||
|
|
||||||
def _delete_hashtags_on_post(base_dir: str, post_json_object: {}) -> None:
|
def _delete_hashtags_on_post(base_dir: str, post_json_object: {}) -> None:
|
||||||
|
@ -2364,8 +2392,13 @@ def _delete_conversation_post(base_dir: str, nickname: str, domain: str,
|
||||||
return False
|
return False
|
||||||
conversation_str = conversation_str.replace(post_id + '\n', '')
|
conversation_str = conversation_str.replace(post_id + '\n', '')
|
||||||
if conversation_str:
|
if conversation_str:
|
||||||
with open(conversation_filename, 'w+', encoding='utf-8') as conv_file:
|
try:
|
||||||
|
with open(conversation_filename, 'w+',
|
||||||
|
encoding='utf-8') as conv_file:
|
||||||
conv_file.write(conversation_str)
|
conv_file.write(conversation_str)
|
||||||
|
except OSError:
|
||||||
|
print('EX: _delete_conversation_post unable to write ' +
|
||||||
|
conversation_filename)
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(conversation_filename + '.muted'):
|
if os.path.isfile(conversation_filename + '.muted'):
|
||||||
try:
|
try:
|
||||||
|
@ -3454,9 +3487,13 @@ def reject_post_id(base_dir: str, nickname: str, domain: str,
|
||||||
if recent_posts_cache['html'].get(post_url):
|
if recent_posts_cache['html'].get(post_url):
|
||||||
del recent_posts_cache['html'][post_url]
|
del recent_posts_cache['html'][post_url]
|
||||||
|
|
||||||
|
try:
|
||||||
with open(post_filename + '.reject', 'w+',
|
with open(post_filename + '.reject', 'w+',
|
||||||
encoding='utf-8') as reject_file:
|
encoding='utf-8') as reject_file:
|
||||||
reject_file.write('\n')
|
reject_file.write('\n')
|
||||||
|
except OSError:
|
||||||
|
print('EX: reject_post_id unable to write ' +
|
||||||
|
post_filename + '.reject')
|
||||||
|
|
||||||
|
|
||||||
def is_chat_message(post_json_object: {}) -> bool:
|
def is_chat_message(post_json_object: {}) -> bool:
|
||||||
|
@ -4246,8 +4283,12 @@ def set_account_timezone(base_dir: str, nickname: str, domain: str,
|
||||||
tz_filename = \
|
tz_filename = \
|
||||||
acct_dir(base_dir, nickname, domain) + '/timezone.txt'
|
acct_dir(base_dir, nickname, domain) + '/timezone.txt'
|
||||||
timezone = timezone.strip()
|
timezone = timezone.strip()
|
||||||
|
try:
|
||||||
with open(tz_filename, 'w+', encoding='utf-8') as fp_timezone:
|
with open(tz_filename, 'w+', encoding='utf-8') as fp_timezone:
|
||||||
fp_timezone.write(timezone)
|
fp_timezone.write(timezone)
|
||||||
|
except OSError:
|
||||||
|
print('EX: set_account_timezone unable to write ' +
|
||||||
|
tz_filename)
|
||||||
|
|
||||||
|
|
||||||
def _is_onion_request(calling_domain: str, referer_domain: str,
|
def _is_onion_request(calling_domain: str, referer_domain: str,
|
||||||
|
|
|
@ -36,8 +36,12 @@ def welcome_screen_is_complete(base_dir: str,
|
||||||
if not os.path.isdir(account_path):
|
if not os.path.isdir(account_path):
|
||||||
return
|
return
|
||||||
complete_filename = account_path + '/.welcome_complete'
|
complete_filename = account_path + '/.welcome_complete'
|
||||||
|
try:
|
||||||
with open(complete_filename, 'w+', encoding='utf-8') as fp_comp:
|
with open(complete_filename, 'w+', encoding='utf-8') as fp_comp:
|
||||||
fp_comp.write('\n')
|
fp_comp.write('\n')
|
||||||
|
except OSError:
|
||||||
|
print('EX: welcome_screen_is_complete unable to write ' +
|
||||||
|
complete_filename)
|
||||||
|
|
||||||
|
|
||||||
def html_welcome_screen(base_dir: str, nickname: str,
|
def html_welcome_screen(base_dir: str, nickname: str,
|
||||||
|
|
Loading…
Reference in New Issue