mirror of https://gitlab.com/bashrc2/epicyon
Replace file operations with functions
parent
6a42cbca51
commit
e06a331fe0
78
blocking.py
78
blocking.py
|
|
@ -486,20 +486,22 @@ def remove_global_block(base_dir: str,
|
||||||
unblock_handle = unblock_nickname + '@' + unblock_domain
|
unblock_handle = unblock_nickname + '@' + unblock_domain
|
||||||
if os.path.isfile(unblocking_filename):
|
if os.path.isfile(unblocking_filename):
|
||||||
if text_in_file(unblock_handle, unblocking_filename):
|
if text_in_file(unblock_handle, unblocking_filename):
|
||||||
try:
|
unblocking_list: list[str] = \
|
||||||
with open(unblocking_filename, 'r',
|
load_list(unblocking_filename,
|
||||||
encoding='utf-8') as fp_unblock:
|
'EX: failed to remove global block ' +
|
||||||
with open(unblocking_filename + '.new', 'w+',
|
unblocking_filename + ' 1 [ex]')
|
||||||
encoding='utf-8') as fpnew:
|
if unblocking_list is None:
|
||||||
for line in fp_unblock:
|
|
||||||
handle = remove_eol(line)
|
|
||||||
if unblock_handle not in line:
|
|
||||||
fpnew.write(handle + '\n')
|
|
||||||
except OSError as ex:
|
|
||||||
print('EX: failed to remove global block ' +
|
|
||||||
unblocking_filename + ' ' + str(ex))
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
text: str = ''
|
||||||
|
for line in unblocking_list:
|
||||||
|
handle = remove_eol(line)
|
||||||
|
if unblock_handle not in line:
|
||||||
|
text += handle + '\n'
|
||||||
|
save_string(text, unblocking_filename + '.new',
|
||||||
|
'EX: failed to remove global block ' +
|
||||||
|
unblocking_filename + ' 1 [ex]')
|
||||||
|
|
||||||
if os.path.isfile(unblocking_filename + '.new'):
|
if os.path.isfile(unblocking_filename + '.new'):
|
||||||
try:
|
try:
|
||||||
os.rename(unblocking_filename + '.new',
|
os.rename(unblocking_filename + '.new',
|
||||||
|
|
@ -513,20 +515,22 @@ def remove_global_block(base_dir: str,
|
||||||
unblock_hashtag = unblock_nickname
|
unblock_hashtag = unblock_nickname
|
||||||
if os.path.isfile(unblocking_filename):
|
if os.path.isfile(unblocking_filename):
|
||||||
if text_in_file(unblock_hashtag + '\n', unblocking_filename):
|
if text_in_file(unblock_hashtag + '\n', unblocking_filename):
|
||||||
try:
|
unblocking_list: list[str] = \
|
||||||
with open(unblocking_filename, 'r',
|
load_list(unblocking_filename,
|
||||||
encoding='utf-8') as fp_unblock:
|
'EX: failed to remove global hashtag block ' +
|
||||||
with open(unblocking_filename + '.new', 'w+',
|
unblocking_filename + ' 1 [ex]')
|
||||||
encoding='utf-8') as fpnew:
|
if unblocking_list is None:
|
||||||
for line in fp_unblock:
|
|
||||||
block_line = remove_eol(line)
|
|
||||||
if unblock_hashtag not in line:
|
|
||||||
fpnew.write(block_line + '\n')
|
|
||||||
except OSError as ex:
|
|
||||||
print('EX: failed to remove global hashtag block ' +
|
|
||||||
unblocking_filename + ' ' + str(ex))
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
text: str = ''
|
||||||
|
for line in unblocking_list:
|
||||||
|
block_line = remove_eol(line)
|
||||||
|
if unblock_hashtag not in line:
|
||||||
|
text += block_line + '\n'
|
||||||
|
save_string(text, unblocking_filename + '.new',
|
||||||
|
'EX: failed to remove global hashtag block ' +
|
||||||
|
unblocking_filename + ' 2 [ex]')
|
||||||
|
|
||||||
if os.path.isfile(unblocking_filename + '.new'):
|
if os.path.isfile(unblocking_filename + '.new'):
|
||||||
try:
|
try:
|
||||||
os.rename(unblocking_filename + '.new',
|
os.rename(unblocking_filename + '.new',
|
||||||
|
|
@ -549,20 +553,22 @@ def remove_block(base_dir: str, nickname: str, domain: str,
|
||||||
unblock_handle = unblock_nickname + '@' + unblock_domain
|
unblock_handle = unblock_nickname + '@' + unblock_domain
|
||||||
if os.path.isfile(unblocking_filename):
|
if os.path.isfile(unblocking_filename):
|
||||||
if text_in_file(unblock_handle, unblocking_filename):
|
if text_in_file(unblock_handle, unblocking_filename):
|
||||||
try:
|
unblocking_list: list[str] = \
|
||||||
with open(unblocking_filename, 'r',
|
load_list(unblocking_filename,
|
||||||
encoding='utf-8') as fp_unblock:
|
'EX: failed to remove block ' +
|
||||||
with open(unblocking_filename + '.new', 'w+',
|
unblocking_filename + ' 1 [ex]')
|
||||||
encoding='utf-8') as fpnew:
|
if unblocking_list is None:
|
||||||
for line in fp_unblock:
|
|
||||||
handle = remove_eol(line)
|
|
||||||
if unblock_handle not in line:
|
|
||||||
fpnew.write(handle + '\n')
|
|
||||||
except OSError as ex:
|
|
||||||
print('EX: failed to remove block ' +
|
|
||||||
unblocking_filename + ' ' + str(ex))
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
text: str = ''
|
||||||
|
for line in unblocking_list:
|
||||||
|
handle = remove_eol(line)
|
||||||
|
if unblock_handle not in line:
|
||||||
|
text += handle + '\n'
|
||||||
|
save_string(text, unblocking_filename + '.new',
|
||||||
|
'EX: failed to remove block ' +
|
||||||
|
unblocking_filename + ' 2 [ex]')
|
||||||
|
|
||||||
if os.path.isfile(unblocking_filename + '.new'):
|
if os.path.isfile(unblocking_filename + '.new'):
|
||||||
try:
|
try:
|
||||||
os.rename(unblocking_filename + '.new',
|
os.rename(unblocking_filename + '.new',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue