Replace file checks with functions

main
bashrc 2026-05-02 12:34:27 +01:00
parent 6ef0276622
commit 28d17bfda5
124 changed files with 1184 additions and 1137 deletions

View File

@ -9,7 +9,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "ActivityPub"
import os
from posts import send_signed_json
from flags import has_group_type
from flags import url_permitted
@ -31,6 +30,7 @@ from utils import has_object_string_type
from utils import get_actor_from_post
from utils import is_yggdrasil_address
from timeFunctions import get_current_time_int
from data import is_a_file
def _create_quote_accept_reject(receiving_actor: str,
@ -369,7 +369,7 @@ def _accept_follow(base_dir: str, message_json: {},
# has this person already been unfollowed?
unfollowed_filename = \
acct_dir(base_dir, nickname, accepted_domain_full) + '/unfollowed.txt'
if os.path.isfile(unfollowed_filename):
if is_a_file(unfollowed_filename):
if text_in_file(followed_nickname + '@' + followed_domain_full,
unfollowed_filename):
if debug:

View File

@ -9,7 +9,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "ActivityPub"
import os
from pprint import pprint
from flags import has_group_type
from flags import url_permitted
@ -42,6 +41,7 @@ from webfinger import webfinger_handle
from auth import create_basic_auth_header
from data import save_string
from data import erase_file
from data import is_a_file
def no_of_announces(post_json_object: {}) -> int:
@ -539,7 +539,7 @@ def announce_seen(base_dir: str, nickname: str, domain: str,
if not post_filename:
return False
seen_filename = post_filename + '.seen'
if not os.path.isfile(seen_filename):
if not is_a_file(seen_filename):
return False
if text_in_file(announce_id, seen_filename):
@ -564,7 +564,7 @@ def mark_announce_as_seen(base_dir: str, nickname: str, domain: str,
if not post_filename:
return
seen_filename = post_filename + '.seen'
if os.path.isfile(seen_filename):
if is_a_file(seen_filename):
return
announce_id = remove_id_ending(message_json['id'])
save_string(announce_id, seen_filename,
@ -592,7 +592,7 @@ def undo_announce_collection_entry(recent_posts_cache: {},
get_cached_post_filename(base_dir, nickname, domain,
post_json_object)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
ex_text = \
'EX: undo_announce_collection_entry ' + \
'unable to delete cached post ' + \
@ -662,7 +662,7 @@ def update_announce_collection(recent_posts_cache: {},
get_cached_post_filename(base_dir, nickname, domain,
post_json_object)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
print('update_announce_collection: removing ' +
cached_post_filename)
ex_text = \

View File

@ -24,6 +24,7 @@ from data import append_string
from data import save_string
from data import load_list
from data import move_file
from data import is_a_file
def _hash_password(password: str) -> str:
@ -154,7 +155,7 @@ def authorize_basic(base_dir: str, path: str, auth_header: str,
nickname + ' in Auth header')
return False
password_file = data_dir(base_dir) + '/passwords'
if not os.path.isfile(password_file):
if not is_a_file(password_file):
if debug:
print('DEBUG: passwords file missing')
return False
@ -193,7 +194,7 @@ def store_basic_credentials(base_dir: str,
password_file = dir_str + '/passwords'
store_str = nickname + ':' + _hash_password(password)
if os.path.isfile(password_file):
if is_a_file(password_file):
if text_in_file(nickname + ':', password_file):
# get the existing passwords
passwords_list = \
@ -240,7 +241,7 @@ def remove_password(base_dir: str, nickname: str) -> None:
This is called during account removal
"""
password_file = data_dir(base_dir) + '/passwords'
if os.path.isfile(password_file):
if is_a_file(password_file):
# load the passwords file
passwords_list = \
load_list(password_file,
@ -325,7 +326,7 @@ def record_login_failure(base_dir: str, ip_address: str,
failure_log: str = data_dir(base_dir) + '/loginfailures.log'
write_type: str = 'a+'
if not os.path.isfile(failure_log):
if not is_a_file(failure_log):
write_type: str = 'w+'
curr_time = date_utcnow()
curr_time_str = curr_time.strftime("%Y-%m-%d %H:%M:%SZ")

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Profile Metadata"
import os
from webfinger import webfinger_handle
from auth import create_basic_auth_header
from posts import get_person_box
@ -22,6 +21,7 @@ from utils import acct_dir
from utils import local_actor_url
from utils import has_actor
from utils import get_actor_from_post
from data import is_a_file
def set_availability(base_dir: str, nickname: str, domain: str,
@ -36,11 +36,11 @@ def set_availability(base_dir: str, nickname: str, domain: str,
actor_exists = isinstance(actor_json, dict)
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if not actor_exists:
if os.path.isfile(actor_filename):
if is_a_file(actor_filename):
actor_json = load_json(actor_filename)
if actor_json:
actor_json['availability'] = status
if os.path.isfile(actor_filename):
if is_a_file(actor_filename):
save_json(actor_json, actor_filename)
return True
@ -54,7 +54,7 @@ def get_availability(base_dir: str, nickname: str, domain: str,
actor_exists = isinstance(actor_json, dict)
if not actor_exists:
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if not os.path.isfile(actor_filename):
if not is_a_file(actor_filename):
return False
actor_json = load_json(actor_filename)
if actor_json:

View File

@ -60,6 +60,7 @@ from data import save_flag_file
from data import append_string
from data import erase_file
from data import move_file
from data import is_a_file
def get_global_block_reason(search_text: str,
@ -96,7 +97,7 @@ def get_account_blocks(base_dir: str,
blocking_reasons_filename = \
account_directory + '/blocking_reasons.txt'
if not os.path.isfile(blocking_filename):
if not is_a_file(blocking_filename):
return ''
blocked_accounts_textarea: str = ''
@ -217,11 +218,11 @@ def add_account_blocks(base_dir: str,
account_directory + '/blocking_reasons.txt'
if not blocking_file_text:
if os.path.isfile(blocking_filename):
if is_a_file(blocking_filename):
erase_file(blocking_filename,
'EX: _profile_edit unable to delete blocking ' +
blocking_filename)
if os.path.isfile(blocking_reasons_filename):
if is_a_file(blocking_reasons_filename):
erase_file(blocking_reasons_filename,
'EX: _profile_edit unable to delete blocking reasons' +
blocking_reasons_filename)
@ -254,7 +255,7 @@ def _add_global_block_reason(base_dir: str,
reason = reason.replace('\n', '').strip()
reason_line = block_id + ' ' + reason + '\n'
if os.path.isfile(blocking_reasons_filename):
if is_a_file(blocking_reasons_filename):
if not text_in_file(block_id,
blocking_reasons_filename):
append_string(reason_line, blocking_reasons_filename,
@ -296,7 +297,7 @@ def add_global_block(base_dir: str,
if not block_nickname.startswith('#'):
# is the handle already blocked?
block_handle = block_nickname + '@' + block_domain
if os.path.isfile(blocking_filename):
if is_a_file(blocking_filename):
if text_in_file(block_handle, blocking_filename):
return False
# block an account handle or domain
@ -307,7 +308,7 @@ def add_global_block(base_dir: str,
else:
block_hashtag = block_nickname
# is the hashtag already blocked?
if os.path.isfile(blocking_filename):
if is_a_file(blocking_filename):
if text_in_file(block_hashtag + '\n', blocking_filename):
return False
# block a hashtag
@ -340,7 +341,7 @@ def _add_block_reason(base_dir: str,
reason = reason.replace('\n', '').strip()
reason_line = block_id + ' ' + reason + '\n'
if os.path.isfile(blocking_reasons_filename):
if is_a_file(blocking_reasons_filename):
if not text_in_file(block_id,
blocking_reasons_filename):
append_string(reason_line, blocking_reasons_filename,
@ -381,14 +382,14 @@ def add_block(base_dir: str, nickname: str, domain: str,
domain = remove_domain_port(domain)
blocking_filename = acct_dir(base_dir, nickname, domain) + '/blocking.txt'
block_handle = block_nickname + '@' + block_domain
if os.path.isfile(blocking_filename):
if is_a_file(blocking_filename):
if text_in_file(block_handle + '\n', blocking_filename):
return False
# if we are following then unfollow
following_filename = \
acct_dir(base_dir, nickname, domain) + '/following.txt'
if os.path.isfile(following_filename):
if is_a_file(following_filename):
if text_in_file(block_handle + '\n', following_filename):
following_str: str = \
load_string(following_filename,
@ -408,7 +409,7 @@ def add_block(base_dir: str, nickname: str, domain: str,
# if they are a follower then remove them
followers_filename = \
acct_dir(base_dir, nickname, domain) + '/followers.txt'
if os.path.isfile(followers_filename):
if is_a_file(followers_filename):
if text_in_file(block_handle + '\n', followers_filename):
followers_str: str = \
load_string(followers_filename,
@ -442,7 +443,7 @@ def _remove_global_block_reason(base_dir: str,
"""Remove a globla block reason
"""
unblocking_filename = data_dir(base_dir) + '/blocking_reasons.txt'
if not os.path.isfile(unblocking_filename):
if not is_a_file(unblocking_filename):
return False
if not unblock_nickname.startswith('#'):
@ -482,7 +483,7 @@ def remove_global_block(base_dir: str,
unblocking_filename = data_dir(base_dir) + '/blocking.txt'
if not unblock_nickname.startswith('#'):
unblock_handle = unblock_nickname + '@' + unblock_domain
if os.path.isfile(unblocking_filename):
if is_a_file(unblocking_filename):
if text_in_file(unblock_handle, unblocking_filename):
unblocking_list: list[str] = \
load_list(unblocking_filename,
@ -500,7 +501,7 @@ def remove_global_block(base_dir: str,
'EX: failed to remove global block ' +
unblocking_filename + ' 1 [ex]')
if os.path.isfile(unblocking_filename + '.new'):
if is_a_file(unblocking_filename + '.new'):
ex_text = \
'EX: remove_global_block unable to rename ' + \
unblocking_filename
@ -510,7 +511,7 @@ def remove_global_block(base_dir: str,
return True
else:
unblock_hashtag = unblock_nickname
if os.path.isfile(unblocking_filename):
if is_a_file(unblocking_filename):
if text_in_file(unblock_hashtag + '\n', unblocking_filename):
unblocking_list: list[str] = \
load_list(unblocking_filename,
@ -528,7 +529,7 @@ def remove_global_block(base_dir: str,
'EX: failed to remove global hashtag block ' +
unblocking_filename + ' 2 [ex]')
if os.path.isfile(unblocking_filename + '.new'):
if is_a_file(unblocking_filename + '.new'):
ex_text = \
'EX: remove_global_block unable to rename 2 ' + \
unblocking_filename
@ -547,7 +548,7 @@ def remove_block(base_dir: str, nickname: str, domain: str,
unblocking_filename = \
acct_dir(base_dir, nickname, domain) + '/blocking.txt'
unblock_handle = unblock_nickname + '@' + unblock_domain
if os.path.isfile(unblocking_filename):
if is_a_file(unblocking_filename):
if text_in_file(unblock_handle, unblocking_filename):
unblocking_list: list[str] = \
load_list(unblocking_filename,
@ -565,7 +566,7 @@ def remove_block(base_dir: str, nickname: str, domain: str,
'EX: failed to remove block ' +
unblocking_filename + ' 2 [ex]')
if os.path.isfile(unblocking_filename + '.new'):
if is_a_file(unblocking_filename + '.new'):
if not move_file(unblocking_filename + '.new',
unblocking_filename,
'EX: remove_block unable to rename 3 ' +
@ -582,7 +583,7 @@ def is_blocked_hashtag(base_dir: str, hashtag: str) -> bool:
if len(hashtag) > 32:
return True
global_blocking_filename = data_dir(base_dir) + '/blocking.txt'
if os.path.isfile(global_blocking_filename):
if is_a_file(global_blocking_filename):
hashtag = hashtag.strip('\n').strip('\r')
if not hashtag.startswith('#'):
hashtag: str = '#' + hashtag
@ -605,7 +606,7 @@ def update_blocked_cache(base_dir: str,
if seconds_since_last_update < blocked_cache_update_secs:
return blocked_cache_last_updated
global_blocking_filename = data_dir(base_dir) + '/blocking.txt'
if not os.path.isfile(global_blocking_filename):
if not is_a_file(global_blocking_filename):
return blocked_cache_last_updated
blocked_lines = load_list(global_blocking_filename,
'EX: update_blocked_cache unable to read ' +
@ -656,7 +657,7 @@ def is_blocked_domain(base_dir: str, domain: str,
blocked_cache = []
# instance block list
global_blocking_filename = data_dir(base_dir) + '/blocking.txt'
if os.path.isfile(global_blocking_filename):
if is_a_file(global_blocking_filename):
blocked_cache_str = \
load_string(global_blocking_filename,
'EX: is_blocked_domain unable to read ' +
@ -719,7 +720,7 @@ def is_blocked_nickname(base_dir: str, nickname: str,
# instance-wide block list
blocked_cache: list[str] = []
global_blocking_filename = data_dir(base_dir) + '/blocking.txt'
if os.path.isfile(global_blocking_filename):
if is_a_file(global_blocking_filename):
blocked_cache_str = \
load_string(global_blocking_filename,
'EX: is_blocked_nickname unable to read ' +
@ -794,7 +795,7 @@ def is_blocked(base_dir: str, nickname: str, domain: str,
return True
else:
global_blocks_filename = data_dir(base_dir) + '/blocking.txt'
if os.path.isfile(global_blocks_filename):
if is_a_file(global_blocks_filename):
if block_nickname:
if text_in_file(block_nickname + '@*\n',
global_blocks_filename):
@ -811,7 +812,7 @@ def is_blocked(base_dir: str, nickname: str, domain: str,
if not block_federated:
federated_blocks_filename = \
data_dir(base_dir) + '/block_api.txt'
if os.path.isfile(federated_blocks_filename):
if is_a_file(federated_blocks_filename):
block_federated: list[str] = []
block_federated_str = \
load_string(federated_blocks_filename,
@ -838,13 +839,13 @@ def is_blocked(base_dir: str, nickname: str, domain: str,
# account level allow list
account_dir = acct_dir(base_dir, nickname, domain)
allow_filename = account_dir + '/allowedinstances.txt'
if block_domain and os.path.isfile(allow_filename):
if block_domain and is_a_file(allow_filename):
if not text_in_file(block_domain + '\n', allow_filename):
return True
# account level block list
blocking_filename = account_dir + '/blocking.txt'
if os.path.isfile(blocking_filename):
if is_a_file(blocking_filename):
if block_nickname:
if text_in_file(block_nickname + '@*\n', blocking_filename):
print('BLOCK: account pattern ' + block_nickname + '@*')
@ -885,7 +886,7 @@ def allowed_announce(base_dir: str, nickname: str, domain: str,
# non-cached instance level announce blocks
global_announce_blocks_filename = \
data_dir(base_dir) + '/noannounce.txt'
if os.path.isfile(global_announce_blocks_filename):
if is_a_file(global_announce_blocks_filename):
if block_nickname:
if text_in_file(block_nickname + '@*',
global_announce_blocks_filename, False):
@ -903,7 +904,7 @@ def allowed_announce(base_dir: str, nickname: str, domain: str,
# non-cached account level announce blocks
account_dir = acct_dir(base_dir, nickname, domain)
blocking_filename = account_dir + '/noannounce.txt'
if os.path.isfile(blocking_filename):
if is_a_file(blocking_filename):
if block_nickname:
if text_in_file(block_nickname + '@*\n',
blocking_filename, False):
@ -927,7 +928,7 @@ def allowed_announce_add(base_dir: str, nickname: str, domain: str,
blocking_filename = account_dir + '/noannounce.txt'
# if the noannounce.txt file doesn't yet exist
if not os.path.isfile(blocking_filename):
if not is_a_file(blocking_filename):
return
handle = following_nickname + '@' + following_domain
@ -962,7 +963,7 @@ def allowed_announce_remove(base_dir: str, nickname: str, domain: str,
handle = following_nickname + '@' + following_domain
# if the noannounce.txt file doesn't yet exist
if not os.path.isfile(blocking_filename):
if not is_a_file(blocking_filename):
file_text = handle + '\n'
save_string(file_text, blocking_filename,
'EX: unable to write initial noannounce remove: ' +
@ -991,7 +992,7 @@ def blocked_quote_toots_add(base_dir: str, nickname: str, domain: str,
blocking_filename = account_dir + '/quotesblocked.txt'
# if the quotesblocked.txt file doesn't yet exist
if os.path.isfile(blocking_filename):
if is_a_file(blocking_filename):
return
handle = following_nickname + '@' + following_domain
@ -1019,7 +1020,7 @@ def blocked_quote_toots_remove(base_dir: str, nickname: str, domain: str,
handle = following_nickname + '@' + following_domain
# if the quotesblocked.txt file doesn't yet exist
if not os.path.isfile(blocking_filename):
if not is_a_file(blocking_filename):
return
file_text: str = ''
@ -1237,7 +1238,7 @@ def mute_post(base_dir: str, nickname: str, domain: str, port: int,
cached_post_filename = \
get_cached_post_filename(base_dir, nickname, domain, post_json_object)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
if erase_file(cached_post_filename,
'EX: MUTE cached post not removed ' +
cached_post_filename):
@ -1270,13 +1271,13 @@ def mute_post(base_dir: str, nickname: str, domain: str, port: int,
post_filename = locate_post(base_dir, nickname, domain,
also_update_post_id)
if post_filename:
if os.path.isfile(post_filename):
if is_a_file(post_filename):
post_json_obj = load_json(post_filename)
cached_post_filename = \
get_cached_post_filename(base_dir, nickname, domain,
post_json_obj)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
ex_text = \
'EX: ' + \
'MUTE cached referenced post not removed ' + \
@ -1310,7 +1311,7 @@ def unmute_post(base_dir: str, nickname: str, domain: str, port: int,
return
mute_filename = post_filename + '.muted'
if os.path.isfile(mute_filename):
if is_a_file(mute_filename):
ex_text = \
'EX: unmute_post mute filename not deleted ' + \
str(mute_filename)
@ -1369,7 +1370,7 @@ def unmute_post(base_dir: str, nickname: str, domain: str, port: int,
cached_post_filename = \
get_cached_post_filename(base_dir, nickname, domain, post_json_object)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
ex_text = \
'EX: unmute_post cached post not deleted ' + \
str(cached_post_filename)
@ -1392,13 +1393,13 @@ def unmute_post(base_dir: str, nickname: str, domain: str, port: int,
if also_update_post_id:
post_filename = locate_post(base_dir, nickname, domain,
also_update_post_id)
if os.path.isfile(post_filename):
if is_a_file(post_filename):
post_json_obj = load_json(post_filename)
cached_post_filename = \
get_cached_post_filename(base_dir, nickname, domain,
post_json_obj)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
ex_text = \
'EX: ' + \
'unmute_post cached ref post not removed ' + \
@ -1549,7 +1550,7 @@ def broch_mode_is_active(base_dir: str) -> bool:
"""Returns true if broch mode is active
"""
allow_filename = data_dir(base_dir) + '/allowedinstances.txt'
return os.path.isfile(allow_filename)
return is_a_file(allow_filename)
def set_broch_mode(base_dir: str, domain_full: str, enabled: bool) -> None:
@ -1565,14 +1566,14 @@ def set_broch_mode(base_dir: str, domain_full: str, enabled: bool) -> None:
if not enabled:
# remove instance allow list
if os.path.isfile(allow_filename):
if is_a_file(allow_filename):
ex_text = \
'EX: set_broch_mode allow file not deleted ' + \
str(allow_filename)
erase_file(allow_filename, ex_text)
print('Broch mode turned off')
else:
if os.path.isfile(allow_filename):
if is_a_file(allow_filename):
last_modified = file_last_modified(allow_filename)
print('Broch mode already activated ' + last_modified)
return
@ -1587,7 +1588,7 @@ def set_broch_mode(base_dir: str, domain_full: str, enabled: bool) -> None:
account_dir = os.path.join(dir_str, acct)
for follow_file_type in follow_files:
following_filename = account_dir + '/' + follow_file_type
if not os.path.isfile(following_filename):
if not is_a_file(following_filename):
continue
follow_list = \
load_list(following_filename,
@ -1622,7 +1623,7 @@ def broch_modeLapses(base_dir: str, lapse_days: int) -> bool:
elapses after a period of time
"""
allow_filename = data_dir(base_dir) + '/allowedinstances.txt'
if not os.path.isfile(allow_filename):
if not is_a_file(allow_filename):
return False
last_modified = file_last_modified(allow_filename)
modified_date = \
@ -1673,7 +1674,7 @@ def import_blocking_file(base_dir: str, nickname: str, domain: str,
account_directory + '/blocking_reasons.txt'
existing_lines: list[str] = []
if os.path.isfile(blocking_filename):
if is_a_file(blocking_filename):
existing_lines_str = \
load_string(blocking_filename,
'EX: ' +
@ -1683,7 +1684,7 @@ def import_blocking_file(base_dir: str, nickname: str, domain: str,
if existing_lines_str:
existing_lines = existing_lines_str.splitlines()
existing_reasons: list[str] = []
if os.path.isfile(blocking_reasons_filename):
if is_a_file(blocking_reasons_filename):
existing_reasons_str = \
load_string(blocking_reasons_filename,
'EX: ' +
@ -1757,11 +1758,11 @@ def export_blocking_file(base_dir: str, nickname: str, domain: str) -> str:
'#domain,#severity,#reject_media,#reject_reports,' + \
'#public_comment,#obfuscate\n'
if not os.path.isfile(blocking_filename):
if not is_a_file(blocking_filename):
return blocks_header
blocking_lines: list[str] = []
if os.path.isfile(blocking_filename):
if is_a_file(blocking_filename):
blocking_lines_str = \
load_string(blocking_filename,
'EX: export_blocks failed to read ' +
@ -1770,7 +1771,7 @@ def export_blocking_file(base_dir: str, nickname: str, domain: str) -> str:
blocking_lines = blocking_lines_str.splitlines()
blocking_reasons: list[str] = []
if os.path.isfile(blocking_reasons_filename):
if is_a_file(blocking_reasons_filename):
blocking_reasons_str = \
load_string(blocking_reasons_filename,
'EX: export_blocks failed to read ' +
@ -1839,7 +1840,7 @@ def load_blocked_military(base_dir: str) -> {}:
"""
block_military_filename = data_dir(base_dir) + '/block_military.txt'
nicknames_list: list[str] = []
if os.path.isfile(block_military_filename):
if is_a_file(block_military_filename):
nicknames_list_str = \
load_string(block_military_filename,
'EX: error while reading block military file')
@ -1858,7 +1859,7 @@ def load_blocked_government(base_dir: str) -> {}:
"""
block_government_filename = data_dir(base_dir) + '/block_government.txt'
nicknames_list: list[str] = []
if os.path.isfile(block_government_filename):
if is_a_file(block_government_filename):
nicknames_list_str = \
load_string(block_government_filename,
'EX: error while reading block government file')
@ -1877,7 +1878,7 @@ def load_blocked_bluesky(base_dir: str) -> {}:
"""
block_bluesky_filename = data_dir(base_dir) + '/block_bluesky.txt'
nicknames_list: list[str] = []
if os.path.isfile(block_bluesky_filename):
if is_a_file(block_bluesky_filename):
nicknames_list_str = \
load_string(block_bluesky_filename,
'EX: error while reading block bluesky file')
@ -1896,7 +1897,7 @@ def load_blocked_nostr(base_dir: str) -> {}:
"""
block_nostr_filename = data_dir(base_dir) + '/block_nostr.txt'
nicknames_list: list[str] = []
if os.path.isfile(block_nostr_filename):
if is_a_file(block_nostr_filename):
nicknames_list_str = \
load_string(block_nostr_filename,
'EX: error while reading block nostr file')
@ -2043,7 +2044,7 @@ def load_federated_blocks_endpoints(base_dir: str) -> []:
block_federated_endpoints: list[str] = []
block_api_endpoints_filename = \
data_dir(base_dir) + '/block_api_endpoints.txt'
if os.path.isfile(block_api_endpoints_filename):
if is_a_file(block_api_endpoints_filename):
new_block_federated_endpoints: list[str] = []
new_block_federated_endpoints_str = \
load_string(block_api_endpoints_filename,
@ -2160,7 +2161,7 @@ def _update_federated_blocks(session, base_dir: str,
data_dir(base_dir) + '/block_api.txt'
if not new_block_api_str:
print('DEBUG: federated blocklist not loaded: ' + block_api_filename)
if os.path.isfile(block_api_filename):
if is_a_file(block_api_filename):
erase_file(block_api_filename,
'EX: unable to remove block api: ' +
block_api_filename)
@ -2193,12 +2194,12 @@ def save_block_federated_endpoints(base_dir: str,
block_federated_endpoints_str += endpoint.strip() + '\n'
result.append(endpoint)
if not block_federated_endpoints_str:
if os.path.isfile(block_api_endpoints_filename):
if is_a_file(block_api_endpoints_filename):
erase_file(block_api_endpoints_filename,
'EX: unable to delete block_api_endpoints.txt')
block_api_filename = \
data_dir(base_dir) + '/block_api.txt'
if os.path.isfile(block_api_filename):
if is_a_file(block_api_filename):
erase_file(block_api_filename,
'EX: unable to delete block_api.txt')
else:
@ -2248,7 +2249,7 @@ def sending_is_blocked2(base_dir: str, nickname: str, domain: str,
send_block_filename = \
acct_dir(base_dir, nickname, domain) + '/send_blocks.txt'
if not os.path.isfile(send_block_filename):
if not is_a_file(send_block_filename):
return False
send_blocked: bool = False

37
blog.py
View File

@ -50,6 +50,7 @@ from flags import is_image_file
from data import load_string
from data import save_string
from data import load_list
from data import is_a_file
def _no_of_blog_replies(base_dir: str, http_prefix: str, translate: {},
@ -69,7 +70,7 @@ def _no_of_blog_replies(base_dir: str, http_prefix: str, translate: {},
post_filename = \
acct_dir(base_dir, nickname, domain) + '/' + post_box + '/' + \
post_id.replace('/', '#') + '.replies'
if os.path.isfile(post_filename):
if is_a_file(post_filename):
box_found = True
break
if not box_found:
@ -78,7 +79,7 @@ def _no_of_blog_replies(base_dir: str, http_prefix: str, translate: {},
post_filename = \
acct_dir(base_dir, nickname, domain) + '/' + post_box + '/' + \
post_id.replace('/', '#')
if os.path.isfile(post_filename):
if is_a_file(post_filename):
return 1
return 0
@ -135,7 +136,7 @@ def _get_blog_replies(base_dir: str, http_prefix: str, translate: {},
post_filename = \
acct_dir(base_dir, nickname, domain) + '/' + post_box + '/' + \
post_id.replace('/', '#') + '.replies'
if os.path.isfile(post_filename):
if is_a_file(post_filename):
box_found = True
break
if not box_found:
@ -144,11 +145,11 @@ def _get_blog_replies(base_dir: str, http_prefix: str, translate: {},
post_filename = \
acct_dir(base_dir, nickname, domain) + '/' + post_box + '/' + \
post_id.replace('/', '#') + '.json'
if os.path.isfile(post_filename):
if is_a_file(post_filename):
post_filename = acct_dir(base_dir, nickname, domain) + \
'/postcache/' + \
post_id.replace('/', '#') + '.html'
if os.path.isfile(post_filename):
if is_a_file(post_filename):
blog_text = load_string(post_filename,
'EX: unable to read blog 3 ' +
post_filename)
@ -174,7 +175,7 @@ def _get_blog_replies(base_dir: str, http_prefix: str, translate: {},
post_filename = acct_dir(base_dir, nickname, domain) + \
'/postcache/' + \
reply_post_id.replace('/', '#') + '.html'
if not os.path.isfile(post_filename):
if not is_a_file(post_filename):
continue
reply_text = load_string(post_filename,
'EX: unable to read blog replies ' +
@ -601,7 +602,7 @@ def html_blog_post(session, authorized: bool,
blog_str: str = ''
css_filename = base_dir + '/epicyon-blog.css'
if os.path.isfile(base_dir + '/blog.css'):
if is_a_file(base_dir + '/blog.css'):
css_filename = base_dir + '/blog.css'
instance_title = \
get_config_param(base_dir, 'instanceTitle')
@ -667,7 +668,7 @@ def html_blog_page(authorized: bool, session,
blog_str: str = ''
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
instance_title = \
get_config_param(base_dir, 'instanceTitle')
@ -678,7 +679,7 @@ def html_blog_page(authorized: bool, session,
_html_blog_remove_cw_button(blog_str, translate)
blogs_index = acct_dir(base_dir, nickname, domain) + '/tlblogs.index'
if not os.path.isfile(blogs_index):
if not is_a_file(blogs_index):
return blog_str + html_footer()
timeline_json = \
@ -765,7 +766,7 @@ def html_blog_page_rss2(base_dir: str, http_prefix: str, translate: {},
'Blog', translate)
blogs_index = acct_dir(base_dir, nickname, domain) + '/tlblogs.index'
if not os.path.isfile(blogs_index):
if not is_a_file(blogs_index):
if include_header:
return blog_rss2 + rss2footer()
return blog_rss2
@ -807,7 +808,7 @@ def html_blog_page_rss3(base_dir: str, http_prefix: str,
blog_rss3: str = ''
blogs_index = acct_dir(base_dir, nickname, domain) + '/tlblogs.index'
if not os.path.isfile(blogs_index):
if not is_a_file(blogs_index):
return blog_rss3
timeline_json = \
@ -840,7 +841,7 @@ def _no_of_blog_accounts(base_dir: str) -> int:
continue
account_dir = os.path.join(dir_str, acct)
blogs_index = account_dir + '/tlblogs.index'
if os.path.isfile(blogs_index):
if is_a_file(blogs_index):
ctr += 1
break
return ctr
@ -856,7 +857,7 @@ def _single_blog_account_nickname(base_dir: str) -> str:
continue
account_dir = os.path.join(dir_str, acct)
blogs_index = account_dir + '/tlblogs.index'
if os.path.isfile(blogs_index):
if is_a_file(blogs_index):
return acct.split('@')[0]
break
return None
@ -873,7 +874,7 @@ def html_blog_view(authorized: bool,
blog_str: str = ''
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
instance_title = \
get_config_param(base_dir, 'instanceTitle')
@ -900,7 +901,7 @@ def html_blog_view(authorized: bool,
continue
account_dir = os.path.join(dir_str, acct)
blogs_index = account_dir + '/tlblogs.index'
if os.path.isfile(blogs_index):
if is_a_file(blogs_index):
blog_str += '<p class="blogaccount">'
blog_str += '<a href="' + \
http_prefix + '://' + domain_full + '/blog/' + \
@ -932,7 +933,7 @@ def html_edit_blog(media_instance: bool, translate: {},
# load blog template if it exists
dir_str = data_dir(base_dir)
if os.path.isfile(dir_str + '/newblog.txt'):
if is_a_file(dir_str + '/newblog.txt'):
edit_blog_text_str = \
load_string(dir_str + '/newblog.txt',
'EX: html_edit_blog unable to read ' +
@ -941,7 +942,7 @@ def html_edit_blog(media_instance: bool, translate: {},
edit_blog_text: str = '<p>' + edit_blog_text_str + '</p>'
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
if '?' in path:
@ -1082,7 +1083,7 @@ def path_contains_blog_link(base_dir: str,
# check for blog posts
blog_index_filename = \
acct_dir(base_dir, nickname, domain) + '/tlblogs.index'
if not os.path.isfile(blog_index_filename):
if not is_a_file(blog_index_filename):
return None, None
if not text_in_file('#' + user_ending2[1] + '.', blog_index_filename):
return None, None

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Timeline"
import os
from pprint import pprint
from webfinger import webfinger_handle
from auth import create_basic_auth_header
@ -39,6 +38,7 @@ from data import load_string
from data import save_string
from data import prepend_string
from data import erase_file
from data import is_a_file
def undo_bookmarks_collection_entry(recent_posts_cache: {},
@ -60,7 +60,7 @@ def undo_bookmarks_collection_entry(recent_posts_cache: {},
get_cached_post_filename(base_dir, nickname,
domain, post_json_object)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
ex_text = \
'EX: undo_bookmarks_collection_entry ' + \
'unable to delete cached post file ' + \
@ -71,7 +71,7 @@ def undo_bookmarks_collection_entry(recent_posts_cache: {},
# remove from the index
bookmarks_index_filename = \
acct_dir(base_dir, nickname, domain) + '/bookmarks.index'
if not os.path.isfile(bookmarks_index_filename):
if not is_a_file(bookmarks_index_filename):
return
if '/' in post_filename:
bookmark_index = post_filename.split('/')[-1].strip()
@ -180,7 +180,7 @@ def update_bookmarks_collection(recent_posts_cache: {},
get_cached_post_filename(base_dir, nickname,
domain, post_json_object)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
ex_text = \
'EX: update_bookmarks_collection ' + \
'unable to delete cached post ' + \
@ -248,7 +248,7 @@ def update_bookmarks_collection(recent_posts_cache: {},
bookmarks_index_filename = \
acct_dir(base_dir, nickname, domain) + '/bookmarks.index'
bookmark_index = post_filename.split('/')[-1]
if os.path.isfile(bookmarks_index_filename):
if is_a_file(bookmarks_index_filename):
if not text_in_file(bookmark_index, bookmarks_index_filename):
if prepend_string(bookmark_index, bookmarks_index_filename,
'EX: ' +

View File

@ -34,6 +34,7 @@ from content import remove_script
from data import save_binary
from data import load_binary
from data import erase_file
from data import is_a_file
def remove_person_from_cache(base_dir: str, person_url: str,
@ -42,7 +43,7 @@ def remove_person_from_cache(base_dir: str, person_url: str,
"""
cache_filename = base_dir + '/cache/actors/' + \
person_url.replace('/', '#') + '.json'
if os.path.isfile(cache_filename):
if is_a_file(cache_filename):
ex_text = \
'EX: unable to delete cached actor ' + str(cache_filename)
erase_file(cache_filename, ex_text)
@ -116,7 +117,7 @@ def store_person_in_cache(base_dir: str, person_url: str,
if os.path.isdir(base_dir + '/cache/actors'):
cache_filename = base_dir + '/cache/actors/' + \
person_url.replace('/', '#') + '.json'
if not os.path.isfile(cache_filename):
if not is_a_file(cache_filename):
save_json(person_json, cache_filename)
@ -402,7 +403,7 @@ def remove_avatar_from_cache(base_dir: str, actor_str: str) -> None:
for extension in avatar_filename_extensions:
avatar_filename = \
base_dir + '/cache/avatars/' + actor_str + '.' + extension
if not os.path.isfile(avatar_filename):
if not is_a_file(avatar_filename):
continue
ex_text = \
'EX: remove_avatar_from_cache ' + \
@ -426,7 +427,7 @@ def clear_from_post_caches(base_dir: str, recent_posts_cache: {},
continue
cache_dir = os.path.join(dir_str, acct)
post_filename = cache_dir + filename
if os.path.isfile(post_filename):
if is_a_file(post_filename):
ex_text = \
'EX: clear_from_post_caches file not removed ' + \
str(post_filename)

View File

@ -17,6 +17,7 @@ from utils import get_invalid_characters
from data import load_string
from data import save_string
from data import erase_file
from data import is_a_file
MAX_TAG_LENGTH = 42
@ -27,12 +28,12 @@ def get_hashtag_category(base_dir: str, hashtag: str) -> str:
"""Returns the category for the hashtag
"""
category_filename = base_dir + '/tags/' + hashtag + '.category'
if not os.path.isfile(category_filename):
if not is_a_file(category_filename):
category_filename = base_dir + '/tags/' + hashtag.title() + '.category'
if not os.path.isfile(category_filename):
if not is_a_file(category_filename):
category_filename = \
base_dir + '/tags/' + hashtag.upper() + '.category'
if not os.path.isfile(category_filename):
if not is_a_file(category_filename):
return ''
category_str: str = \
@ -64,7 +65,7 @@ def load_city_hashtags(base_dir: str, translate: {}) -> None:
if not cities_file.endswith('.txt'):
continue
cities_filename = base_dir + '/data/cities/' + cities_file
if not os.path.isfile(cities_filename):
if not is_a_file(cities_filename):
continue
cities: list[str] = []
cities_str = \
@ -81,7 +82,7 @@ def load_city_hashtags(base_dir: str, translate: {}) -> None:
hashtag2 = replace_strings(hashtag, replacements2)
city_filename = base_dir + '/tags/' + hashtag2 + '.category'
if not os.path.isfile(city_filename):
if not is_a_file(city_filename):
save_string(category_str, city_filename,
'EX: unable to write city category ' +
city_filename)
@ -93,7 +94,7 @@ def load_city_hashtags(base_dir: str, translate: {}) -> None:
hashtag2 = new_hashtag
city_filename = \
base_dir + '/tags/' + hashtag2 + '.category'
if not os.path.isfile(city_filename):
if not is_a_file(city_filename):
save_string(category_str, city_filename,
'EX: unable to write city category2 ' +
city_filename)
@ -105,7 +106,7 @@ def load_city_hashtags(base_dir: str, translate: {}) -> None:
hashtag2 = new_hashtag
city_filename = \
base_dir + '/tags/' + hashtag2 + '.category'
if not os.path.isfile(city_filename):
if not is_a_file(city_filename):
save_string(category_str, city_filename,
'EX: unable to write city category3 ' +
city_filename)
@ -127,7 +128,7 @@ def get_hashtag_categories(base_dir: str,
if not catfile.endswith('.category'):
continue
category_filename = os.path.join(base_dir + '/tags', catfile)
if not os.path.isfile(category_filename):
if not is_a_file(category_filename):
continue
hashtag = catfile.split('.')[0]
if len(hashtag) > MAX_TAG_LENGTH:
@ -147,7 +148,7 @@ def get_hashtag_categories(base_dir: str,
if recent:
tags_filename = base_dir + '/tags/' + hashtag + '.txt'
if not os.path.isfile(tags_filename):
if not is_a_file(tags_filename):
continue
mod_time_since_epoc = \
os.path.getmtime(tags_filename)
@ -174,7 +175,7 @@ def update_hashtag_categories(base_dir: str) -> None:
category_list_filename = data_dir(base_dir) + '/categoryList.txt'
hashtag_categories = get_hashtag_categories(base_dir, False, None)
if not hashtag_categories:
if os.path.isfile(category_list_filename):
if is_a_file(category_list_filename):
erase_file(category_list_filename,
'EX: update_hashtag_categories ' +
'unable to delete cached category list ' +
@ -232,13 +233,13 @@ def set_hashtag_category(base_dir: str, hashtag: str, category: str,
if not force:
hashtag_filename = base_dir + '/tags/' + hashtag + '.txt'
if not os.path.isfile(hashtag_filename):
if not is_a_file(hashtag_filename):
hashtag = hashtag.title()
hashtag_filename = base_dir + '/tags/' + hashtag + '.txt'
if not os.path.isfile(hashtag_filename):
if not is_a_file(hashtag_filename):
hashtag = hashtag.upper()
hashtag_filename = base_dir + '/tags/' + hashtag + '.txt'
if not os.path.isfile(hashtag_filename):
if not is_a_file(hashtag_filename):
return False
if not os.path.isdir(base_dir + '/tags'):
@ -246,7 +247,7 @@ def set_hashtag_category(base_dir: str, hashtag: str, category: str,
category_filename = base_dir + '/tags/' + hashtag + '.category'
if force:
# don't overwrite any existing categories
if os.path.isfile(category_filename):
if is_a_file(category_filename):
return False
category_written: bool = False

12
city.py
View File

@ -12,7 +12,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Metadata"
import os
import datetime
import random
import math
@ -20,6 +19,7 @@ from random import randint
from utils import acct_dir
from utils import remove_eol
from data import load_string
from data import is_a_file
# states which the simulated city dweller can be in
PERSON_SLEEP = 0
@ -204,11 +204,11 @@ def spoof_geolocation(base_dir: str,
camera make, camera model, camera serial number
"""
locations_filename = base_dir + '/custom_locations.txt'
if not os.path.isfile(locations_filename):
if not is_a_file(locations_filename):
locations_filename = base_dir + '/locations.txt'
nogo_filename = base_dir + '/custom_locations_nogo.txt'
if not os.path.isfile(nogo_filename):
if not is_a_file(nogo_filename):
nogo_filename = base_dir + '/locations_nogo.txt'
man_city_radius: float = 0.1
@ -226,7 +226,7 @@ def spoof_geolocation(base_dir: str,
if cities_list:
cities = cities_list
else:
if not os.path.isfile(locations_filename):
if not is_a_file(locations_filename):
return (default_latitude, default_longitude,
default_latdirection, default_longdirection,
"", "", 0)
@ -241,7 +241,7 @@ def spoof_geolocation(base_dir: str,
if nogo_list:
nogo = nogo_list
else:
if os.path.isfile(nogo_filename):
if is_a_file(nogo_filename):
nogo_list: list[str] = []
nogo_list_str = \
load_string(nogo_filename,
@ -339,7 +339,7 @@ def get_spoofed_city(city: str, base_dir: str,
"""
city: str = ''
city_filename = acct_dir(base_dir, nickname, domain) + '/city.txt'
if os.path.isfile(city_filename):
if is_a_file(city_filename):
city1 = load_string(city_filename,
'EX: get_spoofed_city unable to read ' +
city_filename)

View File

@ -56,6 +56,7 @@ from data import save_string
from data import save_binary
from data import append_string
from data import erase_file
from data import is_a_file
MUSIC_SITES = ('soundcloud.com', 'bandcamp.com', 'resonate.coop')
@ -278,7 +279,7 @@ def dangerous_css(filename: str, allow_local_network_access: bool) -> bool:
"""Returns true is the css file contains code which
can create security problems
"""
if not os.path.isfile(filename):
if not is_a_file(filename):
return False
content = load_string(filename,
@ -332,7 +333,7 @@ def switch_words(base_dir: str, nickname: str, domain: str, content: str,
if not rules:
switch_words_filename = \
acct_dir(base_dir, nickname, domain) + '/replacewords.txt'
if not os.path.isfile(switch_words_filename):
if not is_a_file(switch_words_filename):
return content
rules_str = load_string(switch_words_filename,
'EX: unable to read switches ' +
@ -384,7 +385,7 @@ def _save_custom_emoji(session, base_dir: str, emoji_name: str, url: str,
return
emoji_json_filename = custom_emoji_dir + '/emoji.json'
emoji_json = {}
if os.path.isfile(emoji_json_filename):
if is_a_file(emoji_json_filename):
emoji_json = load_json(emoji_json_filename)
if not emoji_json:
emoji_json = {}
@ -401,9 +402,9 @@ def _get_emoji_name_from_code(base_dir: str, emoji_code: str) -> str:
"""Returns the emoji name from its code
"""
emojis_filename = base_dir + '/emoji/emoji.json'
if not os.path.isfile(emojis_filename):
if not is_a_file(emojis_filename):
emojis_filename = base_dir + '/emoji/default_emoji.json'
if not os.path.isfile(emojis_filename):
if not is_a_file(emojis_filename):
return None
emojis_json = load_json(emojis_filename)
if not emojis_json:
@ -428,7 +429,7 @@ def _update_common_emoji(base_dir: str, emoji_content: str) -> None:
return
common_emoji_filename = data_dir(base_dir) + '/common_emoji.txt'
common_emoji = None
if os.path.isfile(common_emoji_filename):
if is_a_file(common_emoji_filename):
common_emoji_str = load_string(common_emoji_filename,
'EX: unable to load common emoji file')
if common_emoji_str:
@ -919,10 +920,10 @@ def _add_emoji(base_dir: str, word_str: str,
if not emoji_dict.get(emoji):
return False
emoji_filename = base_dir + '/emoji/' + emoji_dict[emoji] + '.png'
if not os.path.isfile(emoji_filename):
if not is_a_file(emoji_filename):
emoji_filename = \
base_dir + '/emojicustom/' + emoji_dict[emoji] + '.png'
if not os.path.isfile(emoji_filename):
if not is_a_file(emoji_filename):
return False
emoji_url = http_prefix + "://" + domain + \
"/emoji/" + emoji_dict[emoji] + '.png'
@ -963,12 +964,12 @@ def _mention_to_url(base_dir: str, http_prefix: str,
users_path = users_path.replace('/', '#')
possible_cache_entry = \
cache_path_start + users_path + nickname + '.json'
if os.path.isfile(possible_cache_entry):
if is_a_file(possible_cache_entry):
return http_prefix + '://' + \
domain + users_path.replace('#', '/') + nickname
possible_cache_entry = \
cache_path_start + '#' + nickname + '.json'
if os.path.isfile(possible_cache_entry):
if is_a_file(possible_cache_entry):
return http_prefix + '://' + domain + '/' + nickname
return http_prefix + '://' + domain + '/users/' + nickname
@ -1268,7 +1269,7 @@ def _load_auto_tags(base_dir: str, nickname: str, domain: str) -> []:
the lines of the file
"""
filename = acct_dir(base_dir, nickname, domain) + '/autotags.txt'
if not os.path.isfile(filename):
if not is_a_file(filename):
return []
fp_tags_str = load_string(filename,
'EX: unable to read auto tags ' + filename)
@ -1411,7 +1412,7 @@ def detect_dogwhistles(content: str, dogwhistles: {}) -> {}:
def load_dogwhistles(filename: str) -> {}:
"""Loads a list of dogwhistles from file
"""
if not os.path.isfile(filename):
if not is_a_file(filename):
return {}
dogwhistle_lines: list[str] = []
dogwhistle_lines_str = \
@ -1496,7 +1497,7 @@ def add_html_tags(base_dir: str, http_prefix: str,
following = None
petnames = None
if '@' in words:
if os.path.isfile(following_filename):
if is_a_file(following_filename):
following: list[str] = []
following_str = load_string(following_filename,
'EX: add_html_tags unable to read ' +
@ -1544,14 +1545,14 @@ def add_html_tags(base_dir: str, http_prefix: str,
# emoji.json is generated so that it can be customized and
# the changes will be retained even if default_emoji.json
# is subsequently updated
if not os.path.isfile(base_dir + '/emoji/emoji.json'):
if not is_a_file(base_dir + '/emoji/emoji.json'):
copyfile(base_dir + '/emoji/default_emoji.json',
base_dir + '/emoji/emoji.json')
emoji_dict = load_json(base_dir + '/emoji/emoji.json')
# append custom emoji to the dict
custom_emoji_filename = base_dir + '/emojicustom/emoji.json'
if os.path.isfile(custom_emoji_filename):
if is_a_file(custom_emoji_filename):
custom_emoji_dict = load_json(custom_emoji_filename)
if custom_emoji_dict:
# combine emoji dicts one by one
@ -1685,13 +1686,13 @@ def save_media_in_form_post(media_bytes, debug: bool,
extension_types = get_image_extensions()
for ex in extension_types:
possible_other_format = filename_base + '.' + ex
if os.path.isfile(possible_other_format):
if is_a_file(possible_other_format):
ex_text = \
'EX: save_media_in_form_post ' + \
'unable to delete other ' + \
str(possible_other_format)
erase_file(possible_other_format, ex_text)
if os.path.isfile(filename_base):
if is_a_file(filename_base):
ex_text = \
'EX: save_media_in_form_post ' + \
'unable to delete ' + str(filename_base)
@ -1783,7 +1784,7 @@ def save_media_in_form_post(media_bytes, debug: bool,
filename.replace('.temp', '').replace('.' +
detected_extension, '.' +
ex)
if os.path.isfile(possible_other_format):
if is_a_file(possible_other_format):
ex_text = \
'EX: save_media_in_form_post ' + \
'unable to delete other 2 ' + \
@ -1814,7 +1815,7 @@ def save_media_in_form_post(media_bytes, debug: bool,
save_binary(media_bytes[start_pos:], filename,
'EX: save_media_in_form_post unable to write media')
if not os.path.isfile(filename):
if not is_a_file(filename):
if debug:
print('WARN: Media file could not be written to file: ' +
filename)
@ -2125,7 +2126,7 @@ def import_emoji(base_dir: str, import_filename: str, session) -> None:
"""Imports emoji from the given filename
Each line should be [emoji url], :emojiname:
"""
if not os.path.isfile(import_filename):
if not is_a_file(import_filename):
return
emoji_dict: dict = load_json(base_dir + '/emoji/default_emoji.json')
added: int = 0
@ -2144,7 +2145,7 @@ def import_emoji(base_dir: str, import_filename: str, session) -> None:
if emoji_dict.get(tag):
continue
emoji_image_filename = base_dir + '/emoji/' + tag + '.png'
if os.path.isfile(emoji_image_filename):
if is_a_file(emoji_image_filename):
continue
if download_image(session, url,
emoji_image_filename, True, False):
@ -2274,7 +2275,7 @@ def remove_script(content: str, log_filename: str,
# write the detected script to a log file
log_str = actor + ' ' + url + ' ' + text + '\n'
write_type: str = 'a+'
if os.path.isfile(log_filename):
if is_a_file(log_filename):
write_type = 'w+'
if write_type == 'a+':
append_string(log_str, log_filename,
@ -2295,7 +2296,7 @@ def reject_twitter_summary(base_dir: str, nickname: str, domain: str,
return False
remove_twitter = \
acct_dir(base_dir, nickname, domain) + '/.removeTwitter'
if not os.path.isfile(remove_twitter):
if not is_a_file(remove_twitter):
return False
summary_lower = summary.lower()
twitter_strings = ('twitter', '/x.com', ' x.com', 'birdsite')
@ -2360,7 +2361,7 @@ def add_name_emojis_to_tags(base_dir: str, http_prefix: str,
url = emoji_id + '.png'
emoji_filename = base_dir + '/emoji/' + emoji_name + '.png'
updated = None
if os.path.isfile(emoji_filename):
if is_a_file(emoji_filename):
updated = file_last_modified(emoji_filename)
new_tag = {
'icon': {
@ -2432,7 +2433,7 @@ def _load_auto_cw(base_dir: str, nickname: str, domain: str) -> []:
the lines of the file
"""
auto_cw_filename = acct_dir(base_dir, nickname, domain) + '/autocw.txt'
if not os.path.isfile(auto_cw_filename):
if not is_a_file(auto_cw_filename):
return []
fp_auto_str = load_string(auto_cw_filename,
'EX: unable to load auto cw file ' +

View File

@ -25,6 +25,7 @@ from data import save_string
from data import save_flag_file
from data import append_string
from data import erase_file
from data import is_a_file
def _get_conversation_filename(base_dir: str, nickname: str, domain: str,
@ -66,7 +67,7 @@ def update_conversation(base_dir: str, nickname: str, domain: str,
if not conversation_filename:
return False
post_id = remove_id_ending(post_json_object['object']['id'])
if not os.path.isfile(conversation_filename):
if not is_a_file(conversation_filename):
if save_string(post_id + '\n', conversation_filename,
'EX: update_conversation ' +
'unable to write to ' +
@ -91,9 +92,9 @@ def mute_conversation(base_dir: str, nickname: str, domain: str,
conversation_dir = acct_dir(base_dir, nickname, domain) + '/conversation'
conversation_filename = \
conversation_dir + '/' + conversation_id.replace('/', '#')
if not os.path.isfile(conversation_filename):
if not is_a_file(conversation_filename):
return
if os.path.isfile(conversation_filename + '.muted'):
if is_a_file(conversation_filename + '.muted'):
return
save_flag_file(conversation_filename + '.muted',
'EX: unable to write mute ' + conversation_filename)
@ -109,9 +110,9 @@ def unmute_conversation(base_dir: str, nickname: str, domain: str,
conversation_dir = acct_dir(base_dir, nickname, domain) + '/conversation'
conversation_filename = \
conversation_dir + '/' + conversation_id.replace('/', '#')
if not os.path.isfile(conversation_filename):
if not is_a_file(conversation_filename):
return
if not os.path.isfile(conversation_filename + '.muted'):
if not is_a_file(conversation_filename + '.muted'):
return
erase_file(conversation_filename + '.muted',
'EX: unmute_conversation unable to delete ' +

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Core"
import os
from utils import data_dir
from utils import save_json
from utils import user_agent_domain
@ -21,6 +20,7 @@ from blocking import update_blocked_cache
from blocking import is_blocked_domain
from data import load_string
from data import save_string
from data import is_a_file
default_user_agent_blocks = [
'fedilist', 'ncsc scan', 'fedifetcher'
@ -64,7 +64,7 @@ def load_known_web_bots(base_dir: str) -> []:
"""Returns a list of known web bots
"""
known_bots_filename = data_dir(base_dir) + '/knownBots.txt'
if not os.path.isfile(known_bots_filename):
if not is_a_file(known_bots_filename):
return []
crawlers_str = load_string(known_bots_filename,
'EX: unable to load web bots from ' +

View File

@ -106,6 +106,7 @@ from daemon_utils import is_authorized
from poison import load_dictionary
from poison import load_2grams
from data import load_string
from data import is_a_file
class PubServer(BaseHTTPRequestHandler):
@ -581,7 +582,7 @@ def load_tokens(base_dir: str, tokens_dict: {}, tokens_lookup: {}) -> None:
for handle in dirs:
if '@' in handle:
token_filename = acct_handle_dir(base_dir, handle) + '/.token'
if not os.path.isfile(token_filename):
if not is_a_file(token_filename):
continue
nickname = handle.split('@')[0]
token = load_string(token_filename,
@ -748,7 +749,7 @@ def run_daemon(accounts_data_dir: str,
# if a custom robots.txt exists then read it
robots_txt_filename = data_dir(base_dir) + '/robots.txt'
httpd.robots_txt = None
if os.path.isfile(robots_txt_filename):
if is_a_file(robots_txt_filename):
new_robots_txt = \
load_string(robots_txt_filename,
'EX: error reading 1 ' + robots_txt_filename)
@ -764,7 +765,7 @@ def run_daemon(accounts_data_dir: str,
# for each account whether to hide announces
httpd.hide_announces = {}
hide_announces_filename = data_dir(base_dir) + '/hide_announces.json'
if os.path.isfile(hide_announces_filename):
if is_a_file(hide_announces_filename):
httpd.hide_announces = load_json(hide_announces_filename)
# short description of the instance
@ -799,7 +800,7 @@ def run_daemon(accounts_data_dir: str,
# loads a catalog of http header fields
headers_catalog_fieldname = data_dir(base_dir) + '/headers_catalog.json'
httpd.headers_catalog = {}
if os.path.isfile(headers_catalog_fieldname):
if is_a_file(headers_catalog_fieldname):
httpd.headers_catalog = load_json(headers_catalog_fieldname)
# list of websites which are currently down
@ -855,7 +856,7 @@ def run_daemon(accounts_data_dir: str,
# load a list of dogwhistle words
dogwhistles_filename = data_dir(base_dir) + '/dogwhistles.txt'
if not os.path.isfile(dogwhistles_filename):
if not is_a_file(dogwhistles_filename):
dogwhistles_filename = base_dir + '/default_dogwhistles.txt'
httpd.dogwhistles = load_dogwhistles(dogwhistles_filename)
@ -895,7 +896,7 @@ def run_daemon(accounts_data_dir: str,
# fitness metrics
fitness_filename = data_dir(base_dir) + '/fitness.json'
httpd.fitness = {}
if os.path.isfile(fitness_filename):
if is_a_file(fitness_filename):
fitness = load_json(fitness_filename)
if fitness is not None:
httpd.fitness = fitness
@ -1209,7 +1210,7 @@ def run_daemon(accounts_data_dir: str,
# and how many times they have been seen
httpd.known_crawlers = {}
known_crawlers_filename = dir_str + '/knownCrawlers.json'
if os.path.isfile(known_crawlers_filename):
if is_a_file(known_crawlers_filename):
httpd.known_crawlers = load_json(known_crawlers_filename)
# when was the last crawler seen?
httpd.last_known_crawler = 0

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon"
import os
import time
import json
import urllib.parse
@ -222,6 +221,7 @@ from daemon_get_login import show_login_screen
from poison import html_poisoned
from data import load_string
from data import load_binary
from data import is_a_file
# Blogs can be longer, so don't show many per page
MAX_POSTS_IN_BLOGS_FEED = 4
@ -875,7 +875,7 @@ def daemon_http_get(self) -> None:
if not actor_json:
actor_filename = acct_dir(self.server.base_dir, nickname,
self.server.domain) + '.json'
if os.path.isfile(actor_filename):
if is_a_file(actor_filename):
actor_json = load_json(actor_filename)
if not actor_json:
print('DEBUG: shareditems 2 ' + actor)
@ -2267,7 +2267,7 @@ def daemon_http_get(self) -> None:
following_filename = \
acct_dir(self.server.base_dir,
nickname, self.server.domain) + '/following.txt'
if not os.path.isfile(following_filename):
if not is_a_file(following_filename):
http_404(self, 125)
return
if self.path.endswith('/followingaccounts.csv'):
@ -2308,7 +2308,7 @@ def daemon_http_get(self) -> None:
followers_filename = \
acct_dir(self.server.base_dir,
nickname, self.server.domain) + '/followers.txt'
if not os.path.isfile(followers_filename):
if not is_a_file(followers_filename):
http_404(self, 128)
return
if html_getreq:
@ -2634,7 +2634,7 @@ def daemon_http_get(self) -> None:
'/apple-touch-icon.png'):
media_filename = \
self.server.base_dir + '/img' + self.path
if os.path.isfile(media_filename):
if is_a_file(media_filename):
if etag_exists(self, media_filename):
# The file has not changed
http_304(self)
@ -2672,7 +2672,7 @@ def daemon_http_get(self) -> None:
if self.path in ('/screenshot1.jpg', '/screenshot2.jpg'):
screen_filename = \
self.server.base_dir + '/img' + self.path
if os.path.isfile(screen_filename):
if is_a_file(screen_filename):
if etag_exists(self, screen_filename):
# The file has not changed
http_304(self)
@ -2710,7 +2710,7 @@ def daemon_http_get(self) -> None:
(string_starts_with(self.path,
('/login.', '/qrcode.png', '/qrcode_lxmf.png'))):
icon_filename = data_dir(self.server.base_dir) + self.path
if os.path.isfile(icon_filename):
if is_a_file(icon_filename):
if etag_exists(self, icon_filename):
# The file has not changed
http_304(self)
@ -3196,7 +3196,7 @@ def daemon_http_get(self) -> None:
hashtag = urllib.parse.unquote(hashtag_url.split('/')[-1])
tags_filename = \
self.server.base_dir + '/tags/' + hashtag + '.txt'
if os.path.isfile(tags_filename):
if is_a_file(tags_filename):
# redirect to the local hashtag screen
self.server.getreq_busy = False
ht_url = \
@ -6247,7 +6247,7 @@ def daemon_http_get(self) -> None:
self.server.getreq_busy = False
return
if os.path.isfile(filename):
if is_a_file(filename):
content = load_string(filename,
'EX: unable to read file ' + filename)
if content:
@ -6446,7 +6446,7 @@ def _get_speaker(self, calling_domain: str, referer_domain: str,
nickname = nickname.split('/')[0]
speaker_filename = \
acct_dir(base_dir, nickname, domain) + '/speaker.json'
if not os.path.isfile(speaker_filename):
if not is_a_file(speaker_filename):
http_404(self, 18)
return
@ -6488,7 +6488,7 @@ def _get_ontology(self, calling_domain: str,
ontology_filename = base_dir + '/ontology/' + ontology_str
if ontology_str.endswith('.json'):
ontology_file_type = 'application/ld+json'
if os.path.isfile(ontology_filename):
if is_a_file(ontology_filename):
ontology_file = \
load_string(ontology_filename,
'EX: unable to read ontology ' +

View File

@ -9,7 +9,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon GET"
import os
from utils import get_mutuals_of_person
from utils import delete_post
from utils import locate_post
@ -30,6 +29,7 @@ from daemon_utils import post_to_outbox
from fitnessFunctions import fitness_performance
from follow import follower_approval_active
from webapp_post import individual_post_as_html
from data import is_a_file
def announce_button(self, calling_domain: str, path: str,
@ -231,7 +231,7 @@ def announce_button(self, calling_domain: str, path: str,
if not mitm:
mitm_filename = \
announce_filename.replace('.json', '') + '.mitm'
if os.path.isfile(mitm_filename):
if is_a_file(mitm_filename):
mitm = True
bold_reading: bool = False
if bold_reading_nicknames.get(self.post_to_nickname):

View File

@ -9,7 +9,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon GET"
import os
from utils import get_mutuals_of_person
from utils import get_cached_post_filename
from utils import load_json
@ -28,6 +27,7 @@ from bookmarks import undo_bookmark_post
from follow import follower_approval_active
from webapp_post import individual_post_as_html
from fitnessFunctions import fitness_performance
from data import is_a_file
def bookmark_button(self, calling_domain: str, path: str,
@ -183,7 +183,7 @@ def bookmark_button(self, calling_domain: str, path: str,
if not mitm:
mitm_filename = \
bookmark_filename.replace('.json', '') + '.mitm'
if os.path.isfile(mitm_filename):
if is_a_file(mitm_filename):
mitm = True
bold_reading: bool = False
if bold_reading_nicknames.get(self.post_to_nickname):
@ -410,7 +410,7 @@ def bookmark_button_undo(self, calling_domain: str, path: str,
if not mitm:
mitm_filename = \
bookmark_filename.replace('.json', '') + '.mitm'
if os.path.isfile(mitm_filename):
if is_a_file(mitm_filename):
mitm = True
bold_reading: bool = False
if bold_reading_nicknames.get(self.post_to_nickname):

View File

@ -9,7 +9,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon GET"
import os
from utils import get_mutuals_of_person
from utils import is_dm
from utils import get_cached_post_filename
@ -30,6 +29,7 @@ from fitnessFunctions import fitness_performance
from like import update_likes_collection
from like import undo_likes_collection_entry
from webapp_post import individual_post_as_html
from data import is_a_file
def like_button(self, calling_domain: str, path: str,
@ -230,7 +230,7 @@ def like_button(self, calling_domain: str, path: str,
if not mitm:
mitm_filename = \
liked_post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(mitm_filename):
if is_a_file(mitm_filename):
mitm = True
bold_reading: bool = False
if bold_reading_nicknames.get(self.post_to_nickname):
@ -501,7 +501,7 @@ def like_button_undo(self, calling_domain: str, path: str,
if not mitm:
mitm_filename = \
liked_post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(mitm_filename):
if is_a_file(mitm_filename):
mitm = True
bold_reading: bool = False
if bold_reading_nicknames.get(self.post_to_nickname):

View File

@ -9,7 +9,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon GET"
import os
from utils import get_mutuals_of_person
from utils import is_dm
from utils import get_cached_post_filename
@ -25,6 +24,7 @@ from blocking import mute_post
from follow import follower_approval_active
from webapp_post import individual_post_as_html
from fitnessFunctions import fitness_performance
from data import is_a_file
def mute_button(self, calling_domain: str, path: str,
@ -139,7 +139,7 @@ def mute_button(self, calling_domain: str, path: str,
if not mitm:
mitm_filename = \
mute_filename.replace('.json', '') + '.mitm'
if os.path.isfile(mitm_filename):
if is_a_file(mitm_filename):
mitm = True
bold_reading = False
if bold_reading_nicknames.get(nickname):
@ -329,7 +329,7 @@ def mute_button_undo(self, calling_domain: str, path: str,
if not mitm:
mitm_filename = \
mute_filename.replace('.json', '') + '.mitm'
if os.path.isfile(mitm_filename):
if is_a_file(mitm_filename):
mitm = True
bold_reading = False
if bold_reading_nicknames.get(nickname):

View File

@ -9,7 +9,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon GET"
import os
import urllib.parse
from utils import get_mutuals_of_person
from utils import get_cached_post_filename
@ -31,6 +30,7 @@ from reaction import undo_reaction_collection_entry
from reaction import update_reaction_collection
from follow import follower_approval_active
from webapp_post import individual_post_as_html
from data import is_a_file
def reaction_button(self, calling_domain: str, path: str,
@ -260,7 +260,7 @@ def reaction_button(self, calling_domain: str, path: str,
if not mitm:
mitm_filename = \
reaction_post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(mitm_filename):
if is_a_file(mitm_filename):
mitm = True
bold_reading: bool = False
if bold_reading_nicknames.get(self.post_to_nickname):
@ -554,7 +554,7 @@ def reaction_button_undo(self, calling_domain: str, path: str,
if not mitm:
mitm_filename = \
reaction_post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(mitm_filename):
if is_a_file(mitm_filename):
mitm = True
bold_reading: bool = False
if bold_reading_nicknames.get(self.post_to_nickname):

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon GET"
import os
import time
from httpcodes import http_304
from httpcodes import http_404
@ -19,6 +18,7 @@ from utils import get_css
from fitnessFunctions import fitness_performance
from daemon_utils import etag_exists
from data import load_binary
from data import is_a_file
def get_style_sheet(self, base_dir: str, calling_domain: str, path: str,
@ -35,7 +35,7 @@ def get_style_sheet(self, base_dir: str, calling_domain: str, path: str,
css = None
if css_cache.get(path):
css = css_cache[path]
elif os.path.isfile(path):
elif is_a_file(path):
tries: int = 0
while tries < 5:
try:
@ -101,7 +101,7 @@ def get_fonts(self, calling_domain: str, path: str,
'_GET', '_get_fonts cache',
debug)
return
if os.path.isfile(font_filename):
if is_a_file(font_filename):
font_binary = load_binary(font_filename,
'EX: unable to load font ' +
font_filename)

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon GET"
import os
from httpcodes import http_404
from httpcodes import write2
from httpheaders import set_headers
@ -15,6 +14,7 @@ from httpheaders import set_headers_etag
from utils import get_nickname_from_actor
from blocking import export_blocking_file
from data import load_binary
from data import is_a_file
def get_exported_blocks(self, path: str, base_dir: str,
@ -43,7 +43,7 @@ def get_exported_theme(self, path: str, base_dir: str,
"""
filename = path.split('/exports/', 1)[1]
filename = base_dir + '/exports/' + filename
if os.path.isfile(filename):
if is_a_file(filename):
export_binary = load_binary(filename,
'EX: unable to read theme export ' +
filename)

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon GET"
import os
import urllib.parse
from fitnessFunctions import fitness_performance
from httpheaders import set_headers_etag
@ -20,6 +19,7 @@ from utils import get_config_param
from utils import binary_is_image
from formats import media_file_mime_type
from data import load_binary
from data import is_a_file
def get_favicon(self, calling_domain: str,
@ -51,7 +51,7 @@ def get_favicon(self, calling_domain: str,
base_dir + '/theme/' + self.server.theme_name + \
'/icons/' + fav_filename
if not fav_filename.endswith('.ico'):
if not os.path.isfile(favicon_filename):
if not is_a_file(favicon_filename):
if fav_filename.endswith('.webp'):
fav_filename = fav_filename.replace('.webp', '.ico')
elif fav_filename.endswith('.avif'):
@ -60,7 +60,7 @@ def get_favicon(self, calling_domain: str,
fav_filename = fav_filename.replace('.heic', '.ico')
elif fav_filename.endswith('.jxl'):
fav_filename = fav_filename.replace('.jxl', '.ico')
if not os.path.isfile(favicon_filename):
if not is_a_file(favicon_filename):
# default favicon
favicon_filename = \
base_dir + '/theme/default/icons/' + fav_filename
@ -81,7 +81,7 @@ def get_favicon(self, calling_domain: str,
if debug:
print('Sent favicon from cache: ' + calling_domain)
return
if os.path.isfile(favicon_filename):
if is_a_file(favicon_filename):
fav_binary = load_binary(favicon_filename,
'EX: unable to read favicon ' +
favicon_filename)
@ -122,7 +122,7 @@ def show_cached_favicon(self, referer_domain: str, path: str,
fitness_performance(getreq_start_time, fitness,
'_GET', '_show_cached_favicon2', debug)
return
if not os.path.isfile(fav_filename):
if not is_a_file(fav_filename):
http_404(self, 44)
return
if etag_exists(self, fav_filename):

View File

@ -31,6 +31,7 @@ from person import save_person_qrcode
from lxmf import save_lxmf_qrcode
from data import load_string
from data import load_binary
from data import is_a_file
def show_avatar_or_banner(self, referer_domain: str, path: str,
@ -79,7 +80,7 @@ def show_avatar_or_banner(self, referer_domain: str, path: str,
avatar_file = 'watermark_image.' + avatar_file_ext
avatar_filename = \
acct_dir(base_dir, avatar_nickname, domain) + '/' + avatar_file
if not os.path.isfile(avatar_filename):
if not is_a_file(avatar_filename):
original_ext = avatar_file_ext
original_avatar_file = avatar_file
alt_ext = get_image_extensions()
@ -93,7 +94,7 @@ def show_avatar_or_banner(self, referer_domain: str, path: str,
avatar_filename = \
acct_dir(base_dir, avatar_nickname, domain) + \
'/' + avatar_file
if os.path.isfile(avatar_filename):
if is_a_file(avatar_filename):
alt_found = True
break
if not alt_found:
@ -131,7 +132,7 @@ def show_cached_avatar(self, referer_domain: str, path: str,
"""Shows an avatar image obtained from the cache
"""
media_filename = base_dir + '/cache' + path
if os.path.isfile(media_filename):
if is_a_file(media_filename):
if etag_exists(self, media_filename):
# The file has not changed
http_304(self)
@ -175,14 +176,14 @@ def show_help_screen_image(self, path: str,
media_filename = \
base_dir + '/theme/' + theme + '/helpimages/' + icon_filename
# if there is no theme-specific help image then use the default one
if not os.path.isfile(media_filename):
if not is_a_file(media_filename):
media_filename = \
base_dir + '/theme/default/helpimages/' + icon_filename
if etag_exists(self, media_filename):
# The file has not changed
http_304(self)
return
if os.path.isfile(media_filename):
if is_a_file(media_filename):
media_binary = load_binary(media_filename,
'EX: unable to read help image ' +
media_filename)
@ -230,7 +231,7 @@ def show_manual_image(self, path: str,
'_GET', 'show_manual_image',
debug)
return
if os.path.isfile(media_filename):
if is_a_file(media_filename):
media_binary = load_binary(media_filename,
'EX: unable to read manual image ' +
media_filename)
@ -279,7 +280,7 @@ def show_specification_image(self, path: str,
'_GET', 'show_specification_image',
debug)
return
if os.path.isfile(media_filename):
if is_a_file(media_filename):
media_binary = load_binary(media_filename,
'EX: unable to read specification image ' +
media_filename)
@ -311,7 +312,7 @@ def show_share_image(self, path: str,
media_str = path.split('/sharefiles/')[1]
media_filename = base_dir + '/sharefiles/' + media_str
if not os.path.isfile(media_filename):
if not is_a_file(media_filename):
http_404(self, 102)
return True
@ -375,7 +376,7 @@ def show_icon(self, path: str,
fitness_performance(getreq_start_time, fitness,
'_GET', 'show_icon', debug)
return
if os.path.isfile(media_filename):
if is_a_file(media_filename):
media_binary = load_binary(media_filename,
'EX: unable to read icon image ' +
media_filename)
@ -405,7 +406,7 @@ def show_media(self, path: str, base_dir: str,
path_is_audio(path):
media_str = path.split('/media/')[1]
media_filename = base_dir + '/media/' + media_str
if os.path.isfile(media_filename):
if is_a_file(media_filename):
if etag_exists(self, media_filename):
# The file has not changed
http_304(self)
@ -488,7 +489,7 @@ def show_qrcode(self, calling_domain: str, path: str,
save_person_qrcode(base_dir, nickname, domain, qrcode_domain, port)
qr_filename = \
acct_dir(base_dir, nickname, domain) + '/qrcode.png'
if os.path.isfile(qr_filename):
if is_a_file(qr_filename):
if etag_exists(self, qr_filename):
# The file has not changed
http_304(self)
@ -531,11 +532,11 @@ def search_screen_banner(self, path: str,
return True
banner_filename = \
acct_dir(base_dir, nickname, domain) + '/search_banner.png'
if not os.path.isfile(banner_filename):
if os.path.isfile(base_dir + '/theme/default/search_banner.png'):
if not is_a_file(banner_filename):
if is_a_file(base_dir + '/theme/default/search_banner.png'):
copyfile(base_dir + '/theme/default/search_banner.png',
banner_filename)
if os.path.isfile(banner_filename):
if is_a_file(banner_filename):
if etag_exists(self, banner_filename):
# The file has not changed
http_304(self)
@ -577,7 +578,7 @@ def column_image(self, side: str, path: str, base_dir: str, domain: str,
banner_filename = \
acct_dir(base_dir, nickname, domain) + '/' + \
side + '_col_image.png'
if os.path.isfile(banner_filename):
if is_a_file(banner_filename):
if etag_exists(self, banner_filename):
# The file has not changed
http_304(self)
@ -618,7 +619,7 @@ def show_default_profile_background(self, base_dir: str, theme_name: str,
for ext in image_extensions:
bg_filename = \
base_dir + '/theme/' + theme_name + '/image.' + ext
if os.path.isfile(bg_filename):
if is_a_file(bg_filename):
if etag_exists(self, bg_filename):
# The file has not changed
http_304(self)
@ -668,7 +669,7 @@ def show_background_image(self, path: str,
bg_filename = \
data_dir(base_dir) + '/' + \
bg_im + '-background.' + ext
if os.path.isfile(bg_filename):
if is_a_file(bg_filename):
if etag_exists(self, bg_filename):
# The file has not changed
http_304(self)
@ -711,9 +712,9 @@ def show_emoji(self, path: str,
if is_image_file(path):
emoji_str = path.split('/emoji/')[1]
emoji_filename = base_dir + '/emoji/' + emoji_str
if not os.path.isfile(emoji_filename):
if not is_a_file(emoji_filename):
emoji_filename = base_dir + '/emojicustom/' + emoji_str
if os.path.isfile(emoji_filename):
if is_a_file(emoji_filename):
if etag_exists(self, emoji_filename):
# The file has not changed
http_304(self)

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon Timeline"
import os
import json
from webapp_conversation import html_conversation_view
from flags import is_public_post_from_url
@ -50,6 +49,7 @@ from securemode import secure_mode
from context import get_individual_post_context
from conversation import convthread_id_to_conversation_tag
from data import load_string
from data import is_a_file
def _show_post_from_file(self, post_filename: str, liked_by: str,
@ -93,7 +93,7 @@ def _show_post_from_file(self, post_filename: str, liked_by: str,
ua_str: str) -> bool:
"""Shows an individual post from its filename
"""
if not os.path.isfile(post_filename):
if not is_a_file(post_filename):
http_404(self, 71)
self.server.getreq_busy = False
return True
@ -132,7 +132,7 @@ def _show_post_from_file(self, post_filename: str, liked_by: str,
if not mitm:
mitm_filename = \
post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(mitm_filename):
if is_a_file(mitm_filename):
mitm = True
bold_reading: bool = False
@ -301,12 +301,12 @@ def show_individual_post(self, ssml_getreq: bool, authorized: bool,
acct_dir(base_dir, nickname, domain) + '/outbox/' + \
http_prefix + ':##' + domain_full + '#users#' + nickname + \
'#statuses#' + status_number + '.ssml'
if not os.path.isfile(ssml_filename):
if not is_a_file(ssml_filename):
ssml_filename = \
acct_dir(base_dir, nickname, domain) + '/postcache/' + \
http_prefix + ':##' + domain_full + '#users#' + \
nickname + '#statuses#' + status_number + '.ssml'
if not os.path.isfile(ssml_filename):
if not is_a_file(ssml_filename):
http_404(self, 74)
return True
ssml_str = load_string(ssml_filename,
@ -651,12 +651,12 @@ def show_individual_at_post(self, ssml_getreq: bool, authorized: bool,
acct_dir(base_dir, nickname, domain) + '/outbox/' + \
http_prefix + ':##' + domain_full + '#users#' + nickname + \
'#statuses#' + status_number + '.ssml'
if not os.path.isfile(ssml_filename):
if not is_a_file(ssml_filename):
ssml_filename = \
acct_dir(base_dir, nickname, domain) + '/postcache/' + \
http_prefix + ':##' + domain_full + '#users#' + \
nickname + '#statuses#' + status_number + '.ssml'
if not os.path.isfile(ssml_filename):
if not is_a_file(ssml_filename):
http_404(self, 67)
return True
ssml_str = load_string(ssml_filename,
@ -997,7 +997,7 @@ def show_replies_to_post(self, authorized: bool,
nickname + '#statuses#' + status_number
post_replies_filename = \
post_dir + '/' + orig_post_url + '.replies'
if not os.path.isfile(post_replies_filename):
if not is_a_file(post_replies_filename):
# There are no replies,
# so show empty collection
first_str = \

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon GET"
import os
import json
from roles import get_actor_roles_list
from skills import no_of_actor_skills
@ -34,6 +33,7 @@ from webapp_profile import html_profile
from webapp_profile import html_edit_profile
from fitnessFunctions import fitness_performance
from securemode import secure_mode
from data import is_a_file
def show_person_profile(self, authorized: bool,
@ -264,7 +264,7 @@ def show_roles(self, calling_domain: str, referer_domain: str,
post_sections = named_status.split('/')
nickname = post_sections[0]
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if not os.path.isfile(actor_filename):
if not is_a_file(actor_filename):
return False
actor_json = load_json(actor_filename)
@ -423,7 +423,7 @@ def show_skills(self, calling_domain: str, referer_domain: str,
post_sections = named_status.split('/')
nickname = post_sections[0]
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if os.path.isfile(actor_filename):
if is_a_file(actor_filename):
actor_json = load_json(actor_filename)
if actor_json:
if no_of_actor_skills(actor_json) > 0:

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon GET"
import os
from daemon_utils import has_accept
from httpcodes import write2
from httpcodes import http_400
@ -19,6 +18,7 @@ from utils import load_json
from utils import string_contains
from pgp import actor_to_vcard_xml
from pgp import actor_to_vcard
from data import is_a_file
def show_vcard(self, base_dir: str, path: str, calling_domain: str,
@ -60,7 +60,7 @@ def show_vcard(self, base_dir: str, path: str, calling_domain: str,
actor_json = None
actor_filename = \
acct_dir(base_dir, nickname, domain) + '.json'
if os.path.isfile(actor_filename):
if is_a_file(actor_filename):
actor_json = load_json(actor_filename)
if not actor_json:
print('WARN: vcard actor not found ' + actor_filename)

View File

@ -26,6 +26,7 @@ from daemon_utils import log_epicyon_instances
from data import load_string
from data import load_binary
from data import save_string
from data import is_a_file
def daemon_http_head(self) -> None:
@ -109,7 +110,7 @@ def daemon_http_head(self) -> None:
nickname + '@' + self.server.domain + '/' + \
banner_file
if os.path.isfile(media_filename):
if is_a_file(media_filename):
check_path = media_filename
file_length = os.path.getsize(media_filename)
media_tm = os.path.getmtime(media_filename)
@ -120,7 +121,7 @@ def daemon_http_head(self) -> None:
last_modified_time_str = \
last_modified_time.strftime(time_format_str)
media_tag_filename = media_filename + '.etag'
if os.path.isfile(media_tag_filename):
if is_a_file(media_tag_filename):
etag_str = load_string(media_tag_filename,
'EX: do_HEAD unable to read ' +
media_tag_filename)

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon POST"
import os
import errno
import urllib.parse
from socket import error as SocketError
@ -21,6 +20,7 @@ from blocking import is_blocked_hashtag
from filters import is_filtered
from categories import set_hashtag_category
from data import erase_file
from data import is_a_file
def set_hashtag_category2(self, calling_domain: str, cookie: str,
@ -49,7 +49,7 @@ def set_hashtag_category2(self, calling_domain: str, cookie: str,
http_404(self, 15)
return
hashtag_filename = base_dir + '/tags/' + hashtag + '.txt'
if not os.path.isfile(hashtag_filename):
if not is_a_file(hashtag_filename):
# the hashtag does not exist
http_404(self, 16)
return
@ -131,7 +131,7 @@ def set_hashtag_category2(self, calling_domain: str, cookie: str,
category_str, False, False)
else:
category_filename = base_dir + '/tags/' + hashtag + '.category'
if os.path.isfile(category_filename):
if is_a_file(category_filename):
erase_file(category_filename,
'EX: _set_hashtag_category unable to delete ' +
category_filename)

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon POST"
import os
import errno
from socket import error as SocketError
from flags import is_editor
@ -20,6 +19,7 @@ from httpheaders import redirect_headers
from content import extract_text_fields_in_post
from data import save_string
from data import erase_file
from data import is_a_file
def _links_update_edited(fields: {}, links_filename: str) -> None:
@ -43,7 +43,7 @@ def _links_update_edited(fields: {}, links_filename: str) -> None:
'EX: _links_update unable to write ' +
links_filename)
else:
if os.path.isfile(links_filename):
if is_a_file(links_filename):
erase_file(links_filename,
'EX: _links_update unable to delete ' +
links_filename)
@ -61,7 +61,7 @@ def _links_update_about(fields: {}, allow_local_network_access: bool,
'EX: unable to write about ' +
about_filename)
else:
if os.path.isfile(about_filename):
if is_a_file(about_filename):
erase_file(about_filename,
'EX: _links_update unable to delete ' +
about_filename)
@ -78,7 +78,7 @@ def _links_update_tos(fields: {}, allow_local_network_access: bool,
save_string(tos_str, tos_filename,
'EX: unable to write TOS ' + tos_filename)
else:
if os.path.isfile(tos_filename):
if is_a_file(tos_filename):
erase_file(tos_filename,
'EX: _links_update unable to delete ' +
tos_filename)
@ -94,7 +94,7 @@ def _links_update_sepcification(fields: {},
'EX: unable to write specification ' +
specification_filename)
else:
if os.path.isfile(specification_filename):
if is_a_file(specification_filename):
erase_file(specification_filename,
'EX: _links_update_specification unable to delete ' +
specification_filename)

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon POST"
import os
import time
import errno
from hashlib import sha256
@ -38,6 +37,7 @@ from person import activate_account2
from person import register_account
from data import load_string
from data import save_string
from data import is_a_file
def post_login_screen(self, calling_domain: str, cookie: str,
@ -181,7 +181,7 @@ def post_login_screen(self, calling_domain: str, cookie: str,
salt_filename = \
acct_dir(base_dir, login_nickname, domain) + '/.salt'
salt = create_password(32)
if os.path.isfile(salt_filename):
if is_a_file(salt_filename):
salt_str = load_string(salt_filename,
'EX: Unable to read salt for ' +
login_nickname + ' [ex]')

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon POST"
import os
import errno
from socket import error as SocketError
from flags import is_editor
@ -28,6 +27,7 @@ from content import extract_text_fields_in_post
from content import load_dogwhistles
from data import save_string
from data import erase_file
from data import is_a_file
def newswire_update(self, calling_domain: str, cookie: str,
@ -128,7 +128,7 @@ def newswire_update(self, calling_domain: str, cookie: str,
'EX: unable to write ' + newswire_filename)
else:
# text area has been cleared and there is no new feed
if os.path.isfile(newswire_filename):
if is_a_file(newswire_filename):
erase_file(newswire_filename,
'EX: _newswire_update unable to delete ' +
newswire_filename)
@ -142,7 +142,7 @@ def newswire_update(self, calling_domain: str, cookie: str,
'EX: newswire_update unable to write ' +
filter_newswire_filename)
else:
if os.path.isfile(filter_newswire_filename):
if is_a_file(filter_newswire_filename):
erase_file(filter_newswire_filename,
'EX: _newswire_update unable to delete ' +
filter_newswire_filename)
@ -171,7 +171,7 @@ def newswire_update(self, calling_domain: str, cookie: str,
'EX: newswire_update unable to write 4 ' +
hashtag_rules_filename)
else:
if os.path.isfile(hashtag_rules_filename):
if is_a_file(hashtag_rules_filename):
erase_file(hashtag_rules_filename,
'EX: _newswire_update unable to delete ' +
hashtag_rules_filename)
@ -185,7 +185,7 @@ def newswire_update(self, calling_domain: str, cookie: str,
'EX: newswire_update unable to write 5 ' +
newswire_tusted_filename)
else:
if os.path.isfile(newswire_tusted_filename):
if is_a_file(newswire_tusted_filename):
erase_file(newswire_tusted_filename,
'EX: _newswire_update unable to delete ' +
newswire_tusted_filename)
@ -222,7 +222,7 @@ def citations_update(self, calling_domain: str, cookie: str,
citations_filename = \
acct_dir(base_dir, nickname, domain) + '/.citations.txt'
# remove any existing citations file
if os.path.isfile(citations_filename):
if is_a_file(citations_filename):
erase_file(citations_filename,
'EX: _citations_update unable to delete ' +
citations_filename)

View File

@ -51,6 +51,7 @@ from notifyOnPost import remove_notify_on_post
from flags import is_moderator
from data import save_flag_file
from data import erase_file
from data import is_a_file
def _person_options_page_number(options_confirm_params: str) -> int:
@ -603,7 +604,7 @@ def _person_options_post_to_news(self, options_confirm_params: str,
options_nickname, options_domain)
newswire_blocked_filename = account_dir + '/.nonewswire'
if posts_to_news == 'on':
if os.path.isfile(newswire_blocked_filename):
if is_a_file(newswire_blocked_filename):
erase_file(newswire_blocked_filename,
'EX: _person_options unable to delete ' +
newswire_blocked_filename)
@ -655,7 +656,7 @@ def _person_options_post_to_features(self, options_confirm_params: str,
options_nickname, options_domain)
features_blocked_filename = account_dir + '/.nofeatures'
if posts_to_features == 'on':
if os.path.isfile(features_blocked_filename):
if is_a_file(features_blocked_filename):
erase_file(features_blocked_filename,
'EX: _person_options unable to delete ' +
features_blocked_filename)
@ -707,7 +708,7 @@ def _person_options_mod_news(self, options_confirm_params: str,
options_nickname, options_domain)
newswire_mod_filename = account_dir + '/.newswiremoderated'
if mod_posts_to_news != 'on':
if os.path.isfile(newswire_mod_filename):
if is_a_file(newswire_mod_filename):
erase_file(newswire_mod_filename,
'EX: _person_options unable to delete ' +
newswire_mod_filename)

View File

@ -151,6 +151,7 @@ from daemon_utils import post_to_outbox
from data import save_string
from data import save_flag_file
from data import erase_file
from data import is_a_file
def _profile_post_deactivate_account(base_dir: str, nickname: str, domain: str,
@ -257,7 +258,7 @@ def _profile_post_git_projects(base_dir: str, nickname: str, domain: str,
save_string(text, git_projects_filename,
'EX: unable to write git ' + git_projects_filename)
else:
if os.path.isfile(git_projects_filename):
if is_a_file(git_projects_filename):
erase_file(git_projects_filename,
'EX: _profile_edit unable to delete ' +
git_projects_filename)
@ -283,7 +284,7 @@ def _profile_post_peertube_instances(base_dir: str, fields: {}, self,
continue
peertube_instances.append(url)
else:
if os.path.isfile(peertube_instances_file):
if is_a_file(peertube_instances_file):
erase_file(peertube_instances_file,
'EX: _profile_edit unable to delete ' +
peertube_instances_file)
@ -315,7 +316,7 @@ def _profile_post_robots_txt(base_dir: str, fields: {}, self) -> None:
robots_txt_filename = data_dir(base_dir) + '/robots.txt'
if not new_robots_txt:
self.server.robots_txt = ''
if os.path.isfile(robots_txt_filename):
if is_a_file(robots_txt_filename):
erase_file(robots_txt_filename,
'EX: _profile_post_robots_txt' +
' unable to delete ' +
@ -356,7 +357,7 @@ def _profile_post_buy_domains(base_dir: str, fields: {}, self) -> None:
if buy_sites:
save_json(buy_sites, buy_sites_filename)
else:
if os.path.isfile(buy_sites_filename):
if is_a_file(buy_sites_filename):
erase_file(buy_sites_filename,
'EX: unable to delete ' + buy_sites_filename)
@ -436,7 +437,7 @@ def _profile_post_allowed_instances(base_dir: str, nickname: str, domain: str,
'EX: unable to write allowed instances ' +
allowed_instances_filename)
else:
if os.path.isfile(allowed_instances_filename):
if is_a_file(allowed_instances_filename):
erase_file(allowed_instances_filename,
'EX: _profile_edit unable to delete ' +
allowed_instances_filename)
@ -456,7 +457,7 @@ def _profile_post_dm_instances(base_dir: str, nickname: str, domain: str,
'EX: unable to write allowed DM instances ' +
dm_allowed_instances_filename)
else:
if os.path.isfile(dm_allowed_instances_filename):
if is_a_file(dm_allowed_instances_filename):
erase_file(dm_allowed_instances_filename,
'EX: _profile_edit unable to delete ' +
dm_allowed_instances_filename)
@ -470,7 +471,7 @@ def _profile_post_import_theme(base_dir: str, nickname: str,
if not os.path.isdir(base_dir + '/imports'):
os.mkdir(base_dir + '/imports')
filename_base = base_dir + '/imports/newtheme.zip'
if os.path.isfile(filename_base):
if is_a_file(filename_base):
erase_file(filename_base,
'EX: _profile_edit unable to delete ' +
filename_base)
@ -524,7 +525,7 @@ def _profile_post_auto_cw(base_dir: str, nickname: str, domain: str,
auto_cw_filename)
self.server.auto_cw_cache[nickname] = fields['autoCW'].split('\n')
else:
if os.path.isfile(auto_cw_filename):
if is_a_file(auto_cw_filename):
erase_file(auto_cw_filename,
'EX: _profile_edit unable to delete ' +
auto_cw_filename)
@ -543,7 +544,7 @@ def _profile_post_autogenerated_tags(base_dir: str,
'EX: unable to write auto tags ' +
auto_tags_filename)
else:
if os.path.isfile(auto_tags_filename):
if is_a_file(auto_tags_filename):
erase_file(auto_tags_filename,
'EX: _profile_edit unable to delete ' +
auto_tags_filename)
@ -561,7 +562,7 @@ def _profile_post_word_replacements(base_dir: str,
'EX: unable to write switches ' +
switch_filename)
else:
if os.path.isfile(switch_filename):
if is_a_file(switch_filename):
erase_file(switch_filename,
'EX: _profile_edit unable to delete ' +
switch_filename)
@ -579,7 +580,7 @@ def _profile_post_filtered_words_within_bio(base_dir: str,
'EX: unable to write bio filter ' +
filter_bio_filename)
else:
if os.path.isfile(filter_bio_filename):
if is_a_file(filter_bio_filename):
erase_file(filter_bio_filename,
'EX: _profile_edit ' +
'unable to delete bio filter ' +
@ -596,7 +597,7 @@ def _profile_post_filtered_words(base_dir: str, nickname: str, domain: str,
'EX: unable to write filter ' +
filter_filename)
else:
if os.path.isfile(filter_filename):
if is_a_file(filter_filename):
erase_file(filter_filename,
'EX: _profile_edit unable to delete filter ' +
filter_filename)
@ -719,7 +720,7 @@ def _profile_post_notify_reactions(base_dir: str,
'notify reactions ' +
notify_reactions_filename)
if not notify_reactions_active:
if os.path.isfile(notify_reactions_filename):
if is_a_file(notify_reactions_filename):
erase_file(notify_reactions_filename,
'EX: _profile_edit unable to delete ' +
notify_reactions_filename)
@ -749,7 +750,7 @@ def _profile_post_notify_likes(on_final_welcome_screen: bool,
'EX: unable to write notify likes ' +
notify_likes_filename)
if not notify_likes_active:
if os.path.isfile(notify_likes_filename):
if is_a_file(notify_likes_filename):
erase_file(notify_likes_filename,
'EX: _profile_edit unable to delete ' +
notify_likes_filename)
@ -843,12 +844,12 @@ def _profile_post_no_reply_boosts(base_dir: str, nickname: str, domain: str,
if fields['noReplyBoosts'] == 'on':
no_reply_boosts = True
if no_reply_boosts:
if not os.path.isfile(no_reply_boosts_filename):
if not is_a_file(no_reply_boosts_filename):
save_flag_file(no_reply_boosts_filename,
'EX: unable to write noReplyBoosts ' +
no_reply_boosts_filename)
if not no_reply_boosts:
if os.path.isfile(no_reply_boosts_filename):
if is_a_file(no_reply_boosts_filename):
erase_file(no_reply_boosts_filename,
'EX: _profile_edit unable to delete ' +
no_reply_boosts_filename)
@ -865,12 +866,12 @@ def _profile_post_no_seen_posts(base_dir: str, nickname: str, domain: str,
if fields['noSeenPosts'] == 'on':
no_seen_posts = True
if no_seen_posts:
if not os.path.isfile(no_seen_posts_filename):
if not is_a_file(no_seen_posts_filename):
save_flag_file(no_seen_posts_filename,
'EX: unable to write noSeenPosts ' +
no_seen_posts_filename)
if not no_seen_posts:
if os.path.isfile(no_seen_posts_filename):
if is_a_file(no_seen_posts_filename):
erase_file(no_seen_posts_filename,
'EX: _profile_edit unable to delete ' +
no_seen_posts_filename)
@ -888,12 +889,12 @@ def _profile_post_watermark_enabled(base_dir: str,
if fields['watermarkEnabled'] == 'on':
watermark_enabled = True
if watermark_enabled:
if not os.path.isfile(watermark_enabled_filename):
if not is_a_file(watermark_enabled_filename):
save_flag_file(watermark_enabled_filename,
'EX: unable to write watermarkEnabled ' +
watermark_enabled_filename)
if not watermark_enabled:
if os.path.isfile(watermark_enabled_filename):
if is_a_file(watermark_enabled_filename):
erase_file(watermark_enabled_filename,
'EX: _profile_edit ' +
'unable to delete ' +
@ -917,7 +918,7 @@ def _profile_post_hide_follows(base_dir: str, nickname: str, domain: str,
self.server.hide_follows[nickname] = True
actor_json['hideFollows'] = True
actor_changed = True
if not os.path.isfile(hide_follows_filename):
if not is_a_file(hide_follows_filename):
save_flag_file(hide_follows_filename,
'EX: unable to write hideFollows ' +
hide_follows_filename)
@ -926,7 +927,7 @@ def _profile_post_hide_follows(base_dir: str, nickname: str, domain: str,
if self.server.hide_follows.get(nickname):
del self.server.hide_follows[nickname]
actor_changed = True
if os.path.isfile(hide_follows_filename):
if is_a_file(hide_follows_filename):
erase_file(hide_follows_filename,
'EX: _profile_post_hide_follows ' +
'unable to delete ' +
@ -951,7 +952,7 @@ def _profile_post_hide_recent_posts(base_dir: str, nickname: str, domain: str,
self.server.hide_recent_posts[nickname] = True
actor_json['hideRecentPosts'] = True
actor_changed = True
if not os.path.isfile(hide_recent_posts_filename):
if not is_a_file(hide_recent_posts_filename):
save_flag_file(hide_recent_posts_filename,
'EX: unable to write hideRecentPosts ' +
hide_recent_posts_filename)
@ -960,7 +961,7 @@ def _profile_post_hide_recent_posts(base_dir: str, nickname: str, domain: str,
if self.server.hide_recent_posts.get(nickname):
del self.server.hide_recent_posts[nickname]
actor_changed = True
if os.path.isfile(hide_recent_posts_filename):
if is_a_file(hide_recent_posts_filename):
erase_file(hide_recent_posts_filename,
'EX: _profile_post_hide_recent_posts ' +
'unable to delete ' +
@ -976,7 +977,7 @@ def _profile_post_mutuals_replies(account_dir: str, fields: {}) -> None:
if fields['repliesFromMutualsOnly'] == 'on':
show_replies_mutuals = True
show_replies_mutuals_file = account_dir + '/.repliesFromMutualsOnly'
if os.path.isfile(show_replies_mutuals_file):
if is_a_file(show_replies_mutuals_file):
if not show_replies_mutuals:
erase_file(show_replies_mutuals_file,
'EX: unable to remove repliesFromMutualsOnly file ' +
@ -997,7 +998,7 @@ def _profile_post_only_follower_replies(fields: {},
if fields['repliesFromFollowersOnly'] == 'on':
show_replies_followers = True
show_replies_followers_file = account_dir + '/.repliesFromFollowersOnly'
if os.path.isfile(show_replies_followers_file):
if is_a_file(show_replies_followers_file):
if not show_replies_followers:
erase_file(show_replies_followers_file,
'EX: unable to remove ' +
@ -1019,7 +1020,7 @@ def _profile_post_show_quote_toots(fields: {}, account_dir: str) -> None:
if fields['showQuotes'] == 'on':
show_quote_toots = True
show_quote_toots_file = account_dir + '/.allowQuotes'
if os.path.isfile(show_quote_toots_file):
if is_a_file(show_quote_toots_file):
if not show_quote_toots:
erase_file(show_quote_toots_file,
'EX: unable to remove allowQuotes file ' +
@ -1039,7 +1040,7 @@ def _profile_post_show_questions(fields: {}, account_dir: str) -> None:
if fields['showVotes'] == 'on':
show_vote_posts = True
show_vote_file = account_dir + '/.noVotes'
if os.path.isfile(show_vote_file):
if is_a_file(show_vote_file):
if show_vote_posts:
erase_file(show_vote_file,
'EX: unable to remove noVotes file ' +
@ -1088,7 +1089,7 @@ def _profile_post_bold_reading(base_dir: str,
if not bold_reading:
if self.server.bold_reading.get(nickname):
del self.server.bold_reading[nickname]
if os.path.isfile(bold_reading_filename):
if is_a_file(bold_reading_filename):
erase_file(bold_reading_filename,
'EX: _profile_edit unable to delete ' +
bold_reading_filename)
@ -1111,12 +1112,12 @@ def _profile_post_hide_reaction_button2(base_dir: str,
'EX: unable to write hide reaction ' +
hide_reaction_button_file)
# remove notify Reaction selection
if os.path.isfile(notify_reactions_filename):
if is_a_file(notify_reactions_filename):
erase_file(notify_reactions_filename,
'EX: _profile_edit unable to delete ' +
notify_reactions_filename)
if not hide_reaction_button_active:
if os.path.isfile(hide_reaction_button_file):
if is_a_file(hide_reaction_button_file):
erase_file(hide_reaction_button_file,
'EX: _profile_edit unable to delete ' +
hide_reaction_button_file)
@ -1162,12 +1163,12 @@ def _profile_post_hide_like_button2(base_dir: str, nickname: str, domain: str,
'EX: unable to write hide like ' +
hide_like_button_file)
# remove notify likes selection
if os.path.isfile(notify_likes_filename):
if is_a_file(notify_likes_filename):
erase_file(notify_likes_filename,
'EX: _profile_edit unable to delete ' +
notify_likes_filename)
if not hide_like_button_active:
if os.path.isfile(hide_like_button_file):
if is_a_file(hide_like_button_file):
erase_file(hide_like_button_file,
'EX: _profile_edit unable to delete ' +
hide_like_button_file)
@ -1187,7 +1188,7 @@ def _profile_post_remove_retweets(base_dir: str, nickname: str, domain: str,
'EX: unable to write remove twitter ' +
remove_twitter_filename)
if not remove_twitter_active:
if os.path.isfile(remove_twitter_filename):
if is_a_file(remove_twitter_filename):
erase_file(remove_twitter_filename,
'EX: _profile_edit unable to delete ' +
remove_twitter_filename)
@ -1216,7 +1217,7 @@ def _profile_post_dms_from_followers(base_dir: str, nickname: str, domain: str,
'EX: unable to write follow DMs 2 ' +
follow_dms_filename)
if not follow_dms_active:
if os.path.isfile(follow_dms_filename):
if is_a_file(follow_dms_filename):
erase_file(follow_dms_filename,
'EX: _profile_edit unable to delete ' +
follow_dms_filename)
@ -1236,18 +1237,14 @@ def _profile_post_remove_custom_font(base_dir: str, nickname: str, domain: str,
path.startswith('/users/' + admin_nickname + '/'))):
font_ext = ('woff', 'woff2', 'otf', 'ttf')
for ext in font_ext:
if os.path.isfile(base_dir + '/fonts/custom.' + ext):
if is_a_file(base_dir + '/fonts/custom.' + ext):
erase_file(base_dir + '/fonts/custom.' + ext,
'EX: _profile_edit unable to delete ' +
base_dir + '/fonts/custom.' + ext)
if os.path.isfile(base_dir +
'/fonts/custom.' + ext + '.etag'):
erase_file(base_dir +
'/fonts/custom.' + ext + '.etag',
'EX: _profile_edit ' +
'unable to delete ' +
base_dir + '/fonts/custom.' +
ext + '.etag')
if is_a_file(base_dir + '/fonts/custom.' + ext + '.etag'):
erase_file(base_dir + '/fonts/custom.' + ext + '.etag',
'EX: _profile_edit unable to delete ' +
base_dir + '/fonts/custom.' + ext + '.etag')
curr_theme = get_theme(base_dir)
if curr_theme:
self.server.theme_name = curr_theme
@ -1299,7 +1296,7 @@ def _profile_post_reject_spam_actors(base_dir: str,
curr_reject_spam_actors: bool = False
actor_spam_filter_filename = \
acct_dir(base_dir, nickname, domain) + '/.reject_spam_actors'
if os.path.isfile(actor_spam_filter_filename):
if is_a_file(actor_spam_filter_filename):
curr_reject_spam_actors = True
if reject_spam_actors != curr_reject_spam_actors:
if reject_spam_actors:
@ -2729,7 +2726,7 @@ def profile_edit(self, calling_domain: str, cookie: str,
if not os.path.isdir(base_dir + '/imports'):
os.mkdir(base_dir + '/imports')
filename_base = base_dir + '/imports/newtheme.zip'
if os.path.isfile(filename_base):
if is_a_file(filename_base):
erase_file(filename_base,
'EX: _profile_edit unable to delete ' +
filename_base)
@ -2754,7 +2751,7 @@ def profile_edit(self, calling_domain: str, cookie: str,
continue
if m_type == 'importFollows':
if os.path.isfile(filename_base):
if is_a_file(filename_base):
print(nickname + ' imported follows csv')
else:
print('WARN: failed to import follows from csv for ' +
@ -2775,7 +2772,7 @@ def profile_edit(self, calling_domain: str, cookie: str,
print('DEBUG: POST ' + m_type +
' media removing metadata')
# remove existing etag
if os.path.isfile(post_image_filename + '.etag'):
if is_a_file(post_image_filename + '.etag'):
erase_file(post_image_filename + '.etag',
'EX: _profile_edit unable to delete ' +
post_image_filename + '.etag')
@ -2789,7 +2786,7 @@ def profile_edit(self, calling_domain: str, cookie: str,
process_meta_data(base_dir, nickname, domain,
filename, post_image_filename, city,
content_license_url, exif_json)
if os.path.isfile(post_image_filename):
if is_a_file(post_image_filename):
print('profile update POST ' + m_type +
' image, zip or font saved to ' +
post_image_filename)
@ -2852,7 +2849,7 @@ def profile_edit(self, calling_domain: str, cookie: str,
# load the json for the actor for this user
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if os.path.isfile(actor_filename):
if is_a_file(actor_filename):
actor_json = load_json(actor_filename)
if actor_json:
if not actor_json.get('discoverable'):

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon POST"
import os
import errno
import urllib.parse
from socket import error as SocketError
@ -30,6 +29,7 @@ from daemon_utils import post_to_outbox
from inbox import populate_replies
from data import append_string
from data import erase_file
from data import is_a_file
def receive_vote(self, calling_domain: str, cookie: str,
@ -206,7 +206,7 @@ def _send_reply_to_question(self, base_dir: str,
acct_dir(base_dir, nickname, domain) + \
'/questions.txt'
if os.path.isfile(votes_filename):
if is_a_file(votes_filename):
# have we already voted on this?
if text_in_file(message_id, votes_filename):
print('Already voted on message ' + message_id)
@ -302,7 +302,7 @@ def _send_reply_to_question(self, base_dir: str,
nickname, domain,
post_json_object)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
erase_file(cached_post_filename,
'EX: _send_reply_to_question ' +
'unable to delete ' +

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon POST"
import os
import time
import copy
import errno
@ -68,6 +67,7 @@ from maps import geocoords_to_osm_link
from data import save_string
from data import erase_file
from data import move_file
from data import is_a_file
NEW_POST_SUCCESS = 1
NEW_POST_FAILED = -1
@ -416,14 +416,14 @@ def _receive_new_post_process_editblog(self, fields: {},
print('Edited blog post received')
post_filename = \
locate_post(base_dir, nickname, domain, fields['postUrl'])
if os.path.isfile(post_filename):
if is_a_file(post_filename):
post_json_object = load_json(post_filename)
if post_json_object:
cached_filename = \
acct_dir(base_dir, nickname, domain) + \
'/postcache/' + \
fields['postUrl'].replace('/', '#') + '.html'
if os.path.isfile(cached_filename):
if is_a_file(cached_filename):
print('Edited blog post, removing cached html')
erase_file(cached_filename,
'EX: _receive_new_post_process ' +
@ -1718,7 +1718,7 @@ def _receive_new_post_process_newshare(self, fields: {},
if not actor_json:
actor_filename = \
acct_dir(base_dir, nickname, domain) + '.json'
if os.path.isfile(actor_filename):
if is_a_file(actor_filename):
actor_json = load_json(actor_filename)
if actor_json:
if add_shares_to_actor(base_dir, nickname, domain,
@ -1745,7 +1745,7 @@ def _receive_new_post_process_newshare(self, fields: {},
debug)
if filename:
if os.path.isfile(filename):
if is_a_file(filename):
erase_file(filename,
'EX: _receive_new_post_process ' +
'unable to delete ' + filename)
@ -1903,14 +1903,14 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
process_meta_data(base_dir, nickname, domain,
filename, post_image_filename, city,
content_license_url, exif_json)
if os.path.isfile(post_image_filename):
if is_a_file(post_image_filename):
print('POST media saved to ' + post_image_filename)
else:
exif_json = []
print('ERROR: POST media could not be saved to ' +
post_image_filename)
else:
if os.path.isfile(filename):
if is_a_file(filename):
new_filename = filename.replace('.temp', '')
if move_file(filename, new_filename,
'EX: POST could not rename ' +

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon POST"
import os
import errno
import urllib.parse
from socket import error as SocketError
@ -32,6 +31,7 @@ from person import get_actor_update_json
from daemon_utils import post_to_outbox_thread
from daemon_utils import post_to_outbox
from happening import remove_calendar_event
from data import is_a_file
def remove_reading_status(self, calling_domain: str, cookie: str,
@ -195,7 +195,7 @@ def remove_share(self, calling_domain: str, cookie: str,
actor_filename = \
acct_dir(base_dir, share_nickname,
share_domain) + '.json'
if os.path.isfile(actor_filename):
if is_a_file(actor_filename):
actor_json = load_json(actor_filename)
if actor_json:
if add_shares_to_actor(base_dir,

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Daemon"
import os
import time
from auth import authorize
from threads import thread_with_trace
@ -79,6 +78,7 @@ from httpheaders import set_headers
from fitnessFunctions import fitness_performance
from siteactive import is_online
from data import load_string
from data import is_a_file
def post_to_outbox(self, message_json: {}, version: str,
@ -904,7 +904,7 @@ def etag_exists(self, media_filename: str) -> bool:
if self.headers.get(etag_header):
old_etag = self.headers[etag_header].replace('"', '')
if os.path.isfile(media_filename + '.etag'):
if is_a_file(media_filename + '.etag'):
# load the etag from file
exc_str = 'EX: _etag_exists unable to read ' + \
str(media_filename)
@ -953,7 +953,7 @@ def load_known_epicyon_instances(base_dir: str) -> []:
"""
epicyon_instances_filename = \
data_dir(base_dir) + '/known_epicyon_instances.json'
if not os.path.isfile(epicyon_instances_filename):
if not is_a_file(epicyon_instances_filename):
return []
known_epicyon_instances = load_json(epicyon_instances_filename)
if not known_epicyon_instances:

View File

@ -177,3 +177,9 @@ def move_file(old_filename: str, new_filename: str,
exception_text = exception_text.replace('[ex]', str(exc))
print(exception_text)
return False
def is_a_file(filename: str) -> bool:
"""Returns true if the given filename exists
"""
return os.path.isfile(filename)

View File

@ -29,6 +29,7 @@ from webfinger import webfinger_handle
from auth import create_basic_auth_header
from posts import get_person_box
from data import erase_file
from data import is_a_file
def send_delete_via_server(base_dir: str, session,
@ -198,7 +199,7 @@ def remove_old_hashtags(base_dir: str, max_months: int) -> str:
for _, _, files in os.walk(base_dir + '/tags'):
for fname in files:
tags_filename = os.path.join(base_dir + '/tags', fname)
if not os.path.isfile(tags_filename):
if not is_a_file(tags_filename):
continue
# get last modified datetime
mod_time_since_epoc = os.path.getmtime(tags_filename)

View File

@ -75,6 +75,7 @@ from cache import get_person_from_cache
from data import save_string
from data import load_string
from data import prepend_string
from data import is_a_file
def _desktop_help() -> None:
@ -186,7 +187,7 @@ def _mark_post_as_read(actor: str, post_id: str, post_category: str) -> None:
handle += '_' + str(port)
read_posts_dir = home_dir + '/.config/epicyon/' + handle
read_posts_filename = read_posts_dir + '/' + post_category + '.txt'
if os.path.isfile(read_posts_filename):
if is_a_file(read_posts_filename):
if text_in_file(post_id, read_posts_filename):
return
prepend_string(post_id, read_posts_filename,
@ -212,7 +213,7 @@ def _has_read_post(actor: str, post_id: str, post_category: str) -> bool:
handle += '_' + str(port)
read_posts_dir = home_dir + '/.config/epicyon/' + handle
read_posts_filename = read_posts_dir + '/' + post_category + '.txt'
if os.path.isfile(read_posts_filename):
if is_a_file(read_posts_filename):
if text_in_file(post_id, read_posts_filename):
return True
return False
@ -317,10 +318,10 @@ def _desktop_show_banner() -> None:
"""Shows the banner at the top
"""
banner_filename = 'banner.txt'
if not os.path.isfile(banner_filename):
if not is_a_file(banner_filename):
banner_theme = 'starlight'
banner_filename = 'theme/' + banner_theme + '/banner.txt'
if not os.path.isfile(banner_filename):
if not is_a_file(banner_filename):
return
banner = load_string(banner_filename,
'EX: unable to read banner file ' + banner_filename)
@ -348,7 +349,7 @@ def _play_sound(sound_filename: str,
player: str = 'ffplay') -> None:
"""Plays a sound
"""
if not os.path.isfile(sound_filename):
if not is_a_file(sound_filename):
return
if player == 'ffplay':

View File

@ -137,6 +137,7 @@ from siteactive import site_is_active
from siteactive import is_online
from data import save_string
from data import load_list
from data import is_a_file
def str2bool(value_str) -> bool:
@ -908,7 +909,7 @@ def _command_options() -> None:
if argb.debug:
debug = True
else:
if os.path.isfile('debug'):
if is_a_file('debug'):
debug = True
if argb.accounts_data_dir:
@ -1976,7 +1977,7 @@ def _command_options() -> None:
accounts_dir = acct_dir(base_dir, argb.nickname, domain)
approve_follows_filename = accounts_dir + '/followrequests.txt'
approve_ctr: int = 0
if os.path.isfile(approve_follows_filename):
if is_a_file(approve_follows_filename):
approve_follows_list: list[str] = \
load_list(approve_follows_filename,
'EX: unable to read follow approvals file ' +
@ -3461,7 +3462,7 @@ def _command_options() -> None:
print('Account ' + nickname + '@' + domain + ' not found')
sys.exit()
password_file = data_dir(base_dir) + '/passwords'
if os.path.isfile(password_file):
if is_a_file(password_file):
if text_in_file(nickname + ':', password_file):
store_basic_credentials(base_dir, nickname, new_password)
print('Password for ' + nickname + ' was changed')
@ -3503,7 +3504,7 @@ def _command_options() -> None:
sys.exit()
if argb.avatar:
if not os.path.isfile(argb.avatar):
if not is_a_file(argb.avatar):
print(argb.avatar + ' is not an image filename')
sys.exit()
if not argb.nickname:
@ -3519,7 +3520,7 @@ def _command_options() -> None:
sys.exit()
if argb.backgroundImage:
if not os.path.isfile(argb.backgroundImage):
if not is_a_file(argb.backgroundImage):
print(argb.backgroundImage + ' is not an image filename')
sys.exit()
if not argb.nickname:

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Moderation"
import os
import fnmatch
from utils import data_dir
from utils import acct_dir
@ -20,6 +19,7 @@ from data import append_string
from data import save_string
from data import load_list
from data import move_file
from data import is_a_file
def add_filter(base_dir: str, nickname: str, domain: str, words: str) -> bool:
@ -27,7 +27,7 @@ def add_filter(base_dir: str, nickname: str, domain: str, words: str) -> bool:
incoming posts
"""
filters_filename = acct_dir(base_dir, nickname, domain) + '/filters.txt'
if os.path.isfile(filters_filename):
if is_a_file(filters_filename):
if text_in_file(words, filters_filename):
return False
if not append_string(words + '\n', filters_filename,
@ -45,7 +45,7 @@ def add_global_filter(base_dir: str, words: str) -> bool:
if len(words) < 2:
return False
filters_filename = data_dir(base_dir) + '/filters.txt'
if os.path.isfile(filters_filename):
if is_a_file(filters_filename):
if text_in_file(words, filters_filename):
return False
if not append_string(words + '\n', filters_filename,
@ -59,7 +59,7 @@ def remove_filter(base_dir: str, nickname: str, domain: str,
"""Removes a word filter
"""
filters_filename = acct_dir(base_dir, nickname, domain) + '/filters.txt'
if not os.path.isfile(filters_filename):
if not is_a_file(filters_filename):
return False
if not text_in_file(words, filters_filename):
return False
@ -81,7 +81,7 @@ def remove_filter(base_dir: str, nickname: str, domain: str,
'EX: unable to remove filter ' +
filters_filename + ' 2 [ex]')
if os.path.isfile(new_filters_filename):
if is_a_file(new_filters_filename):
if move_file(new_filters_filename, filters_filename,
'EX: remove_filter could not rename ' +
new_filters_filename + ' -> ' + filters_filename):
@ -93,7 +93,7 @@ def remove_global_filter(base_dir: str, words: str) -> bool:
"""Removes a global word filter
"""
filters_filename = data_dir(base_dir) + '/filters.txt'
if not os.path.isfile(filters_filename):
if not is_a_file(filters_filename):
return False
if not text_in_file(words, filters_filename):
return False
@ -115,7 +115,7 @@ def remove_global_filter(base_dir: str, words: str) -> bool:
'EX: unable to remove global filter ' +
filters_filename + ' 2 [ex]')
if os.path.isfile(new_filters_filename):
if is_a_file(new_filters_filename):
if move_file(new_filters_filename, filters_filename,
'EX: remove_global_filter could not rename ' +
new_filters_filename + ' -> ' + filters_filename):
@ -154,7 +154,7 @@ def _is_filtered_base(filename: str, content: str,
"""Uses the given file containing filtered words to check
the given content
"""
if not os.path.isfile(filename):
if not is_a_file(filename):
return False
content = remove_inverted_text(content, system_language)
@ -227,7 +227,7 @@ def is_filtered(base_dir: str, nickname: str, domain: str,
# optionally remove retweets
remove_twitter = acct_dir(base_dir, nickname, domain) + '/.removeTwitter'
if os.path.isfile(remove_twitter):
if is_a_file(remove_twitter):
if _is_twitter_post(content):
return True

View File

@ -7,13 +7,13 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Core"
import os
import time
from webapp_utils import html_header_with_external_style
from webapp_utils import html_footer
from utils import data_dir
from utils import get_config_param
from utils import save_json
from data import is_a_file
def fitness_performance(start_time, fitness_state: {},
@ -76,7 +76,7 @@ def html_watch_points_graph(base_dir: str, fitness: {}, fitness_id: str,
watch_points_list = sorted_watch_points(fitness, fitness_id)
css_filename = base_dir + '/epicyon-graph.css'
if os.path.isfile(base_dir + '/graph.css'):
if is_a_file(base_dir + '/graph.css'):
css_filename = base_dir + '/graph.css'
instance_title = \

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Core"
import os
import re
from timeFunctions import date_utcnow
from timeFunctions import get_published_date
@ -32,6 +31,7 @@ from utils import get_group_paths
from formats import get_image_extensions
from quote import get_quote_toot_url
from data import load_string
from data import is_a_file
def is_featured_writer(base_dir: str, nickname: str, domain: str) -> bool:
@ -40,7 +40,7 @@ def is_featured_writer(base_dir: str, nickname: str, domain: str) -> bool:
"""
features_blocked_filename = \
acct_dir(base_dir, nickname, domain) + '/.nofeatures'
return not os.path.isfile(features_blocked_filename)
return not is_a_file(features_blocked_filename)
def is_dormant(base_dir: str, nickname: str, domain: str, actor: str,
@ -51,7 +51,7 @@ def is_dormant(base_dir: str, nickname: str, domain: str, actor: str,
last_seen_filename = acct_dir(base_dir, nickname, domain) + \
'/lastseen/' + actor.replace('/', '#') + '.txt'
if not os.path.isfile(last_seen_filename):
if not is_a_file(last_seen_filename):
return False
days_since_epoch_str = \
@ -76,7 +76,7 @@ def is_editor(base_dir: str, nickname: str) -> bool:
"""
editors_file = data_dir(base_dir) + '/editors.txt'
if not os.path.isfile(editors_file):
if not is_a_file(editors_file):
admin_name = get_config_param(base_dir, 'admin')
if admin_name:
if admin_name == nickname:
@ -106,7 +106,7 @@ def is_artist(base_dir: str, nickname: str) -> bool:
"""
artists_file = data_dir(base_dir) + '/artists.txt'
if not os.path.isfile(artists_file):
if not is_a_file(artists_file):
admin_name = get_config_param(base_dir, 'admin')
if admin_name:
if admin_name == nickname:
@ -152,7 +152,7 @@ def is_memorial_account(base_dir: str, nickname: str) -> bool:
"""Returns true if the given nickname is a memorial account
"""
memorial_file = data_dir(base_dir) + '/memorial'
if not os.path.isfile(memorial_file):
if not is_a_file(memorial_file):
return False
memorial_list: list[str] = \
load_string(memorial_file,
@ -174,7 +174,7 @@ def is_suspended(base_dir: str, nickname: str) -> bool:
return False
suspended_filename = data_dir(base_dir) + '/suspended.txt'
if os.path.isfile(suspended_filename):
if is_a_file(suspended_filename):
lines: list[str] = \
load_string(suspended_filename,
'EX: is_suspended unable to read ' +
@ -510,7 +510,7 @@ def is_group_actor(base_dir: str, actor: str, person_cache: {},
print('Actor ' + actor + ' not in cache')
cached_actor_filename = \
base_dir + '/cache/actors/' + (actor.replace('/', '#')) + '.json'
if not os.path.isfile(cached_actor_filename):
if not is_a_file(cached_actor_filename):
if debug:
print('Cached actor file not found ' + cached_actor_filename)
return False
@ -525,7 +525,7 @@ def is_group_account(base_dir: str, nickname: str, domain: str) -> bool:
"""Returns true if the given account is a group
"""
account_filename = acct_dir(base_dir, nickname, domain) + '.json'
if not os.path.isfile(account_filename):
if not is_a_file(account_filename):
return False
if text_in_file('"type": "Group"', account_filename):
return True
@ -607,7 +607,7 @@ def is_premium_account(base_dir: str, nickname: str, domain: str) -> bool:
""" Is the given account a premium one?
"""
premium_filename = acct_dir(base_dir, nickname, domain) + '/.premium'
return os.path.isfile(premium_filename)
return is_a_file(premium_filename)
def url_permitted(url: str, federation_list: []) -> bool:
@ -721,7 +721,7 @@ def is_moderator(base_dir: str, nickname: str) -> bool:
"""
moderators_file = data_dir(base_dir) + '/moderators.txt'
if not os.path.isfile(moderators_file):
if not is_a_file(moderators_file):
admin_name = get_config_param(base_dir, 'admin')
if not admin_name:
return False

View File

@ -51,6 +51,7 @@ from data import load_list
from data import save_string
from data import erase_file
from data import move_file
from data import is_a_file
def create_initial_last_seen(base_dir: str, http_prefix: str) -> None:
@ -65,7 +66,7 @@ def create_initial_last_seen(base_dir: str, http_prefix: str) -> None:
continue
account_dir = os.path.join(dir_str, acct)
following_filename = account_dir + '/following.txt'
if not os.path.isfile(following_filename):
if not is_a_file(following_filename):
continue
last_seen_dir = account_dir + '/lastseen'
if not os.path.isdir(last_seen_dir):
@ -89,7 +90,7 @@ def create_initial_last_seen(base_dir: str, http_prefix: str) -> None:
actor = local_actor_url(http_prefix, nickname, domain)
last_seen_filename = \
last_seen_dir + '/' + actor.replace('/', '#') + '.txt'
if os.path.isfile(last_seen_filename):
if is_a_file(last_seen_filename):
continue
text = str(100)
save_string(text, last_seen_filename,
@ -105,7 +106,7 @@ def _pre_approved_follower(base_dir: str,
"""
account_dir = acct_dir(base_dir, nickname, domain)
approved_filename = account_dir + '/approved.txt'
if os.path.isfile(approved_filename):
if is_a_file(approved_filename):
if text_in_file(approve_handle, approved_filename):
return True
return False
@ -119,7 +120,7 @@ def _remove_from_follow_base(base_dir: str,
"""
accounts_dir = acct_dir(base_dir, nickname, domain)
approve_follows_filename = accounts_dir + '/' + follow_file + '.txt'
if not os.path.isfile(approve_follows_filename):
if not is_a_file(approve_follows_filename):
if debug:
print('There is no ' + follow_file +
' to remove ' + nickname + '@' + domain + ' from')
@ -201,7 +202,7 @@ def is_following_actor(base_dir: str,
if not os.path.isdir(accounts_dir):
return False
following_file = accounts_dir + '/following.txt'
if not os.path.isfile(following_file):
if not is_a_file(following_file):
return False
if actor.startswith('@'):
actor = actor[1:]
@ -240,7 +241,7 @@ def get_follower_domains(base_dir: str, nickname: str, domain: str) -> []:
"""
domain = remove_domain_port(domain)
followers_file = acct_dir(base_dir, nickname, domain) + '/followers.txt'
if not os.path.isfile(followers_file):
if not is_a_file(followers_file):
return []
lines: list[str] = \
@ -273,7 +274,7 @@ def is_follower_of_person(base_dir: str, nickname: str, domain: str,
return False
domain = remove_domain_port(domain)
followers_file = acct_dir(base_dir, nickname, domain) + '/followers.txt'
if not os.path.isfile(followers_file):
if not is_a_file(followers_file):
return False
handle = follower_nickname + '@' + follower_domain
@ -322,7 +323,7 @@ def unfollow_account(base_dir: str, nickname: str, domain: str,
accounts_dir = acct_dir(base_dir, nickname, domain)
filename = accounts_dir + '/' + follow_file
if not os.path.isfile(filename):
if not is_a_file(filename):
if debug:
print('DEBUG: follow file ' + filename + ' was not found')
return False
@ -352,7 +353,7 @@ def unfollow_account(base_dir: str, nickname: str, domain: str,
# write to an unfollowed file so that if a follow accept
# later arrives then it can be ignored
unfollowed_filename = accounts_dir + '/unfollowed.txt'
if os.path.isfile(unfollowed_filename):
if is_a_file(unfollowed_filename):
if not text_in_file(handle_to_unfollow_lower,
unfollowed_filename, False):
append_string(handle_to_unfollow + '\n', unfollowed_filename,
@ -387,7 +388,7 @@ def clear_follows(base_dir: str, nickname: str, domain: str,
if not os.path.isdir(accounts_dir):
os.mkdir(accounts_dir)
filename = accounts_dir + '/' + follow_file
if os.path.isfile(filename):
if is_a_file(filename):
erase_file(filename,
'EX: clear_follows unable to delete ' + filename)
@ -408,7 +409,7 @@ def _get_no_of_follows(base_dir: str, nickname: str, domain: str,
# return 9999
accounts_dir = acct_dir(base_dir, nickname, domain)
filename = accounts_dir + '/' + follow_file
if not os.path.isfile(filename):
if not is_a_file(filename):
return 0
ctr: int = 0
lines: list[str] = \
@ -528,7 +529,7 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str,
handle_domain = remove_domain_port(handle_domain)
accounts_dir = acct_dir(base_dir, nickname, handle_domain)
filename = accounts_dir + '/' + follow_file + '.txt'
if not os.path.isfile(filename):
if not is_a_file(filename):
return following
curr_page: int = 1
page_ctr: int = 0
@ -594,7 +595,7 @@ def follow_approval_required(base_dir: str, nickname_to_follow: str,
domain_to_follow = remove_domain_port(domain_to_follow)
actor_filename = data_dir(base_dir) + '/' + \
nickname_to_follow + '@' + domain_to_follow + '.json'
if os.path.isfile(actor_filename):
if is_a_file(actor_filename):
actor = load_json(actor_filename)
if actor:
if 'manuallyApprovesFollowers' in actor:
@ -616,7 +617,7 @@ def no_of_follow_requests(base_dir: str,
"""
accounts_dir = acct_dir(base_dir, nickname_to_follow, domain_to_follow)
approve_follows_filename = accounts_dir + '/followrequests.txt'
if not os.path.isfile(approve_follows_filename):
if not is_a_file(approve_follows_filename):
return 0
ctr: int = 0
lines: list[str] = \
@ -660,7 +661,7 @@ def store_follow_request(base_dir: str,
approve_handle = '!' + approve_handle
followers_filename = accounts_dir + '/followers.txt'
if os.path.isfile(followers_filename):
if is_a_file(followers_filename):
already_following = False
followers_str = \
@ -692,7 +693,7 @@ def store_follow_request(base_dir: str,
# should this follow be denied?
deny_follows_filename = accounts_dir + '/followrejects.txt'
if os.path.isfile(deny_follows_filename):
if is_a_file(deny_follows_filename):
if text_in_file(approve_handle, deny_follows_filename):
remove_from_follow_requests(base_dir, nickname_to_follow,
domain_to_follow, approve_handle,
@ -711,7 +712,7 @@ def store_follow_request(base_dir: str,
if group_account:
approve_handle = '!' + approve_handle
if os.path.isfile(approve_follows_filename):
if is_a_file(approve_follows_filename):
if not text_in_file(approve_handle, approve_follows_filename):
append_string(approve_handle_stored + '\n',
approve_follows_filename,
@ -778,7 +779,7 @@ def followed_account_accepts(session, base_dir: str, http_prefix: str,
follow_activity_filename = \
acct_dir(base_dir, nickname_to_follow, domain_to_follow) + \
'/requests/' + nickname + '@' + domain + '.follow'
if os.path.isfile(follow_activity_filename):
if is_a_file(follow_activity_filename):
erase_file(follow_activity_filename,
'EX: follow Accept ' +
'followed_account_accepts unable to delete ' +
@ -951,7 +952,7 @@ def send_follow_request(session, base_dir: str,
# remove follow handle from unfollowed.txt
unfollowed_filename = \
acct_dir(base_dir, nickname, domain) + '/unfollowed.txt'
if os.path.isfile(unfollowed_filename):
if is_a_file(unfollowed_filename):
if text_in_file(follow_handle, unfollowed_filename):
unfollowed_file = \
load_string(unfollowed_filename,
@ -1443,7 +1444,7 @@ def get_followers_of_actor(base_dir: str, actor: str, debug: bool) -> {}:
if debug:
print('DEBUG: examining follows of ' + account)
print(following_filename)
if os.path.isfile(following_filename):
if is_a_file(following_filename):
# does this account follow the given actor?
if debug:
print('DEBUG: checking if ' + actor_handle +
@ -1524,7 +1525,7 @@ def follower_approval_active(base_dir: str,
"""
manually_approves_followers: bool = False
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if os.path.isfile(actor_filename):
if is_a_file(actor_filename):
actor_json = load_json(actor_filename)
if actor_json:
if 'manuallyApprovesFollowers' in actor_json:
@ -1540,7 +1541,7 @@ def remove_follower(base_dir: str,
"""
followers_filename = \
acct_dir(base_dir, nickname, domain) + '/followers.txt'
if not os.path.isfile(followers_filename):
if not is_a_file(followers_filename):
return False
followers_str = \
load_string(followers_filename,
@ -1587,7 +1588,7 @@ def pending_followers_timeline_json(actor: str, base_dir: str,
follow_requests_filename = \
acct_dir(base_dir, nickname, domain) + '/followrequests.txt'
if os.path.isfile(follow_requests_filename):
if is_a_file(follow_requests_filename):
follow_requests_list: list[str] = \
load_list(follow_requests_filename,
'EX: unable to read follow requests ' +
@ -1607,7 +1608,7 @@ def pending_followers_timeline_json(actor: str, base_dir: str,
acct_dir(base_dir, nickname, domain) + \
'/requests/' + \
foll_nickname + '@' + foll_domain + '.follow'
if not os.path.isfile(follow_activity_filename):
if not is_a_file(follow_activity_filename):
continue
follow_json = load_json(follow_activity_filename)
if not follow_json:

View File

@ -7,12 +7,12 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "ActivityPub"
import os
import hashlib
from hashlib import sha256
from utils import acct_dir
from utils import get_user_paths
from data import load_string
from data import is_a_file
def remove_followers_sync(followers_sync_cache: {},
@ -35,7 +35,7 @@ def _get_followers_for_domain(base_dir: str,
"""
followers_filename = \
acct_dir(base_dir, nickname, domain) + '/followers.txt'
if not os.path.isfile(followers_filename):
if not is_a_file(followers_filename):
return []
lines: list[str] = []
foll_text: str = \
@ -63,7 +63,7 @@ def _get_followers_for_domain(base_dir: str,
possible_path + nick
filename = base_dir + '/cache/actors/' + \
url.replace('/', '#') + '.json'
if not os.path.isfile(filename):
if not is_a_file(filename):
continue
if url not in result:
result.append(url)
@ -73,7 +73,7 @@ def _get_followers_for_domain(base_dir: str,
url = prefix + '://' + search_domain + '/' + nick
filename = base_dir + '/cache/actors/' + \
url.replace('/', '#') + '.json'
if os.path.isfile(filename):
if is_a_file(filename):
if url not in result:
result.append(url)
found = True

View File

@ -7,9 +7,9 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Calendar"
import os
from data import load_string
from data import save_string
from data import is_a_file
def _data_dir2(base_dir) -> str:
@ -69,10 +69,10 @@ def receiving_calendar_events(base_dir: str, nickname: str, domain: str,
calendar_filename = \
_dir_acct(base_dir, nickname, domain) + '/followingCalendar.txt'
handle = following_nickname + '@' + following_domain
if not os.path.isfile(calendar_filename):
if not is_a_file(calendar_filename):
following_filename = \
_dir_acct(base_dir, nickname, domain) + '/following.txt'
if not os.path.isfile(following_filename):
if not is_a_file(following_filename):
return False
# create a new calendar file from the following file
following_handles = \
@ -95,7 +95,7 @@ def _receive_calendar_events(base_dir: str, nickname: str, domain: str,
domain = _port_domain_remove(domain)
following_filename = \
_dir_acct(base_dir, nickname, domain) + '/following.txt'
if not os.path.isfile(following_filename):
if not is_a_file(following_filename):
print("WARN: following.txt doesn't exist for " +
nickname + '@' + domain)
return
@ -112,7 +112,7 @@ def _receive_calendar_events(base_dir: str, nickname: str, domain: str,
# get the contents of the calendar file, which is
# a set of handles
following_handles: str = ''
if os.path.isfile(calendar_filename):
if is_a_file(calendar_filename):
print('Calendar file exists')
following_handles = \
load_string(calendar_filename,

3
git.py
View File

@ -18,6 +18,7 @@ from utils import remove_html
from utils import get_attributed_to
from utils import string_contains
from data import save_string
from data import is_a_file
def _git_format_content(content: str) -> str:
@ -41,7 +42,7 @@ def _get_git_project_name(base_dir: str, nickname: str, domain: str,
"""
git_projects_filename = \
acct_dir(base_dir, nickname, domain) + '/gitprojects.txt'
if not os.path.isfile(git_projects_filename):
if not is_a_file(git_projects_filename):
return None
subject_line_words = subject.lower().split(' ')
for word in subject_line_words:

View File

@ -42,6 +42,7 @@ from data import save_string
from data import append_string
from data import prepend_string
from data import erase_file
from data import is_a_file
def _strings_are_digits(strings_list: []) -> bool:
@ -101,7 +102,7 @@ def _remove_event_from_timeline(event_id: str,
if events_timeline:
save_string(events_timeline, tl_events_filename,
'EX: ERROR: unable to save events timeline')
elif os.path.isfile(tl_events_filename):
elif is_a_file(tl_events_filename):
erase_file(tl_events_filename,
'EX: ERROR: unable to remove events timeline')
@ -157,7 +158,7 @@ def save_event_post(base_dir: str, handle: str, post_id: str,
# save to the events timeline
tl_events_filename = handle_dir + '/events.txt'
if os.path.isfile(tl_events_filename):
if is_a_file(tl_events_filename):
_remove_event_from_timeline(event_id, tl_events_filename)
ex_str: str = \
'EX: Failed to prepend entry to events file ' + \
@ -178,7 +179,7 @@ def save_event_post(base_dir: str, handle: str, post_id: str,
'/' + str(event_month_number) + '.txt'
# Does this event post already exist within the calendar month?
if os.path.isfile(calendar_filename):
if is_a_file(calendar_filename):
if text_in_file(post_id, calendar_filename):
# Event post already exists
return False
@ -288,7 +289,7 @@ def get_todays_events(base_dir: str, nickname: str, domain: str,
acct_dir(base_dir, nickname, domain) + \
'/calendar/' + str(year) + '/' + str(month_number) + '.txt'
events = {}
if not os.path.isfile(calendar_filename):
if not is_a_file(calendar_filename):
return events
calendar_post_ids: list[str] = []
@ -614,7 +615,7 @@ def day_events_check(base_dir: str, nickname: str, domain: str,
calendar_filename = \
acct_dir(base_dir, nickname, domain) + \
'/calendar/' + str(year) + '/' + str(month_number) + '.txt'
if not os.path.isfile(calendar_filename):
if not is_a_file(calendar_filename):
return False
events_exist: bool = False
@ -673,7 +674,7 @@ def get_this_weeks_events(base_dir: str, nickname: str, domain: str) -> {}:
'/calendar/' + str(year) + '/' + str(month_number) + '.txt'
events = {}
if not os.path.isfile(calendar_filename):
if not is_a_file(calendar_filename):
return events
calendar_post_ids: list[str] = []
@ -749,7 +750,7 @@ def get_calendar_events(base_dir: str, nickname: str, domain: str,
'/calendar/' + str(year) + '/' + str(month_number) + '.txt'
events = {}
if not os.path.isfile(calendar_filename):
if not is_a_file(calendar_filename):
return events
calendar_post_ids: list[str] = []
@ -844,7 +845,7 @@ def remove_calendar_event(base_dir: str, nickname: str, domain: str,
calendar_filename = \
acct_dir(base_dir, nickname, domain) + \
'/calendar/' + str(year) + '/' + str(month_number) + '.txt'
if not os.path.isfile(calendar_filename):
if not is_a_file(calendar_filename):
return
if '/' in message_id:
message_id = message_id.replace('/', '#')

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Core"
import os
import urllib.parse
from hashlib import md5
from utils import string_contains
@ -19,6 +18,7 @@ from utils import has_object_dict
from utils import get_attributed_to
from data import load_string
from data import save_string
from data import is_a_file
def login_headers(self, file_format: str, length: int,
@ -225,7 +225,7 @@ def set_headers_etag(self, media_filename: str, file_format: str,
_set_headers_base(self, file_format, datalen, cookie, calling_domain,
permissive)
etag = None
if os.path.isfile(media_filename + '.etag'):
if is_a_file(media_filename + '.etag'):
etag = load_string(media_filename + '.etag',
'EX: _set_headers_etag ' +
'unable to read ' + media_filename + '.etag')

View File

@ -25,6 +25,7 @@ from person import set_person_notes
from data import load_string
from data import save_string
from data import erase_file
from data import is_a_file
def _establish_import_session(httpd,
@ -217,7 +218,7 @@ def run_import_following(base_dir: str, httpd):
account_dir = dir_str + '/' + account
import_filename = account_dir + '/import_following.csv'
if not os.path.isfile(import_filename):
if not is_a_file(import_filename):
continue
if not _update_import_following(base_dir, account, httpd,
import_filename):

View File

@ -144,6 +144,7 @@ from data import load_string
from data import append_string
from data import prepend_string
from data import erase_file
from data import is_a_file
def _store_last_post_id(base_dir: str, nickname: str, domain: str,
@ -256,7 +257,7 @@ def valid_inbox(base_dir: str, nickname: str, domain: str) -> bool:
for subdir, _, files in os.walk(inbox_dir):
for fname in files:
filename = os.path.join(subdir, fname)
if not os.path.isfile(filename):
if not is_a_file(filename):
print('filename: ' + filename)
return False
if text_in_file('postNickname', filename):
@ -283,7 +284,7 @@ def valid_inbox_filenames(base_dir: str, nickname: str, domain: str,
for fname in files:
filename = os.path.join(subdir, fname)
ctr += 1
if not os.path.isfile(filename):
if not is_a_file(filename):
print('filename: ' + filename)
return False
if expected_str in filename:
@ -417,8 +418,8 @@ def _deny_non_follower(base_dir: str, nickname: str, domain: str,
# has this account specified to only receive replies from followers?
account_dir = acct_dir(base_dir, nickname, domain)
if not os.path.isfile(account_dir + '/.repliesFromFollowersOnly'):
if not os.path.isfile(account_dir + '/.repliesFromMutualsOnly'):
if not is_a_file(account_dir + '/.repliesFromFollowersOnly'):
if not is_a_file(account_dir + '/.repliesFromMutualsOnly'):
return False
# is the sending actor a follower?
@ -427,7 +428,7 @@ def _deny_non_follower(base_dir: str, nickname: str, domain: str,
if not is_follower_of_person(base_dir, nickname, domain,
follower_nickname, follower_domain):
return True
if os.path.isfile(account_dir + '/.repliesFromMutualsOnly'):
if is_a_file(account_dir + '/.repliesFromMutualsOnly'):
if not is_following_actor(base_dir, nickname, domain,
sending_actor):
return True
@ -996,7 +997,7 @@ def populate_replies(base_dir: str, http_prefix: str, domain: str,
# populate a text file containing the ids of replies
post_replies_filename = post_filename.replace('.json', '.replies')
message_id = remove_id_ending(message_json['id'])
if os.path.isfile(post_replies_filename):
if is_a_file(post_replies_filename):
num_lines = lines_in_file(post_replies_filename)
if num_lines > max_replies:
return False
@ -1079,7 +1080,7 @@ def _dm_notify(base_dir: str, handle: str, url: str) -> None:
if not os.path.isdir(account_dir):
return
dm_file = account_dir + '/.newDM'
if not os.path.isfile(dm_file):
if not is_a_file(dm_file):
save_string(url, dm_file, 'EX: _dm_notify unable to write ' + dm_file)
@ -1092,7 +1093,7 @@ def _notify_post_arrival(base_dir: str, handle: str, url: str) -> None:
if not os.path.isdir(account_dir):
return
notify_file = account_dir + '/.newNotifiedPost'
if os.path.isfile(notify_file):
if is_a_file(notify_file):
# check that the same notification is not repeatedly sent
existing_notification_message = \
load_string(notify_file,
@ -1112,7 +1113,7 @@ def _reply_notify(base_dir: str, handle: str, url: str) -> None:
if not os.path.isdir(account_dir):
return
reply_file = account_dir + '/.newReply'
if not os.path.isfile(reply_file):
if not is_a_file(reply_file):
save_string(url, reply_file,
'EX: _reply_notify unable to write ' + reply_file)
@ -1135,7 +1136,7 @@ def _group_handle(base_dir: str, handle: str) -> bool:
"""Is the given account handle a group?
"""
actor_file = acct_handle_dir(base_dir, handle) + '.json'
if not os.path.isfile(actor_file):
if not is_a_file(actor_file):
return False
actor_json = load_json(actor_file)
if not actor_json:
@ -1178,7 +1179,7 @@ def _send_to_group_members(server, session, session_onion,
shared_items_federated_domains.append(domain_str)
followers_file = acct_handle_dir(base_dir, handle) + '/followers.txt'
if not os.path.isfile(followers_file):
if not is_a_file(followers_file):
return
if not post_json_object.get('to'):
return
@ -1336,7 +1337,7 @@ def _update_last_seen(base_dir: str, handle: str, actor: str) -> None:
curr_time = date_utcnow()
days_since_epoch = (curr_time - date_epoch()).days
# has the value changed?
if os.path.isfile(last_seen_filename):
if is_a_file(last_seen_filename):
days_since_epoch_file = \
load_string(last_seen_filename,
'EX: _update_last_seen unable to read ' +
@ -1495,7 +1496,7 @@ def _is_valid_dm(base_dir: str, nickname: str, domain: str, port: int,
# check for the flag file which indicates to
# only receive DMs from people you are following
follow_dms_filename = acct_dir(base_dir, nickname, domain) + '/.followDMs'
if not os.path.isfile(follow_dms_filename):
if not is_a_file(follow_dms_filename):
# dm index will be updated
update_index_list.append('dm')
act_url = local_actor_url(http_prefix, nickname, domain)
@ -1527,7 +1528,7 @@ def _is_valid_dm(base_dir: str, nickname: str, domain: str, port: int,
# check that the following file exists
if not sending_to_self:
if not os.path.isfile(following_filename):
if not is_a_file(following_filename):
print('No following.txt file exists for ' +
nickname + '@' + domain +
' so not accepting DM from ' +
@ -1795,7 +1796,7 @@ def _former_representations_to_edits(base_dir: str,
post_history_filename = post_filename.replace('.json', '.edits')
post_history_json = {}
if os.path.isfile(post_history_filename):
if is_a_file(post_history_filename):
post_history_json = load_json(post_history_filename)
# check each former post and add it to the edits file if needed
@ -2302,7 +2303,7 @@ def _inbox_after_initial(server, inbox_start_time,
print('copy queue file from ' + queue_filename +
' to ' + destination_filename)
if os.path.isfile(destination_filename):
if is_a_file(destination_filename):
return True
if message_json.get('postNickname'):
@ -2470,7 +2471,7 @@ def _inbox_after_initial(server, inbox_start_time,
show_vote_posts: bool = True
show_vote_file = acct_dir(base_dir, nickname, domain) + '/.noVotes'
if os.path.isfile(show_vote_file):
if is_a_file(show_vote_file):
show_vote_posts = False
if is_image_media(session, base_dir, http_prefix,
@ -2590,14 +2591,14 @@ def _inbox_after_initial(server, inbox_start_time,
edits_filename = \
destination_filename.replace('.json', '.edits')
modified = edited_json['object']['published']
if os.path.isfile(edits_filename):
if is_a_file(edits_filename):
edits_json = load_json(edits_filename)
if edits_json:
if not edits_json.get(modified):
edits_json[modified] = edited_json
save_json(edits_json, edits_filename)
else:
if os.path.isfile(prev_edits_filename):
if is_a_file(prev_edits_filename):
if prev_edits_filename != edits_filename:
try:
copyfile(prev_edits_filename, edits_filename)
@ -2785,7 +2786,7 @@ def _inbox_after_initial(server, inbox_start_time,
inbox_start_time = time.time()
# if the post wasn't saved
if not os.path.isfile(destination_filename):
if not is_a_file(destination_filename):
if debug:
print("Inbox post was not saved " + destination_filename)
return False
@ -3035,7 +3036,7 @@ def _check_json_signature(base_dir: str, queue_json: {}) -> (bool, bool):
print('unrecognized @context: ' + unknown_context)
already_unknown: bool = False
if os.path.isfile(unknown_contexts_file):
if is_a_file(unknown_contexts_file):
if text_in_file(unknown_context, unknown_contexts_file):
already_unknown = True
@ -3050,7 +3051,7 @@ def _check_json_signature(base_dir: str, queue_json: {}) -> (bool, bool):
data_dir(base_dir) + '/unknownJsonSignatures.txt'
already_unknown: bool = False
if os.path.isfile(unknown_signatures_file):
if is_a_file(unknown_signatures_file):
if text_in_file(jwebsig_type, unknown_signatures_file):
already_unknown = True
@ -3325,7 +3326,7 @@ def _receive_follow_request(session, session_onion, session_i2p,
print('Updating followers file: ' +
followers_filename + ' adding ' + approve_handle)
if os.path.isfile(followers_filename):
if is_a_file(followers_filename):
if not text_in_file(approve_handle, followers_filename):
group_account = \
has_group_type(base_dir,
@ -3547,7 +3548,7 @@ def run_inbox_queue(server,
# oldest item first
queue.sort()
queue_filename = queue[0]
if not os.path.isfile(queue_filename):
if not is_a_file(queue_filename):
print("Queue: queue item rejected because it has no file: " +
queue_filename)
if queue:
@ -3569,7 +3570,7 @@ def run_inbox_queue(server,
if queue:
queue.pop(0)
# delete the queue file
if os.path.isfile(queue_filename):
if is_a_file(queue_filename):
ex_text = \
'EX: run_inbox_queue 1 unable to delete ' + \
str(queue_filename)
@ -3660,7 +3661,7 @@ def run_inbox_queue(server,
# blocking based upon nickname
sender_nickname = get_nickname_from_actor(queue_json['actor'])
if evil_nickname(sender_nickname):
if os.path.isfile(queue_filename):
if is_a_file(queue_filename):
ex_text = \
'EX: run_inbox_queue 11 unable to delete ' + \
str(queue_filename)
@ -3736,7 +3737,7 @@ def run_inbox_queue(server,
if not pub_key:
if debug:
print('Queue: public key could not be obtained from ' + key_id)
if os.path.isfile(queue_filename):
if is_a_file(queue_filename):
ex_text = \
'EX: run_inbox_queue 2 unable to delete ' + \
str(queue_filename)
@ -3795,7 +3796,7 @@ def run_inbox_queue(server,
key_id + ' ' + str(original_json))
if http_signature_failed or verify_all_signatures:
if os.path.isfile(queue_filename):
if is_a_file(queue_filename):
ex_text = \
'EX: run_inbox_queue 3 unable to delete ' + \
str(queue_filename)
@ -3816,7 +3817,7 @@ def run_inbox_queue(server,
else:
print('WARN: jsonld inbox signature check failed ' +
key_id)
if os.path.isfile(queue_filename):
if is_a_file(queue_filename):
ex_text = \
'EX: run_inbox_queue 4 unable to delete ' + \
str(queue_filename)
@ -3840,7 +3841,7 @@ def run_inbox_queue(server,
inbox_start_time = time.time()
dogwhistles_filename = data_dir(base_dir) + '/dogwhistles.txt'
if not os.path.isfile(dogwhistles_filename):
if not is_a_file(dogwhistles_filename):
dogwhistles_filename = base_dir + '/default_dogwhistles.txt'
dogwhistles = load_dogwhistles(dogwhistles_filename)
@ -4052,7 +4053,7 @@ def run_inbox_queue(server,
if len(recipients_dict_followers.items()) > 0:
shared_inbox_post_filename = \
curr_destination.replace(inbox_handle, inbox_handle)
if not os.path.isfile(shared_inbox_post_filename):
if not is_a_file(shared_inbox_post_filename):
save_json(curr_post_json, shared_inbox_post_filename)
fitness_performance(inbox_start_time, server.fitness,
'INBOX', 'shared_inbox_save',
@ -4078,7 +4079,7 @@ def run_inbox_queue(server,
bold_reading: bool = False
bold_reading_filename = \
acct_handle_dir(base_dir, handle) + '/.boldReading'
if os.path.isfile(bold_reading_filename):
if is_a_file(bold_reading_filename):
bold_reading = True
_inbox_after_initial(server, inbox_start_time,
recent_posts_cache,
@ -4128,7 +4129,7 @@ def run_inbox_queue(server,
# should the current queue item be removed?
if remove_queue_item:
if os.path.isfile(queue_filename):
if is_a_file(queue_filename):
ex_text = \
'EX: run_inbox_queue 10 unable to delete ' + \
str(queue_filename)

View File

@ -92,6 +92,7 @@ from data import append_string
from data import prepend_string
from data import load_string
from data import erase_file
from data import is_a_file
def inbox_update_index(boxname: str, base_dir: str, handle: str,
@ -113,7 +114,7 @@ def inbox_update_index(boxname: str, base_dir: str, handle: str,
destination_filename = destination_filename.split('/')[-1]
written: bool = False
if os.path.isfile(index_filename):
if is_a_file(index_filename):
if prepend_string(destination_filename, index_filename,
'EX: Failed to prepend entry to index [ex]'):
written = True
@ -139,7 +140,7 @@ def _notify_moved(base_dir: str, domain_full: str,
continue
account_dir = dir_str + '/' + account
following_filename = account_dir + '/following.txt'
if not os.path.isfile(following_filename):
if not is_a_file(following_filename):
continue
if not text_in_file(prev_actor_handle + '\n', following_filename):
continue
@ -147,7 +148,7 @@ def _notify_moved(base_dir: str, domain_full: str,
continue
# notify
moved_file = account_dir + '/.newMoved'
if os.path.isfile(moved_file):
if is_a_file(moved_file):
if not text_in_file('##sent##', moved_file):
continue
@ -158,7 +159,7 @@ def _notify_moved(base_dir: str, domain_full: str,
moved_str = \
prev_actor_handle + ' ' + new_actor_handle + ' ' + url
if os.path.isfile(moved_file):
if is_a_file(moved_file):
prev_moved_str = \
load_string(moved_file,
'EX: _notify_moved unable to read ' +
@ -228,7 +229,7 @@ def _person_receive_update(base_dir: str,
print('WARN: Public key does not match when updating actor')
return False
else:
if os.path.isfile(actor_filename):
if is_a_file(actor_filename):
existing_person_json = load_json(actor_filename)
if existing_person_json:
existing_pub_key, _ = \
@ -274,7 +275,7 @@ def _person_receive_update(base_dir: str,
refollow_str: str = ''
refollow_filename = data_dir(base_dir) + '/actors_moved.txt'
refollow_file_exists: bool = False
if os.path.isfile(refollow_filename):
if is_a_file(refollow_filename):
refollow_str = \
load_string(refollow_filename,
'EX: _person_receive_update unable to read ' +
@ -352,7 +353,7 @@ def _receive_update_to_question(recent_posts_cache: {}, message_json: {},
cached_post_filename = \
get_cached_post_filename(base_dir, nickname, domain, message_json)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
erase_file(cached_post_filename,
'EX: _receive_update_to_question unable to delete ' +
cached_post_filename)
@ -457,7 +458,7 @@ def receive_edit_to_post(recent_posts_cache: {}, message_json: {},
# save the edit history to file
post_history_filename = post_filename.replace('.json', '') + '.edits'
post_history_json = {}
if os.path.isfile(post_history_filename):
if is_a_file(post_history_filename):
post_history_json = load_json(post_history_filename)
# get the updated or published date
if post_json_object['object'].get('updated'):
@ -475,14 +476,14 @@ def receive_edit_to_post(recent_posts_cache: {}, message_json: {},
# (eg. edited reminder)
if '/outbox/' in post_filename:
inbox_post_filename = post_filename.replace('/outbox/', '/inbox/')
if os.path.isfile(inbox_post_filename):
if is_a_file(inbox_post_filename):
save_json(message_json, inbox_post_filename)
# ensure that the cached post is removed if it exists, so
# that it then will be recreated
cached_post_filename = \
get_cached_post_filename(base_dir, nickname, domain, message_json)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
erase_file(cached_post_filename,
'EX: _receive_edit_to_post unable to delete ' +
cached_post_filename)
@ -499,12 +500,12 @@ def receive_edit_to_post(recent_posts_cache: {}, message_json: {},
not_dm = not is_dm(message_json)
timezone = get_account_timezone(base_dir, nickname, domain)
mitm: bool = False
if os.path.isfile(post_filename.replace('.json', '') + '.mitm'):
if is_a_file(post_filename.replace('.json', '') + '.mitm'):
mitm = True
bold_reading: bool = False
bold_reading_filename = \
acct_dir(base_dir, nickname, domain) + '/.boldReading'
if os.path.isfile(bold_reading_filename):
if is_a_file(bold_reading_filename):
bold_reading = True
timezone = get_account_timezone(base_dir, nickname, domain)
lists_enabled = get_config_param(base_dir, "listsEnabled")
@ -863,11 +864,11 @@ def _like_notify(base_dir: str, domain: str,
# are like notifications enabled?
notify_likes_enabled_filename = account_dir + '/.notifyLikes'
if not os.path.isfile(notify_likes_enabled_filename):
if not is_a_file(notify_likes_enabled_filename):
return
like_file = account_dir + '/.newLike'
if os.path.isfile(like_file):
if is_a_file(like_file):
if not text_in_file('##sent##', like_file):
return
@ -885,7 +886,7 @@ def _like_notify(base_dir: str, domain: str,
like_str = liker_handle + ' ' + url + '?likedBy=' + actor
prev_like_file = account_dir + '/.prevLike'
# was there a previous like notification?
if os.path.isfile(prev_like_file):
if is_a_file(prev_like_file):
# is it the same as the current notification ?
prev_like_str = \
load_string(prev_like_file,
@ -922,11 +923,11 @@ def _reaction_notify(base_dir: str, domain: str, onion_domain: str,
# are reaction notifications enabled?
notify_reaction_enabled_filename = account_dir + '/.notifyReactions'
if not os.path.isfile(notify_reaction_enabled_filename):
if not is_a_file(notify_reaction_enabled_filename):
return
reaction_file = account_dir + '/.newReaction'
if os.path.isfile(reaction_file):
if is_a_file(reaction_file):
if not text_in_file('##sent##', reaction_file):
return
@ -945,7 +946,7 @@ def _reaction_notify(base_dir: str, domain: str, onion_domain: str,
';emoj=' + emoji_content
prev_reaction_file = account_dir + '/.prevReaction'
# was there a previous reaction notification?
if os.path.isfile(prev_reaction_file):
if is_a_file(prev_reaction_file):
# is it the same as the current notification ?
prev_reaction_str = \
load_string(prev_reaction_file,
@ -1081,7 +1082,7 @@ def receive_like(recent_posts_cache: {},
timezone = get_account_timezone(base_dir, handle_name, domain)
mitm: bool = False
test_filename = post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(test_filename):
if is_a_file(test_filename):
mitm = True
minimize_all_images: bool = False
if handle_name in min_images_for_accounts:
@ -1242,7 +1243,7 @@ def receive_reaction(recent_posts_cache: {},
handle_dir = acct_handle_dir(base_dir, handle)
if not os.path.isdir(handle_dir):
print('DEBUG: unknown recipient of emoji reaction - ' + handle)
if os.path.isfile(handle_dir + '/.hideReactionButton'):
if is_a_file(handle_dir + '/.hideReactionButton'):
print('Emoji reaction rejected by ' + handle +
' due to their settings')
return True
@ -1332,7 +1333,7 @@ def receive_reaction(recent_posts_cache: {},
timezone = get_account_timezone(base_dir, handle_name, domain)
mitm: bool = False
test_filename = post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(test_filename):
if is_a_file(test_filename):
mitm = True
minimize_all_images: bool = False
if handle_name in min_images_for_accounts:
@ -1455,7 +1456,7 @@ def receive_zot_reaction(recent_posts_cache: {},
handle_dir = acct_handle_dir(base_dir, handle)
if not os.path.isdir(handle_dir):
print('DEBUG: unknown recipient of zot emoji reaction - ' + handle)
if os.path.isfile(handle_dir + '/.hideReactionButton'):
if is_a_file(handle_dir + '/.hideReactionButton'):
print('Zot emoji reaction rejected by ' + handle +
' due to their settings')
return True
@ -1532,7 +1533,7 @@ def receive_zot_reaction(recent_posts_cache: {},
timezone = get_account_timezone(base_dir, handle_name, domain)
mitm: bool = False
test_filename = post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(test_filename):
if is_a_file(test_filename):
mitm = True
minimize_all_images: bool = False
if handle_name in min_images_for_accounts:
@ -1675,7 +1676,7 @@ def receive_bookmark(recent_posts_cache: {},
timezone = get_account_timezone(base_dir, nickname, domain)
mitm: bool = False
test_filename = post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(test_filename):
if is_a_file(test_filename):
mitm = True
minimize_all_images: bool = False
if nickname in min_images_for_accounts:
@ -2000,7 +2001,7 @@ def receive_announce(recent_posts_cache: {},
show_vote_posts = True
show_vote_file = acct_dir(base_dir, nickname, domain) + '/.noVotes'
if os.path.isfile(show_vote_file):
if is_a_file(show_vote_file):
show_vote_posts = False
# get the list of mutuals for the current account
@ -2072,7 +2073,7 @@ def receive_announce(recent_posts_cache: {},
if post_json_object['object'].get('inReplyTo'):
account_dir = acct_dir(base_dir, nickname, domain)
no_reply_boosts_filename = account_dir + '/.noReplyBoosts'
if os.path.isfile(no_reply_boosts_filename):
if is_a_file(no_reply_boosts_filename):
post_json_object = None
announce_denied = True
@ -2087,7 +2088,7 @@ def receive_announce(recent_posts_cache: {},
if onion_domain in announce_url:
not_in_onion = False
if domain not in announce_url and not_in_onion:
if os.path.isfile(post_filename):
if is_a_file(post_filename):
# if the announce can't be downloaded then remove it
ex_text = \
'EX: _receive_announce unable to delete ' + \
@ -2122,7 +2123,7 @@ def receive_announce(recent_posts_cache: {},
lookup_actor = get_actor_from_post_id(lookup_actor)
if lookup_actor:
if is_recent_post(post_json_object, 3):
if not os.path.isfile(post_filename + '.tts'):
if not is_a_file(post_filename + '.tts'):
domain_full = get_full_domain(domain, port)
update_speaker(base_dir, http_prefix,
nickname, domain, domain_full,
@ -2212,7 +2213,7 @@ def receive_question_vote(server, base_dir: str, nickname: str, domain: str,
cached_post_filename = \
get_cached_post_filename(base_dir, nickname, domain, question_json)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
erase_file(cached_post_filename,
'EX: replytoQuestion unable to delete ' +
cached_post_filename)
@ -2226,7 +2227,7 @@ def receive_question_vote(server, base_dir: str, nickname: str, domain: str,
timezone = get_account_timezone(base_dir, nickname, domain)
mitm: bool = False
test_filename = question_post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(test_filename):
if is_a_file(test_filename):
mitm = True
minimize_all_images: bool = False
if nickname in min_images_for_accounts:

View File

@ -37,6 +37,7 @@ from bookmarks import undo_bookmarks_collection_entry
from webapp_post import individual_post_as_html
from reaction import undo_reaction_collection_entry
from data import erase_file
from data import is_a_file
def _receive_undo_follow(base_dir: str, message_json: {},
@ -267,7 +268,7 @@ def receive_undo_like(recent_posts_cache: {},
timezone = get_account_timezone(base_dir, handle_name, domain)
mitm: bool = False
test_filename = post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(test_filename):
if is_a_file(test_filename):
mitm = True
minimize_all_images: bool = False
if handle_name in min_images_for_accounts:
@ -426,7 +427,7 @@ def receive_undo_reaction(recent_posts_cache: {},
timezone = get_account_timezone(base_dir, handle_name, domain)
mitm: bool = False
test_filename = post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(test_filename):
if is_a_file(test_filename):
mitm = True
minimize_all_images: bool = False
if handle_name in min_images_for_accounts:
@ -571,7 +572,7 @@ def receive_undo_bookmark(recent_posts_cache: {},
timezone = get_account_timezone(base_dir, nickname, domain)
mitm: bool = False
test_filename = post_filename.replace('.json', '') + '.mitm'
if os.path.isfile(test_filename):
if is_a_file(test_filename):
mitm = True
minimize_all_images: bool = False
if nickname in min_images_for_accounts:
@ -655,7 +656,7 @@ def receive_undo_announce(recent_posts_cache: {},
return False
undo_announce_collection_entry(recent_posts_cache, base_dir, post_filename,
actor_url, domain, debug)
if os.path.isfile(post_filename):
if is_a_file(post_filename):
ex_text = \
'EX: _receive_undo_announce unable to delete ' + \
str(post_filename)

View File

@ -7,8 +7,8 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "ActivityPub"
import os
from data import load_string
from data import is_a_file
def _get_local_private_key(base_dir: str, nickname: str, domain: str) -> str:
@ -18,7 +18,7 @@ def _get_local_private_key(base_dir: str, nickname: str, domain: str) -> str:
return None
handle = nickname + '@' + domain
key_filename = base_dir + '/keys/private/' + handle.lower() + '.key'
if not os.path.isfile(key_filename):
if not is_a_file(key_filename):
return None
text = load_string(key_filename,
'EX: _get_local_private_key unable to read ' +
@ -35,7 +35,7 @@ def _get_local_public_key(base_dir: str, nickname: str, domain: str) -> str:
return None
handle = nickname + '@' + domain
key_filename = base_dir + '/keys/public/' + handle.lower() + '.key'
if not os.path.isfile(key_filename):
if not is_a_file(key_filename):
return None
text = load_string(key_filename,
'EX: _get_local_public_key unable to read ' +

View File

@ -22,6 +22,7 @@ from utils import resembles_url
from cache import get_person_from_cache
from data import load_string
from data import save_string
from data import is_a_file
def get_actor_languages(actor_json: {}) -> str:
@ -375,7 +376,7 @@ def load_default_post_languages(base_dir: str) -> {}:
domain = handle.split('@')[1]
default_post_language_filename = \
acct_dir(base_dir, nickname, domain) + '/.new_post_language'
if not os.path.isfile(default_post_language_filename):
if not is_a_file(default_post_language_filename):
continue
text = load_string(default_post_language_filename,
'EX: Unable to read default post language ' +
@ -397,7 +398,7 @@ def get_reply_language(base_dir: str,
return None
for lang, _ in post_obj['contentMap'].items():
lang_filename = base_dir + '/translations/' + lang + '.json'
if not os.path.isfile(lang_filename):
if not is_a_file(lang_filename):
continue
return lang
return None

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "ActivityPub"
import os
from pprint import pprint
from flags import has_group_type
from flags import url_permitted
@ -34,6 +33,7 @@ from webfinger import webfinger_handle
from auth import create_basic_auth_header
from posts import get_person_box
from data import erase_file
from data import is_a_file
def no_of_likes(post_json_object: {}) -> int:
@ -471,7 +471,7 @@ def update_likes_collection(recent_posts_cache: {},
get_cached_post_filename(base_dir, nickname,
domain, post_json_object)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
erase_file(cached_post_filename,
'EX: update_likes_collection unable to delete ' +
cached_post_filename)
@ -549,7 +549,7 @@ def undo_likes_collection_entry(recent_posts_cache: {},
get_cached_post_filename(base_dir, nickname,
domain, post_json_object)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
ex_text = \
'EX: undo_likes_collection_entry ' + \
'unable to delete cached post ' + \

View File

@ -8,13 +8,13 @@ __status__ = "Production"
__module_group__ = "Profile Metadata"
import os
import pyqrcode
from utils import get_attachment_property_value
from utils import acct_dir
from utils import load_json
from utils import string_contains
from data import erase_file
from data import is_a_file
VALID_LXMF_CHARS = set('0123456789abcdefghijklmnopqrstuvwxyz')
@ -38,11 +38,11 @@ def save_lxmf_qrcode(base_dir: str,
This helps to transfer onion or i2p handles to a mobile device
"""
qrcode_filename = acct_dir(base_dir, nickname, domain) + '/qrcode_lxmf.png'
if os.path.isfile(qrcode_filename):
if is_a_file(qrcode_filename):
return False
actor_filename = \
acct_dir(base_dir, nickname, domain) + '.json'
if not os.path.isfile(actor_filename):
if not is_a_file(actor_filename):
return False
actor_json = load_json(actor_filename)
if not actor_json:
@ -111,7 +111,7 @@ def set_lxmf_address(base_dir: str, nickname: str, domain: str,
if not lxmf_address:
qrcode_filename = \
acct_dir(base_dir, nickname, domain) + '/qrcode_lxmf.png'
if os.path.isfile(qrcode_filename):
if is_a_file(qrcode_filename):
erase_file(qrcode_filename,
'EX: cannot remove lxmf qrcode ' + qrcode_filename)

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "ActivityPub"
import os
from follow import followed_account_accepts
from follow import followed_account_rejects
from follow import remove_from_follow_requests
@ -31,6 +30,7 @@ from data import prepend_string
from data import load_list
from data import erase_file
from data import move_file
from data import is_a_file
def manual_deny_follow_request2(session, session_onion, session_i2p,
@ -56,7 +56,7 @@ def manual_deny_follow_request2(session, session_onion, session_i2p,
# has this handle already been rejected?
rejected_follows_filename = accounts_dir + '/followrejects.txt'
if os.path.isfile(rejected_follows_filename):
if is_a_file(rejected_follows_filename):
if text_in_file(deny_handle, rejected_follows_filename):
remove_from_follow_requests(base_dir, nickname, domain,
deny_handle, debug)
@ -145,7 +145,7 @@ def _approve_follower_handle(account_dir: str, approve_handle: str) -> None:
re-follow later then they don't need to be manually approved again
"""
approved_filename = account_dir + '/approved.txt'
if os.path.isfile(approved_filename):
if is_a_file(approved_filename):
if not text_in_file(approve_handle, approved_filename):
append_string(approve_handle + '\n', approved_filename,
'EX: _approve_follower_handle unable to append ' +
@ -182,7 +182,7 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
' approving follow request from ' + approve_handle)
account_dir = acct_handle_dir(base_dir, handle)
approve_follows_filename = account_dir + '/followrequests.txt'
if not os.path.isfile(approve_follows_filename):
if not is_a_file(approve_follows_filename):
print('Manual follow accept: follow requests file ' +
approve_follows_filename + ' not found')
return
@ -257,7 +257,7 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
requests_dir = account_dir + '/requests'
follow_activity_filename = \
requests_dir + '/' + handle_of_follow_requester + '.follow'
if not os.path.isfile(follow_activity_filename):
if not is_a_file(follow_activity_filename):
update_approved_followers = True
continue
follow_json = load_json(follow_activity_filename)
@ -346,7 +346,7 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
if update_approved_followers:
# update the followers
print('Manual follow accept: updating ' + followers_filename)
if os.path.isfile(followers_filename):
if is_a_file(followers_filename):
if not text_in_file(approve_handle_full, followers_filename):
prepend_string(approve_handle_full, followers_filename,
'EX: Manual follow accept. ' +
@ -376,7 +376,7 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
approve_follows_filename)
# remove the .follow file
if follow_activity_filename:
if os.path.isfile(follow_activity_filename):
if is_a_file(follow_activity_filename):
erase_file(follow_activity_filename,
'EX: manual_approve_follow_request ' +
'unable to delete ' + follow_activity_filename)

22
maps.py
View File

@ -8,7 +8,6 @@ __status__ = "Production"
__module_group__ = "Core"
import os
from flags import is_float
from utils import resembles_url
from utils import browser_supports_download_filename
@ -26,6 +25,7 @@ from timeFunctions import date_utcnow
from session import get_resolved_url
from data import load_string
from data import save_string
from data import is_a_file
def geocoords_to_osm_link(osm_domain: str, zoom: int,
@ -200,7 +200,7 @@ def html_address_book_list(base_dir: str, nickname: str, domain: str) -> str:
address_book_filename = \
acct_dir(base_dir, nickname, domain) + '/addresses.json'
address_book_dict = {}
if os.path.isfile(address_book_filename):
if is_a_file(address_book_filename):
address_book_dict2 = load_json(address_book_filename)
if address_book_dict2:
address_book_dict = address_book_dict2
@ -225,7 +225,7 @@ def update_address_book(base_dir: str, nickname: str, domain: str,
address_book_filename = \
acct_dir(base_dir, nickname, domain) + '/addresses.json'
address_book_dict = {}
if os.path.isfile(address_book_filename):
if is_a_file(address_book_filename):
address_book_dict2 = load_json(address_book_filename)
if address_book_dict2:
address_book_dict = address_book_dict2
@ -900,7 +900,7 @@ def set_map_preferences_url(base_dir: str, nickname: str, domain: str,
"""
maps_filename = \
acct_dir(base_dir, nickname, domain) + '/map_preferences.json'
if os.path.isfile(maps_filename):
if is_a_file(maps_filename):
maps_json = load_json(maps_filename)
maps_json['url'] = maps_website_url
else:
@ -915,7 +915,7 @@ def get_map_preferences_url(base_dir: str, nickname: str, domain: str) -> str:
"""
maps_filename = \
acct_dir(base_dir, nickname, domain) + '/map_preferences.json'
if os.path.isfile(maps_filename):
if is_a_file(maps_filename):
maps_json = load_json(maps_filename)
if maps_json.get('url'):
url_str = get_url_from_post(maps_json['url'])
@ -930,7 +930,7 @@ def set_map_preferences_coords(base_dir: str, nickname: str, domain: str,
"""
maps_filename = \
acct_dir(base_dir, nickname, domain) + '/map_preferences.json'
if os.path.isfile(maps_filename):
if is_a_file(maps_filename):
maps_json = load_json(maps_filename)
maps_json['latitude'] = latitude
maps_json['longitude'] = longitude
@ -950,7 +950,7 @@ def get_map_preferences_coords(base_dir: str, nickname: str,
"""
maps_filename = \
acct_dir(base_dir, nickname, domain) + '/map_preferences.json'
if os.path.isfile(maps_filename):
if is_a_file(maps_filename):
maps_json = load_json(maps_filename)
if maps_json.get('latitude') and \
maps_json.get('longitude') and \
@ -1037,7 +1037,7 @@ def add_tag_map_links(tag_maps_dir: str, tag_name: str,
# read the existing map links
existing_map_links: list[str] = []
if os.path.isfile(tag_map_filename):
if is_a_file(tag_map_filename):
existing_map_links_str = \
load_string(tag_map_filename,
'EX: error reading tag map ' + tag_map_filename)
@ -1124,7 +1124,7 @@ def _hashtag_map_to_format(base_dir: str, tag_name: str,
map_str += '<kml xmlns="http://www.opengis.net/kml/2.2">\n'
map_str += '<Document>\n'
if os.path.isfile(tag_map_filename):
if is_a_file(tag_map_filename):
map_links: list[str] = []
map_links_str = \
load_string(tag_map_filename,
@ -1160,7 +1160,7 @@ def _hashtag_map_to_format(base_dir: str, tag_name: str,
post_filename = \
locate_post(base_dir, nickname, domain, post_id)
if post_filename:
if os.path.isfile(post_filename + '.muted'):
if is_a_file(post_filename + '.muted'):
continue
place_ctr += 1
if map_format == 'gpx':
@ -1258,7 +1258,7 @@ def html_hashtag_maps(base_dir: str, tag_name: str,
"""Returns html for maps associated with a hashtag
"""
tag_map_filename = base_dir + '/tagmaps/' + tag_name + '.txt'
if not os.path.isfile(tag_map_filename):
if not is_a_file(tag_map_filename):
return ''
time_period = _get_tagmaps_time_periods()

View File

@ -23,6 +23,7 @@ from utils import account_is_indexable
from utils import is_yggdrasil_address
from data import load_list
from data import load_string
from data import is_a_file
def _meta_data_instance_v1(show_accounts: bool,
@ -37,7 +38,7 @@ def _meta_data_instance_v1(show_accounts: bool,
"""
admin_actor_filename = \
data_dir(base_dir) + '/' + admin_nickname + '@' + domain + '.json'
if not os.path.isfile(admin_actor_filename):
if not is_a_file(admin_actor_filename):
return {}
admin_actor = load_json(admin_actor_filename)
@ -47,7 +48,7 @@ def _meta_data_instance_v1(show_accounts: bool,
rules_list: list[str] = []
rules_filename = data_dir(base_dir) + '/tos.md'
if os.path.isfile(rules_filename):
if is_a_file(rules_filename):
rules_lines = load_list(rules_filename,
'EX: _meta_data_instance_v1 unable to read ' +
rules_filename)
@ -212,7 +213,7 @@ def _get_masto_api_v1account(base_dir: str, nickname: str, domain: str,
"""
account_dir = acct_dir(base_dir, nickname, domain)
account_filename = account_dir + '.json'
if not os.path.isfile(account_filename):
if not is_a_file(account_filename):
return {}
account_json = load_json(account_filename)
if not account_json:
@ -272,7 +273,7 @@ def _get_masto_api_v1account(base_dir: str, nickname: str, domain: str,
})
published_filename = \
acct_dir(base_dir, nickname, domain) + '/.last_published'
if os.path.isfile(published_filename):
if is_a_file(published_filename):
published: str = \
load_string(published_filename,
'EX: unable to read last published time 1 ' +

View File

@ -25,6 +25,7 @@ from formats import get_audio_extensions
from formats import get_video_extensions
from data import load_list
from data import load_string
from data import is_a_file
def _get_masto_api_v2id_from_nickname(nickname: str) -> int:
@ -44,7 +45,7 @@ def _meta_data_instance_v2(show_accounts: bool,
"""
account_dir = data_dir(base_dir) + '/' + admin_nickname + '@' + domain
admin_actor_filename = account_dir + '.json'
if not os.path.isfile(admin_actor_filename):
if not is_a_file(admin_actor_filename):
return {}
admin_actor = load_json(admin_actor_filename)
@ -54,7 +55,7 @@ def _meta_data_instance_v2(show_accounts: bool,
rules_list: list[str] = []
rules_filename = data_dir(base_dir) + '/tos.md'
if os.path.isfile(rules_filename):
if is_a_file(rules_filename):
rules_lines: list[str] = \
load_list(rules_filename,
'EX: _meta_data_instance_v2 unable to read rules')
@ -118,7 +119,7 @@ def _meta_data_instance_v2(show_accounts: bool,
published = None
published_filename = \
acct_dir(base_dir, admin_nickname, domain) + '/.last_published'
if os.path.isfile(published_filename):
if is_a_file(published_filename):
published = \
load_string(published_filename,
'EX: _meta_data_instance_v2 ' +

View File

@ -37,6 +37,7 @@ from data import load_string
from data import append_string
from data import erase_file
from data import move_file
from data import is_a_file
# music file ID3 v1 genres
@ -308,14 +309,14 @@ def _remove_meta_data(image_filename: str, output_filename: str) -> None:
so better to use a dedicated tool if one is installed
"""
copyfile(image_filename, output_filename)
if not os.path.isfile(output_filename):
if not is_a_file(output_filename):
print('ERROR: unable to remove metadata from ' + image_filename)
return
if os.path.isfile('/usr/bin/exiftool'):
if is_a_file('/usr/bin/exiftool'):
print('Removing metadata from ' + output_filename + ' using exiftool')
cmd = 'exiftool -all= ' + safe_system_string(output_filename)
os.system(cmd) # nosec
elif os.path.isfile('/usr/bin/mogrify'):
elif is_a_file('/usr/bin/mogrify'):
print('Removing metadata from ' + output_filename + ' using mogrify')
cmd = \
'/usr/bin/mogrify -strip ' + safe_system_string(output_filename)
@ -328,14 +329,14 @@ def _spoof_meta_data(base_dir: str, nickname: str, domain: str,
exif_json: list[dict]) -> None:
"""Spoof image metadata using a decoy model for a given city
"""
if not os.path.isfile(output_filename):
if not is_a_file(output_filename):
print('ERROR: unable to spoof metadata within ' + output_filename)
return
# get the random seed used to generate a unique pattern for this account
decoy_seed_filename = acct_dir(base_dir, nickname, domain) + '/decoyseed'
decoy_seed = 63725
if os.path.isfile(decoy_seed_filename):
if is_a_file(decoy_seed_filename):
decoy_seed_str = \
load_string(decoy_seed_filename,
'EX: _spoof_meta_data unable to read ' +
@ -349,7 +350,7 @@ def _spoof_meta_data(base_dir: str, nickname: str, domain: str,
'EX: _spoof_meta_data unable to write ' +
decoy_seed_filename)
if os.path.isfile('/usr/bin/exiftool'):
if is_a_file('/usr/bin/exiftool'):
print('Spoofing metadata in ' + output_filename + ' using exiftool')
curr_time_adjusted = \
date_utcnow() - \
@ -476,7 +477,7 @@ def convert_image_to_low_bandwidth(image_filename: str) -> None:
"""Converts an image to a low bandwidth version
"""
low_bandwidth_filename = image_filename + '.low'
if os.path.isfile(low_bandwidth_filename):
if is_a_file(low_bandwidth_filename):
erase_file(low_bandwidth_filename,
'EX: convert_image_to_low_bandwidth unable to delete ' +
low_bandwidth_filename)
@ -490,14 +491,14 @@ def convert_image_to_low_bandwidth(image_filename: str) -> None:
subprocess.call(cmd, shell=True)
# wait for conversion to happen
ctr: int = 0
while not os.path.isfile(low_bandwidth_filename):
while not is_a_file(low_bandwidth_filename):
print('Waiting for low bandwidth image conversion ' + str(ctr))
time.sleep(0.2)
ctr += 1
if ctr > 100:
print('WARN: timed out waiting for low bandwidth image conversion')
break
if os.path.isfile(low_bandwidth_filename):
if is_a_file(low_bandwidth_filename):
erase_file(image_filename,
'EX: convert_image_to_low_bandwidth unable to delete ' +
image_filename)
@ -505,7 +506,7 @@ def convert_image_to_low_bandwidth(image_filename: str) -> None:
'EX: convert_image_to_low_bandwidth could not rename ' +
low_bandwidth_filename + ' -> ' + image_filename)
if os.path.isfile(image_filename):
if is_a_file(image_filename):
print('Image converted to low bandwidth ' + image_filename)
else:
print('Low bandwidth converted image not found: ' +
@ -530,7 +531,7 @@ def process_meta_data(base_dir: str, nickname: str, domain: str,
def _is_media(image_filename: str) -> bool:
"""Is the given file a media file?
"""
if not os.path.isfile(image_filename):
if not is_a_file(image_filename):
print('WARN: Media file does not exist ' + image_filename)
return False
permitted_media = get_media_extensions()
@ -587,7 +588,7 @@ def _update_etag(media_filename: str) -> None:
return
# check that the media exists
if not os.path.isfile(media_filename):
if not is_a_file(media_filename):
return
# read the binary data
@ -631,7 +632,7 @@ def _log_uploaded_media(base_dir: str, nickname: str, domain: str,
account_media_log_filename = account_dir + '/media_log.txt'
media_log = []
write_type = 'w+'
if os.path.isfile(account_media_log_filename):
if is_a_file(account_media_log_filename):
media_log_str = \
load_string(account_media_log_filename,
'EX: unable to read media log for ' + nickname)
@ -849,23 +850,23 @@ def apply_watermark_to_image(base_dir: str, nickname: str, domain: str,
watermark_opacity: int) -> bool:
"""Applies a watermark to the given image
"""
if not os.path.isfile(post_image_filename):
if not is_a_file(post_image_filename):
return False
if not os.path.isfile('/usr/bin/composite'):
if not is_a_file('/usr/bin/composite'):
return False
watermark_enabled_filename = \
acct_dir(base_dir, nickname, domain) + '/.watermarkEnabled'
if not os.path.isfile(watermark_enabled_filename):
if not is_a_file(watermark_enabled_filename):
return False
_, watermark_filename = get_watermark_file(base_dir, nickname, domain)
if not watermark_filename:
# does a default watermark filename exist?
default_watermark_file = base_dir + '/manual/manual-watermark-ai.png'
if os.path.isfile(default_watermark_file):
if is_a_file(default_watermark_file):
watermark_filename = default_watermark_file
if not watermark_filename:
return False
if not os.path.isfile(watermark_filename):
if not is_a_file(watermark_filename):
return False
# scale the watermark so that it is a fixed percentage of the image width
@ -920,7 +921,7 @@ def apply_watermark_to_image(base_dir: str, nickname: str, domain: str,
safe_system_string(post_image_filename) + ' ' + \
safe_system_string(post_image_filename + '.watermarked')
subprocess.call(cmd, shell=True)
if not os.path.isfile(post_image_filename + '.watermarked'):
if not is_a_file(post_image_filename + '.watermarked'):
return False
if not erase_file(post_image_filename,

View File

@ -23,6 +23,7 @@ from person import get_actor_json
from data import load_list
from data import save_string
from data import append_string
from data import is_a_file
def _move_following_handles_for_account(base_dir: str,
@ -39,7 +40,7 @@ def _move_following_handles_for_account(base_dir: str,
ctr: int = 0
following_filename = \
acct_dir(base_dir, nickname, domain) + '/following.txt'
if not os.path.isfile(following_filename):
if not is_a_file(following_filename):
return ctr
following_handles = \
load_list(following_filename,
@ -155,7 +156,7 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
following_filename = \
acct_dir(base_dir, nickname, domain) + '/following.txt'
if os.path.isfile(following_filename):
if is_a_file(following_filename):
following_handles: list[str] = \
load_list(following_filename,
'EX: _update_moved_handle unable to read ' +
@ -187,7 +188,7 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
moved_to_handle)
# save the new handles to the refollow list
if os.path.isfile(refollow_filename):
if is_a_file(refollow_filename):
append_string(moved_to_handle + '\n', refollow_filename,
'EX: ' +
'_update_moved_handle unable to append ' +
@ -202,7 +203,7 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
followers_filename = \
acct_dir(base_dir, nickname, domain) + '/followers.txt'
if os.path.isfile(followers_filename):
if is_a_file(followers_filename):
follower_handles: list[str] = \
load_list(followers_filename,
'EX: _update_moved_handle unable to read ' +

View File

@ -14,10 +14,10 @@ __module_group__ = "Core"
# signature, but they can conduct surveillance and gather posts for LLM
# training (or sale for that purpose).
import os
from utils import data_dir
from data import load_string
from data import save_string
from data import is_a_file
def detect_mitm(self) -> bool:
@ -56,7 +56,7 @@ def load_mitm_servers(base_dir: str) -> []:
"""
mitm_servers_filename = data_dir(base_dir) + '/mitm_servers.txt'
mitm_servers: list[str] = []
if os.path.isfile(mitm_servers_filename):
if is_a_file(mitm_servers_filename):
mitm_servers_str = \
load_string(mitm_servers_filename,
'EX: error while reading mitm_servers.txt')

View File

@ -48,6 +48,7 @@ from data import save_string
from data import append_string
from data import prepend_string
from data import erase_file
from data import is_a_file
def _update_feeds_outbox_index(base_dir: str, domain: str,
@ -57,7 +58,7 @@ def _update_feeds_outbox_index(base_dir: str, domain: str,
base_path = data_dir(base_dir) + '/news@' + domain
index_filename = base_path + '/outbox.index'
if os.path.isfile(index_filename):
if is_a_file(index_filename):
if not text_in_file(post_id, index_filename):
if prepend_string(post_id, index_filename,
'EX: ' +
@ -387,7 +388,7 @@ def _newswire_hashtag_processing(base_dir: str, post_json_object: {},
of this instance
"""
rules_filename = data_dir(base_dir) + '/hashtagrules.txt'
if not os.path.isfile(rules_filename):
if not is_a_file(rules_filename):
return True
rules: list[str] = \
load_list(rules_filename,
@ -462,7 +463,7 @@ def _create_news_mirror(base_dir: str, domain: str,
mirror_index_filename = data_dir(base_dir) + '/newsmirror.txt'
if max_mirrored_articles > 0 and no_of_dirs > max_mirrored_articles:
if not os.path.isfile(mirror_index_filename):
if not is_a_file(mirror_index_filename):
# no index for mirrors found
return True
removals: list[str] = []
@ -527,7 +528,7 @@ def _create_news_mirror(base_dir: str, domain: str,
return True
# append the post Id number to the index file
if os.path.isfile(mirror_index_filename):
if is_a_file(mirror_index_filename):
append_string(post_id_number + '\n', mirror_index_filename,
'EX: _create_news_mirror unable to append ' +
mirror_index_filename)
@ -592,7 +593,7 @@ def _convert_rss_to_activitypub(base_dir: str, http_prefix: str,
# file where the post is stored
filename = base_path + '/' + new_post_id.replace('/', '#') + '.json'
if os.path.isfile(filename):
if is_a_file(filename):
# don't create the post if it already exists
# set the url
# newswire[original_date_str][1] = \
@ -753,7 +754,7 @@ def _convert_rss_to_activitypub(base_dir: str, http_prefix: str,
_save_arrived_time(filename,
blog['object']['arrived'])
else:
if os.path.isfile(filename + '.arrived'):
if is_a_file(filename + '.arrived'):
erase_file(filename + '.arrived',
'EX: _convert_rss_to_activitypub ' +
'unable to delete ' +
@ -821,7 +822,7 @@ def run_newswire_daemon(base_dir: str, httpd,
if not httpd.newswire:
print('Newswire feeds not updated')
if os.path.isfile(newswire_state_filename):
if is_a_file(newswire_state_filename):
print('Loading newswire from file')
httpd.newswire = load_json(newswire_state_filename)
@ -864,7 +865,7 @@ def run_newswire_daemon(base_dir: str, httpd,
time.sleep(10)
# if a new blog post has been created then stop
# waiting and recalculate the newswire
if not os.path.isfile(refresh_filename):
if not is_a_file(refresh_filename):
continue
ex_text = \
'EX: run_newswire_daemon unable to delete ' + \

View File

@ -58,6 +58,7 @@ from data import load_list
from data import load_string
from data import save_binary
from data import erase_file
from data import is_a_file
def _remove_cdata(text: str) -> str:
@ -198,7 +199,7 @@ def _download_newswire_feed_favicon(session, base_dir: str,
# save to the cache
fav_filename = get_fav_filename_from_url(base_dir, fav_url)
if os.path.isfile(fav_filename):
if is_a_file(fav_filename):
return True
if not save_binary(image_data, fav_filename,
'EX: failed writing favicon ' + fav_filename):
@ -397,10 +398,10 @@ def load_hashtag_categories(base_dir: str, language: str) -> None:
"""Loads an rss file containing hashtag categories
"""
hashtag_categories_filename = base_dir + '/categories.xml'
if not os.path.isfile(hashtag_categories_filename):
if not is_a_file(hashtag_categories_filename):
hashtag_categories_filename = \
base_dir + '/defaultcategories/' + language + '.xml'
if not os.path.isfile(hashtag_categories_filename):
if not is_a_file(hashtag_categories_filename):
return
xml_str = load_string(hashtag_categories_filename,
@ -1667,7 +1668,7 @@ def _add_account_blogs_to_newswire(base_dir: str, nickname: str, domain: str,
session, debug: bool) -> None:
"""Adds blogs for the given account to the newswire
"""
if not os.path.isfile(index_filename):
if not is_a_file(index_filename):
return
# local blog entries are unmoderated by default
moderated: bool = False
@ -1675,7 +1676,7 @@ def _add_account_blogs_to_newswire(base_dir: str, nickname: str, domain: str,
# local blogs can potentially be moderated
moderated_filename = \
acct_dir(base_dir, nickname, domain) + '/.newswiremoderated'
if os.path.isfile(moderated_filename):
if is_a_file(moderated_filename):
moderated = True
try:
@ -1719,7 +1720,7 @@ def _add_account_blogs_to_newswire(base_dir: str, nickname: str, domain: str,
published = published.replace('T', ' ')
published = published.replace('Z', '+00:00')
votes: list[str] = []
if os.path.isfile(full_post_filename + '.votes'):
if is_a_file(full_post_filename + '.votes'):
votes = load_json(full_post_filename + '.votes')
content = \
get_base_content_from_post(post_json_object,
@ -1774,13 +1775,13 @@ def _add_blogs_to_newswire(base_dir: str, domain: str, newswire: {},
continue
handle_dir = acct_handle_dir(base_dir, handle)
if os.path.isfile(handle_dir + '/.nonewswire'):
if is_a_file(handle_dir + '/.nonewswire'):
continue
# is there a blogs timeline for this account?
account_dir = os.path.join(dir_str, handle)
blogs_index = account_dir + '/tlblogs.index'
if os.path.isfile(blogs_index):
if is_a_file(blogs_index):
domain = handle.split('@')[1]
_add_account_blogs_to_newswire(base_dir, nickname, domain,
newswire, max_blogs_per_account,
@ -1799,7 +1800,7 @@ def _add_blogs_to_newswire(base_dir: str, domain: str, newswire: {},
save_json(sorted_moderation_dict, newswire_moderation_filename)
else:
# remove the file if there is nothing to moderate
if os.path.isfile(newswire_moderation_filename):
if is_a_file(newswire_moderation_filename):
ex_text = \
'EX: _add_blogs_to_newswire unable to delete ' + \
str(newswire_moderation_filename)
@ -1817,7 +1818,7 @@ def get_dict_from_newswire(session, base_dir: str, domain: str,
"""Gets rss feeds as a dictionary from newswire file
"""
subscriptions_filename = data_dir(base_dir) + '/newswire.txt'
if not os.path.isfile(subscriptions_filename):
if not is_a_file(subscriptions_filename):
return {}
max_posts_per_source = 5

View File

@ -7,13 +7,13 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Calendar"
import os
from utils import remove_domain_port
from utils import acct_dir
from utils import text_in_file
from data import load_string
from data import save_string
from data import save_flag_file
from data import is_a_file
def _notify_on_post_arrival(base_dir: str, nickname: str, domain: str,
@ -27,7 +27,7 @@ def _notify_on_post_arrival(base_dir: str, nickname: str, domain: str,
domain = remove_domain_port(domain)
following_filename = \
acct_dir(base_dir, nickname, domain) + '/following.txt'
if not os.path.isfile(following_filename):
if not is_a_file(following_filename):
print("WARN: following.txt doesn't exist for " +
nickname + '@' + domain)
return
@ -44,7 +44,7 @@ def _notify_on_post_arrival(base_dir: str, nickname: str, domain: str,
# get the contents of the notifyOnPost file, which is
# a set of handles
following_handles: str = ''
if os.path.isfile(notify_on_post_filename):
if is_a_file(notify_on_post_filename):
print('notify file exists')
following_handles = \
load_string(notify_on_post_filename,
@ -125,7 +125,7 @@ def notify_when_person_posts(base_dir: str, nickname: str, domain: str,
notify_on_post_filename = \
acct_dir(base_dir, nickname, domain) + '/notifyOnPost.txt'
handle = following_nickname + '@' + following_domain
if not os.path.isfile(notify_on_post_filename):
if not is_a_file(notify_on_post_filename):
# create a new notifyOnPost file
save_flag_file(notify_on_post_filename,
'EX: notify_when_person_posts unable to write ' +

View File

@ -75,6 +75,7 @@ from markdown import blog_to_markdown
from markdown import blog_to_micron
from data import erase_file
from data import move_file
from data import is_a_file
def _localonly_not_local(message_json: {}, domain_full: str) -> bool:
@ -182,7 +183,7 @@ def _person_receive_update_outbox(base_dir: str, http_prefix: str,
updated_actor_json = message_json['object']
# load actor from file
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if not os.path.isfile(actor_filename):
if not is_a_file(actor_filename):
print('actor_filename not found: ' + actor_filename)
return
actor_json = load_json(actor_filename)
@ -488,7 +489,7 @@ def post_message_to_outbox(session, translate: {},
data_dir(base_dir) + '/' + \
post_to_nickname + '@' + domain
upload_media_filename = media_dir + '/upload.' + file_extension
if not os.path.isfile(upload_media_filename):
if not is_a_file(upload_media_filename):
del message_json['object']['attachment']
else:
# generate a path for the uploaded image
@ -613,7 +614,7 @@ def post_message_to_outbox(session, translate: {},
citations_filename = \
data_dir(base_dir) + '/' + \
post_to_nickname + '@' + domain + '/.citations.txt'
if os.path.isfile(citations_filename):
if is_a_file(citations_filename):
erase_file(citations_filename,
'EX: post_message_to_outbox unable to delete ' +
citations_filename)
@ -636,7 +637,7 @@ def post_message_to_outbox(session, translate: {},
show_vote_posts: bool = True
show_vote_file = \
acct_dir(base_dir, post_to_nickname, domain) + '/.noVotes'
if os.path.isfile(show_vote_file):
if is_a_file(show_vote_file):
show_vote_posts = False
languages_understood: list[str] = []
if is_image_media(session, base_dir, http_prefix,
@ -680,8 +681,8 @@ def post_message_to_outbox(session, translate: {},
get_account_timezone(base_dir,
post_to_nickname, domain)
mitm: bool = False
if os.path.isfile(saved_filename.replace('.json', '') +
'.mitm'):
test_filename = saved_filename.replace('.json', '') + '.mitm'
if is_a_file(test_filename):
mitm = True
minimize_all_images: bool = False
if post_to_nickname in min_images_for_accounts:

View File

@ -98,6 +98,7 @@ from data import load_string
from data import append_string
from data import erase_file
from data import move_file
from data import is_a_file
def generate_rsa_key() -> (str, str):
@ -144,7 +145,7 @@ def set_profile_image(base_dir: str, http_prefix: str,
handle = nickname + '@' + domain
person_filename = acct_handle_dir(base_dir, handle) + '.json'
if not os.path.isfile(person_filename):
if not is_a_file(person_filename):
print('person definition not found: ' + person_filename)
return False
handle_dir = acct_handle_dir(base_dir, handle)
@ -705,11 +706,11 @@ def clear_person_qrcodes(base_dir: str) -> None:
domain = handle.split('@')[1]
qrcode_filename = \
acct_dir(base_dir, nickname, domain) + '/qrcode.png'
if os.path.isfile(qrcode_filename):
if is_a_file(qrcode_filename):
erase_file(qrcode_filename,
'EX: clear_person_qrcodes 1 ' +
qrcode_filename)
if os.path.isfile(qrcode_filename + '.etag'):
if is_a_file(qrcode_filename + '.etag'):
erase_file(qrcode_filename + '.etag',
'EX: clear_person_qrcodes 2 ' +
qrcode_filename + '.etag')
@ -723,7 +724,7 @@ def save_person_qrcode(base_dir: str,
This helps to transfer onion or i2p handles to a mobile device
"""
qrcode_filename = acct_dir(base_dir, nickname, domain) + '/qrcode.png'
if os.path.isfile(qrcode_filename):
if is_a_file(qrcode_filename):
return
handle = get_full_domain('@' + nickname + '@' + qrcode_domain, port)
url = pyqrcode.create(handle)
@ -811,30 +812,30 @@ def create_person(base_dir: str, nickname: str, domain: str, port: int,
theme = 'default'
if nickname != 'news':
if os.path.isfile(base_dir + '/img/default-avatar.png'):
if is_a_file(base_dir + '/img/default-avatar.png'):
account_dir = acct_dir(base_dir, nickname, domain)
copyfile(base_dir + '/img/default-avatar.png',
account_dir + '/avatar.png')
else:
news_avatar = base_dir + '/theme/' + theme + '/icons/avatar_news.png'
if os.path.isfile(news_avatar):
if is_a_file(news_avatar):
account_dir = acct_dir(base_dir, nickname, domain)
copyfile(news_avatar, account_dir + '/avatar.png')
default_profile_image_filename = base_dir + '/theme/default/image.png'
if theme:
if os.path.isfile(base_dir + '/theme/' + theme + '/image.png'):
if is_a_file(base_dir + '/theme/' + theme + '/image.png'):
default_profile_image_filename = \
base_dir + '/theme/' + theme + '/image.png'
if os.path.isfile(default_profile_image_filename):
if is_a_file(default_profile_image_filename):
account_dir = acct_dir(base_dir, nickname, domain)
copyfile(default_profile_image_filename, account_dir + '/image.png')
default_banner_filename = base_dir + '/theme/default/banner.png'
if theme:
if os.path.isfile(base_dir + '/theme/' + theme + '/banner.png'):
if is_a_file(base_dir + '/theme/' + theme + '/banner.png'):
default_banner_filename = \
base_dir + '/theme/' + theme + '/banner.png'
if os.path.isfile(default_banner_filename):
if is_a_file(default_banner_filename):
account_dir = acct_dir(base_dir, nickname, domain)
copyfile(default_banner_filename, account_dir + '/banner.png')
if nickname != 'news' and remaining_config_exists:
@ -866,7 +867,7 @@ def person_upgrade_actor(base_dir: str, person_json: {},
"""Alter the actor to add any new properties
"""
update_actor: bool = False
if not os.path.isfile(filename):
if not is_a_file(filename):
print('WARN: actor file not found ' + filename)
return
if not person_json:
@ -1050,7 +1051,7 @@ def person_upgrade_actor(base_dir: str, person_json: {},
actor_cache_filename = \
data_dir(base_dir) + '/cache/actors/' + \
person_json['id'].replace('/', '#') + '.json'
if os.path.isfile(actor_cache_filename):
if is_a_file(actor_cache_filename):
save_json(person_json, actor_cache_filename)
# update domain/@nickname in actors cache
@ -1058,7 +1059,7 @@ def person_upgrade_actor(base_dir: str, person_json: {},
data_dir(base_dir) + '/cache/actors/' + \
replace_users_with_at(person_json['id']).replace('/', '#') + \
'.json'
if os.path.isfile(actor_cache_filename):
if is_a_file(actor_cache_filename):
save_json(person_json, actor_cache_filename)
@ -1127,7 +1128,7 @@ def person_lookup(domain: str, path: str, base_dir: str) -> {}:
domain = remove_domain_port(domain)
handle = nickname + '@' + domain
filename = acct_handle_dir(base_dir, handle) + '.json'
if not os.path.isfile(filename):
if not is_a_file(filename):
return None
person_json = load_json(filename)
if not is_shared_inbox:
@ -1260,7 +1261,7 @@ def set_display_nickname(base_dir: str, nickname: str, domain: str,
return False
handle = nickname + '@' + domain
filename = acct_handle_dir(base_dir, handle) + '.json'
if not os.path.isfile(filename):
if not is_a_file(filename):
return False
person_json = load_json(filename)
@ -1278,7 +1279,7 @@ def set_bio(base_dir: str, nickname: str, domain: str, bio: str) -> bool:
return False
handle = nickname + '@' + domain
filename = acct_handle_dir(base_dir, handle) + '.json'
if not os.path.isfile(filename):
if not is_a_file(filename):
return False
person_json = load_json(filename)
@ -1296,7 +1297,7 @@ def _unsuspend_media_for_account(base_dir: str, account_dir: str) -> None:
"""Unsuspends all media for an account
"""
account_media_log_filename = account_dir + '/media_log.txt'
if not os.path.isfile(account_media_log_filename):
if not is_a_file(account_media_log_filename):
return
media_log: list[str] = []
@ -1308,7 +1309,7 @@ def _unsuspend_media_for_account(base_dir: str, account_dir: str) -> None:
for filename in media_log:
media_filename = base_dir + filename
if not os.path.isfile(media_filename + '.suspended'):
if not is_a_file(media_filename + '.suspended'):
continue
move_file(media_filename + '.suspended', media_filename,
'EX: unable to unsuspend media ' + media_filename)
@ -1318,7 +1319,7 @@ def reenable_account(base_dir: str, nickname: str, domain: str) -> None:
"""Removes an account suspension
"""
suspended_filename = data_dir(base_dir) + '/suspended.txt'
if os.path.isfile(suspended_filename):
if is_a_file(suspended_filename):
lines: list[str] = \
load_list(suspended_filename,
'EX: reenable_account unable to read ' +
@ -1340,7 +1341,7 @@ def _suspend_media_for_account(base_dir: str, account_dir: str) -> None:
"""Suspends all media for an account
"""
account_media_log_filename = account_dir + '/media_log.txt'
if not os.path.isfile(account_media_log_filename):
if not is_a_file(account_media_log_filename):
return
media_log: list[str] = []
@ -1352,7 +1353,7 @@ def _suspend_media_for_account(base_dir: str, account_dir: str) -> None:
for filename in media_log:
media_filename = base_dir + filename
if not os.path.isfile(media_filename):
if not is_a_file(media_filename):
continue
move_file(media_filename, media_filename + '.suspended',
'EX: unable to suspend media ' + media_filename)
@ -1370,7 +1371,7 @@ def suspend_account(base_dir: str, nickname: str, domain: str) -> None:
# Don't suspend moderators
moderators_file = data_dir(base_dir) + '/moderators.txt'
if os.path.isfile(moderators_file):
if is_a_file(moderators_file):
lines: list[str] = \
load_list(moderators_file,
'EX: suspend_account unable too read ' +
@ -1383,16 +1384,16 @@ def suspend_account(base_dir: str, nickname: str, domain: str) -> None:
account_dir = acct_dir(base_dir, nickname, domain)
salt_filename = account_dir + '/.salt'
if os.path.isfile(salt_filename):
if is_a_file(salt_filename):
erase_file(salt_filename,
'EX: suspend_account unable to delete ' + salt_filename)
token_filename = acct_dir(base_dir, nickname, domain) + '/.token'
if os.path.isfile(token_filename):
if is_a_file(token_filename):
erase_file(token_filename,
'EX: suspend_account unable to delete 2 ' + token_filename)
suspended_filename = data_dir(base_dir) + '/suspended.txt'
if os.path.isfile(suspended_filename):
if is_a_file(suspended_filename):
lines: list[str] = \
load_list(suspended_filename,
'EX: suspend_account unable to read 2 ' +
@ -1430,7 +1431,7 @@ def can_remove_post(base_dir: str,
# is the post by a moderator?
moderators_file = data_dir(base_dir) + '/moderators.txt'
if os.path.isfile(moderators_file):
if is_a_file(moderators_file):
lines: list[str] = \
load_list(moderators_file,
'EX: can_remove_post unable to read ' +
@ -1463,7 +1464,7 @@ def _remove_tags_for_nickname(base_dir: str, nickname: str,
print('EX: _remove_tags_for_nickname unable to join ' +
base_dir + '/tags/ ' + str(filename))
continue
if not os.path.isfile(tag_filename):
if not is_a_file(tag_filename):
continue
if not text_in_file(match_str, tag_filename):
continue
@ -1489,7 +1490,7 @@ def _remove_account_media(base_dir: str, nickname: str, domain: str) -> None:
account_media_log_filename = account_dir + '/media_log.txt'
media_log: list[str] = []
if os.path.isfile(account_media_log_filename):
if is_a_file(account_media_log_filename):
media_log_str = \
load_string(account_media_log_filename,
'EX: remove unable to read media log for ' +
@ -1499,7 +1500,7 @@ def _remove_account_media(base_dir: str, nickname: str, domain: str) -> None:
for filename in media_log:
media_filename = base_dir + filename
if not os.path.isfile(media_filename):
if not is_a_file(media_filename):
continue
erase_file(media_filename,
'EX: unable to remove media ' + media_filename)
@ -1518,7 +1519,7 @@ def remove_account(base_dir: str, nickname: str,
# Don't remove moderators
moderators_file = data_dir(base_dir) + '/moderators.txt'
if os.path.isfile(moderators_file):
if is_a_file(moderators_file):
lines: list[str] = \
load_list(moderators_file,
'EX: remove_account unable to read ' + moderators_file)
@ -1539,26 +1540,26 @@ def remove_account(base_dir: str, nickname: str,
handle_dir = acct_handle_dir(base_dir, handle)
if os.path.isdir(handle_dir):
shutil.rmtree(handle_dir, ignore_errors=False)
if os.path.isfile(handle_dir + '.json'):
if is_a_file(handle_dir + '.json'):
erase_file(handle_dir + '.json',
'EX: remove_account unable to delete ' +
handle_dir + '.json')
if os.path.isfile(base_dir + '/wfendpoints/' + handle + '.json'):
if is_a_file(base_dir + '/wfendpoints/' + handle + '.json'):
erase_file(base_dir + '/wfendpoints/' + handle + '.json',
'EX: remove_account unable to delete ' +
base_dir + '/wfendpoints/' + handle + '.json')
if os.path.isfile(base_dir + '/keys/private/' + handle + '.key'):
if is_a_file(base_dir + '/keys/private/' + handle + '.key'):
erase_file(base_dir + '/keys/private/' + handle + '.key',
'EX: remove_account unable to delete ' +
base_dir + '/keys/private/' + handle + '.key')
if os.path.isfile(base_dir + '/keys/public/' + handle + '.pem'):
if is_a_file(base_dir + '/keys/public/' + handle + '.pem'):
erase_file(base_dir + '/keys/public/' + handle + '.pem',
'EX: remove_account unable to delete ' +
base_dir + '/keys/public/' + handle + '.pem')
if os.path.isdir(base_dir + '/sharefiles/' + nickname):
shutil.rmtree(base_dir + '/sharefiles/' + nickname,
ignore_errors=False)
if os.path.isfile(base_dir + '/wfdeactivated/' + handle + '.json'):
if is_a_file(base_dir + '/wfdeactivated/' + handle + '.json'):
erase_file(base_dir + '/wfdeactivated/' + handle + '.json',
'EX: remove_account unable to delete ' +
base_dir + '/wfdeactivated/' + handle + '.json')
@ -1584,7 +1585,7 @@ def deactivate_account(base_dir: str, nickname: str, domain: str) -> bool:
os.mkdir(deactivated_dir)
shutil.move(account_dir, deactivated_dir + '/' + handle)
if os.path.isfile(base_dir + '/wfendpoints/' + handle + '.json'):
if is_a_file(base_dir + '/wfendpoints/' + handle + '.json'):
deactivated_webfinger_dir = base_dir + '/wfdeactivated'
if not os.path.isdir(deactivated_webfinger_dir):
os.mkdir(deactivated_webfinger_dir)
@ -1618,7 +1619,7 @@ def activate_account2(base_dir: str, nickname: str, domain: str) -> bool:
activated = True
deactivated_webfinger_dir = base_dir + '/wfdeactivated'
if os.path.isfile(deactivated_webfinger_dir + '/' + handle + '.json'):
if is_a_file(deactivated_webfinger_dir + '/' + handle + '.json'):
shutil.move(deactivated_webfinger_dir + '/' + handle + '.json',
base_dir + '/wfendpoints/' + handle + '.json')
@ -1637,7 +1638,7 @@ def is_person_snoozed(base_dir: str, nickname: str, domain: str,
"""Returns true if the given actor is snoozed
"""
snoozed_filename = acct_dir(base_dir, nickname, domain) + '/snoozed.txt'
if not os.path.isfile(snoozed_filename):
if not is_a_file(snoozed_filename):
return False
if not text_in_file(snooze_actor + ' ', snoozed_filename):
return False
@ -1690,7 +1691,7 @@ def person_snooze(base_dir: str, nickname: str, domain: str,
print('ERROR: unknown account ' + account_dir)
return
snoozed_filename = account_dir + '/snoozed.txt'
if os.path.isfile(snoozed_filename):
if is_a_file(snoozed_filename):
if text_in_file(snooze_actor + ' ', snoozed_filename):
return
text = snooze_actor + ' ' + str(int(time.time())) + '\n'
@ -1707,7 +1708,7 @@ def person_unsnooze(base_dir: str, nickname: str, domain: str,
print('ERROR: unknown account ' + account_dir)
return
snoozed_filename = account_dir + '/snoozed.txt'
if not os.path.isfile(snoozed_filename):
if not is_a_file(snoozed_filename):
return
if not text_in_file(snooze_actor + ' ', snoozed_filename):
return
@ -1761,7 +1762,7 @@ def get_person_notes(base_dir: str, nickname: str, domain: str,
person_notes_filename = \
acct_dir(base_dir, nickname, domain) + \
'/notes/' + handle + '.txt'
if os.path.isfile(person_notes_filename):
if is_a_file(person_notes_filename):
person_notes = load_string(person_notes_filename,
'EX: get_person_notes unable to read ' +
person_notes_filename)
@ -2072,10 +2073,10 @@ def get_person_avatar_url(base_dir: str, person_url: str,
for ext in image_extension:
im_filename = avatar_image_path + '.' + ext
im_path = '/avatars/' + actor_str + '.' + ext
if not os.path.isfile(im_filename):
if not is_a_file(im_filename):
im_filename = avatar_image_path.lower() + '.' + ext
im_path = '/avatars/' + actor_str.lower() + '.' + ext
if not os.path.isfile(im_filename):
if not is_a_file(im_filename):
continue
if ext != 'svg':
return im_path
@ -2156,7 +2157,7 @@ def valid_sending_actor(session, base_dir: str,
# is this a known spam actor?
actor_spam_filter_filename = \
acct_dir(base_dir, nickname, domain) + '/.reject_spam_actors'
if not os.path.isfile(actor_spam_filter_filename):
if not is_a_file(actor_spam_filter_filename):
return True
# does the actor have a bio ?
@ -2402,7 +2403,7 @@ def update_memorial_flags(base_dir: str, person_cache: {}) -> None:
if not is_account_dir(account):
continue
actor_filename = data_dir(base_dir) + '/' + account + '.json'
if not os.path.isfile(actor_filename):
if not is_a_file(actor_filename):
continue
actor_json = load_json(actor_filename)
if not actor_json:
@ -2462,7 +2463,7 @@ def get_account_pub_key(path: str, person_cache: {},
actor_json = get_person_from_cache(base_dir, actor, person_cache)
if not actor_json:
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if not os.path.isfile(actor_filename):
if not is_a_file(actor_filename):
return None
actor_json = load_json(actor_filename)
if not actor_json:

View File

@ -7,11 +7,11 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Core"
import os
from utils import acct_dir
from data import load_string
from data import save_string
from data import append_string
from data import is_a_file
def set_pet_name(base_dir: str, nickname: str, domain: str,
@ -30,7 +30,7 @@ def set_pet_name(base_dir: str, nickname: str, domain: str,
entry = petname + ' ' + handle + '\n'
# does this entry already exist?
if os.path.isfile(petnames_filename):
if is_a_file(petnames_filename):
petnames_str: str = \
load_string(petnames_filename,
'EX: set_pet_name unable to read ' + petnames_filename)
@ -77,7 +77,7 @@ def get_pet_name(base_dir: str, nickname: str, domain: str,
handle = handle[1:]
petnames_filename = acct_dir(base_dir, nickname, domain) + '/petnames.txt'
if not os.path.isfile(petnames_filename):
if not is_a_file(petnames_filename):
return ''
petnames_str: str = \
load_string(petnames_filename,
@ -107,7 +107,7 @@ def _get_pet_name_handle(base_dir: str, nickname: str, domain: str,
petname = petname[1:]
petnames_filename = acct_dir(base_dir, nickname, domain) + '/petnames.txt'
if not os.path.isfile(petnames_filename):
if not is_a_file(petnames_filename):
return ''
petnames_str: str = \
load_string(petnames_filename,

View File

@ -8,10 +8,10 @@ __status__ = "Production"
__module_group__ = "Core"
import os
import random
from random import randint
from data import load_string
from data import is_a_file
common_nouns = (
"time",
@ -1974,9 +1974,9 @@ def load_dictionary(base_dir: str) -> []:
"""Loads a dictionary from file
"""
filename = base_dir + '/custom_dictionary.txt'
if not os.path.isfile(filename):
if not is_a_file(filename):
filename = base_dir + '/dictionary.txt'
if not os.path.isfile(filename):
if not is_a_file(filename):
return []
words: list[str] = []
@ -1991,9 +1991,9 @@ def load_2grams(base_dir: str) -> {}:
"""Loads 2-grams from file
"""
filename = base_dir + '/custom_2grams.txt'
if not os.path.isfile(filename):
if not is_a_file(filename):
filename = base_dir + '/2grams.txt'
if not os.path.isfile(filename):
if not is_a_file(filename):
return {}
twograms = {}

113
posts.py
View File

@ -152,6 +152,7 @@ from data import append_string
from data import prepend_string
from data import erase_file
from data import move_file
from data import is_a_file
def convert_post_content_to_html(message_json: {}) -> None:
@ -189,7 +190,7 @@ def no_of_followers_on_domain(base_dir: str, handle: str,
given domain
"""
filename: str = acct_handle_dir(base_dir, handle) + '/' + follow_file
if not os.path.isfile(filename):
if not is_a_file(filename):
return 0
ctr: int = 0
@ -990,7 +991,7 @@ def delete_all_posts(base_dir: str,
delete_filename = delete_filename.name
file_path = os.path.join(box_dir, delete_filename)
try:
if os.path.isfile(file_path):
if is_a_file(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path, ignore_errors=False, onexc=None)
@ -1048,19 +1049,19 @@ def save_post_to_box(base_dir: str, http_prefix: str, post_id: str,
_save_last_published(base_dir, nickname, domain, published)
inbox_filename = filename.replace('/outbox/', '/inbox/')
if os.path.isfile(inbox_filename):
if is_a_file(inbox_filename):
save_json(post_json_object, inbox_filename)
base_filename = \
filename.replace('/outbox/',
'/postcache/').replace('.json', '')
ssml_filename = base_filename + '.ssml'
if os.path.isfile(ssml_filename):
if is_a_file(ssml_filename):
erase_file(ssml_filename,
'EX: ' +
'save_post_to_box unable to delete ssml file ' +
ssml_filename)
html_filename = base_filename + '.html'
if os.path.isfile(html_filename):
if is_a_file(html_filename):
erase_file(html_filename,
'EX: ' +
'save_post_to_box unable to delete html file ' +
@ -1085,7 +1086,7 @@ def _update_hashtags_index(base_dir: str, tag: {}, new_post_id: str,
new_post_id = new_post_id.replace('/', '#')
if not os.path.isfile(tags_filename):
if not is_a_file(tags_filename):
days_diff = date_utcnow() - date_epoch()
days_since_epoch = days_diff.days
tag_line = \
@ -1120,7 +1121,7 @@ def _add_schedule_post(base_dir: str, nickname: str, domain: str,
acct_handle_dir(base_dir, handle) + '/schedule.index'
index_str = event_date_str + ' ' + post_id.replace('/', '#')
if os.path.isfile(schedule_index_filename):
if is_a_file(schedule_index_filename):
if not text_in_file(index_str, schedule_index_filename):
ex_str: str = \
'EX: Failed to prepend entry to scheduled posts index ' + \
@ -2166,7 +2167,7 @@ def undo_pinned_post(base_dir: str, nickname: str, domain: str) -> None:
"""
account_dir = acct_dir(base_dir, nickname, domain)
pinned_filename = account_dir + '/pinToProfile.txt'
if not os.path.isfile(pinned_filename):
if not is_a_file(pinned_filename):
return
erase_file(pinned_filename,
'EX: undo_pinned_post unable to delete ' + pinned_filename)
@ -2181,7 +2182,7 @@ def get_pinned_post_as_json(base_dir: str, http_prefix: str,
pinned_filename = account_dir + '/pinToProfile.txt'
pinned_post_json = {}
actor = local_actor_url(http_prefix, nickname, domain_full)
if os.path.isfile(pinned_filename):
if is_a_file(pinned_filename):
pinned_content = \
load_string(pinned_filename,
'EX: get_pinned_post_as_json unable to read ' +
@ -2248,7 +2249,7 @@ def regenerate_index_for_box(base_dir: str,
if not os.path.isdir(box_dir):
return
if os.path.isfile(box_index_filename):
if is_a_file(box_index_filename):
return
index_lines: list[str] = []
@ -2411,7 +2412,7 @@ def _append_citations_to_blog_post(base_dir: str,
# append citations tags, stored in a file
citations_filename = \
acct_dir(base_dir, nickname, domain) + '/.citations.txt'
if not os.path.isfile(citations_filename):
if not is_a_file(citations_filename):
return
citations_separator = '#####'
citations: list[str] = \
@ -2867,7 +2868,7 @@ def create_report_post(base_dir: str,
# create the list of moderators from the moderators file
moderators_list: list[str] = []
moderators_file = data_dir(base_dir) + '/moderators.txt'
if os.path.isfile(moderators_file):
if is_a_file(moderators_file):
moderators_list2: list[str] = \
load_list(moderators_file,
'EX: create_report_post unable to read ' +
@ -2974,7 +2975,7 @@ def create_report_post(base_dir: str,
# save a notification file so that the moderator
# knows something new has appeared
new_report_file = acct_handle_dir(base_dir, handle) + '/.newReport'
if os.path.isfile(new_report_file):
if is_a_file(new_report_file):
continue
save_string(to_url + '/moderation', new_report_file,
'EX: create_report_post unable to write ' +
@ -2994,7 +2995,7 @@ def _add_send_block(base_dir: str, nickname: str, domain: str,
if inbox_url.endswith('/inbox\n'):
inbox_url = inbox_url.replace('/inbox\n', '\n')
if not os.path.isfile(send_block_filename):
if not is_a_file(send_block_filename):
save_string(inbox_url, send_block_filename,
'EX: _add_send_block unable to create ' +
send_block_filename)
@ -3017,7 +3018,7 @@ def _remove_send_block(base_dir: str, nickname: str, domain: str,
if inbox_url.endswith('/inbox\n'):
inbox_url = inbox_url.replace('/inbox\n', '\n')
if not os.path.isfile(send_block_filename):
if not is_a_file(send_block_filename):
return
if not text_in_file(inbox_url, send_block_filename, False):
@ -3110,7 +3111,7 @@ def thread_send_post(session, post_json_str: str, federation_list: [],
if debug:
# save the log file
post_log_filename = base_dir + '/post.log'
if os.path.isfile(post_log_filename):
if is_a_file(post_log_filename):
append_string(log_str + '\n', post_log_filename,
'EX: thread_send_post unable to append ' +
post_log_filename)
@ -3370,7 +3371,7 @@ def group_followers_by_domain(base_dir: str, nickname: str, domain: str) -> {}:
"""
handle = nickname + '@' + domain
followers_filename = acct_handle_dir(base_dir, handle) + '/followers.txt'
if not os.path.isfile(followers_filename):
if not is_a_file(followers_filename):
return None
grouped = {}
followers_list: list[str] = \
@ -4511,7 +4512,7 @@ def create_moderation(base_dir: str, nickname: str, domain: str, port: int,
if is_moderator(base_dir, nickname):
moderation_index_file = data_dir(base_dir) + '/moderation.txt'
if os.path.isfile(moderation_index_file):
if is_a_file(moderation_index_file):
lines: list[str] = \
load_list(moderation_index_file,
'EX: create_moderation unable to read ' +
@ -4538,7 +4539,7 @@ def create_moderation(base_dir: str, nickname: str, domain: str, port: int,
for post_url in page_lines:
post_filename = \
box_dir + '/' + post_url.replace('/', '#') + '.json'
if os.path.isfile(post_filename):
if is_a_file(post_filename):
post_json_object = load_json(post_filename)
if post_json_object:
box_items['orderedItems'].append(post_json_object)
@ -4597,12 +4598,12 @@ def _add_post_to_timeline(file_path: str, boxname: str,
if file_path.endswith('.json'):
replies_filename = file_path.replace('.json', '.replies')
if os.path.isfile(replies_filename):
if is_a_file(replies_filename):
# append a replies identifier, which will later be removed
post_str += '<hasReplies>'
mitm_filename = file_path.replace('.json', '.mitm')
if os.path.isfile(mitm_filename):
if is_a_file(mitm_filename):
# append a mitm identifier, which will later be removed
post_str += '<postmitm>'
@ -4667,7 +4668,7 @@ def _locate_news_arrival(base_dir: str, domain: str,
account_dir = data_dir(base_dir) + '/news@' + domain + '/'
post_filename = account_dir + 'outbox/' + post_url
if os.path.isfile(post_filename):
if is_a_file(post_filename):
arrival = load_string(post_filename,
'EX: _locate_news_arrival unable to read ' +
post_filename)
@ -4752,7 +4753,7 @@ def _create_box_items(base_dir: str,
'/' + index_box_name + '.index'
total_posts_count: int = 0
posts_added_to_timeline: int = 0
if not os.path.isfile(index_filename):
if not is_a_file(index_filename):
return total_posts_count, posts_added_to_timeline
# format the first post into an hashed url
@ -4839,7 +4840,7 @@ def _create_box_items(base_dir: str,
original_domain, post_url, False)
if full_post_filename:
# has the post been rejected?
if os.path.isfile(full_post_filename + '.reject'):
if is_a_file(full_post_filename + '.reject'):
post_url2 = post_url.replace('/', '#') + '.json'
remove_post_from_index(post_url2, False,
index_filename)
@ -5107,7 +5108,7 @@ def _expire_announce_cache_for_person(base_dir: str,
cache_filename = cache_filename.name
# Time of file creation
full_filename = os.path.join(cache_dir, cache_filename)
if not os.path.isfile(full_filename):
if not is_a_file(full_filename):
continue
last_modified = file_last_modified(full_filename)
# get time difference
@ -5137,7 +5138,7 @@ def _expire_conversations_for_person(base_dir: str,
continue
# Time of file creation
full_filename = os.path.join(conv_dir, conv_filename)
if not os.path.isfile(full_filename):
if not is_a_file(full_filename):
continue
last_modified = file_last_modified(full_filename)
# get time difference
@ -5164,7 +5165,7 @@ def _expire_posts_cache_for_person(base_dir: str,
cache_filename = cache_filename.name
# Time of file creation
full_filename = os.path.join(cache_dir, cache_filename)
if not os.path.isfile(full_filename):
if not is_a_file(full_filename):
continue
last_modified = file_last_modified(full_filename)
# get time difference
@ -5276,7 +5277,7 @@ def _novel_fields_for_person(nickname: str, domain: str,
if not post_filename.endswith('.json'):
continue
full_filename = os.path.join(box_dir, post_filename)
if not os.path.isfile(full_filename):
if not is_a_file(full_filename):
continue
post_json_object = load_json(full_filename)
if not post_json_object:
@ -5397,7 +5398,7 @@ def _expire_posts_for_person(http_prefix: str, nickname: str, domain: str,
continue
# get the post json as text
full_filename = os.path.join(box_dir, post_filename)
if not os.path.isfile(full_filename):
if not is_a_file(full_filename):
continue
content = \
load_string(full_filename,
@ -5456,7 +5457,7 @@ def get_post_expiry_keep_dms(base_dir: str, nickname: str, domain: str) -> int:
handle: str = nickname + '@' + domain
expire_dms_filename = \
acct_handle_dir(base_dir, handle) + '/.expire_posts_dms'
if os.path.isfile(expire_dms_filename):
if is_a_file(expire_dms_filename):
keep_dms = False
return keep_dms
@ -5469,7 +5470,7 @@ def set_post_expiry_keep_dms(base_dir: str, nickname: str, domain: str,
expire_dms_filename = \
acct_handle_dir(base_dir, handle) + '/.expire_posts_dms'
if keep_dms:
if os.path.isfile(expire_dms_filename):
if is_a_file(expire_dms_filename):
erase_file(expire_dms_filename,
'EX: unable to write set_post_expiry_keep_dms False ' +
expire_dms_filename)
@ -5493,7 +5494,7 @@ def expire_posts(base_dir: str, http_prefix: str,
domain = handle.split('@')[1]
expire_posts_filename = \
acct_handle_dir(base_dir, handle) + '/.expire_posts_days'
if not os.path.isfile(expire_posts_filename):
if not is_a_file(expire_posts_filename):
continue
keep_dms = get_post_expiry_keep_dms(base_dir, nickname, domain)
expire_days_str = \
@ -5525,7 +5526,7 @@ def get_post_expiry_days(base_dir: str, nickname: str, domain: str) -> int:
handle = nickname + '@' + domain
expire_posts_filename = \
acct_handle_dir(base_dir, handle) + '/.expire_posts_days'
if not os.path.isfile(expire_posts_filename):
if not is_a_file(expire_posts_filename):
return 0
days_str = load_string(expire_posts_filename,
'EX: unable to write post expire days ' +
@ -5577,7 +5578,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
handle = nickname + '@' + domain
index_filename = \
acct_handle_dir(base_dir, handle) + '/' + boxname + '.index'
if os.path.isfile(index_filename):
if is_a_file(index_filename):
index_ctr: int = 0
# get the existing index entries as a string
new_index = ''
@ -5613,7 +5614,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
full_original_filename = \
os.path.join(box_dir, original_post_filename)
full_filename = os.path.join(box_dir, post_filename)
if not os.path.isfile(full_original_filename):
if not is_a_file(full_original_filename):
# if the original file doesn't exist (was remotely deleted by
# its author) then remove the corresponding edits
if erase_file(full_filename,
@ -5623,7 +5624,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
else:
continue
edit_files_ctr += 1
if os.path.isfile(full_filename):
if is_a_file(full_filename):
content = load_string(full_filename,
'EX: unable to open content 2 ' +
full_filename)
@ -5657,7 +5658,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
remove_edits_ctr: int = 0
for published_str, edit_filename in edits_in_box_sorted.items():
file_path = os.path.join(box_dir, edit_filename)
if not os.path.isfile(file_path):
if not is_a_file(file_path):
continue
if archive_dir:
archive_path = os.path.join(archive_dir, edit_filename)
@ -5688,7 +5689,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
continue
# Get the published time
full_filename = os.path.join(box_dir, post_filename)
if os.path.isfile(full_filename):
if is_a_file(full_filename):
content = load_string(full_filename,
'EX: unable to open content 1 ' +
full_filename)
@ -5718,7 +5719,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
remove_ctr: int = 0
for published_str, post_filename in posts_in_box_sorted.items():
file_path = os.path.join(box_dir, post_filename)
if not os.path.isfile(file_path):
if not is_a_file(file_path):
continue
if archive_dir:
archive_path = os.path.join(archive_dir, post_filename)
@ -5732,14 +5733,14 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
)
for ext in extensions:
ext_path = file_path.replace('.json', '.' + ext)
if os.path.isfile(ext_path):
if is_a_file(ext_path):
new_ext_path = archive_path.replace('.json', '.' + ext)
move_file(ext_path, new_ext_path,
'EX: unable to archive file ' + ext_path +
' -> ' + new_ext_path)
continue
ext_path = file_path.replace('.json', '.json.' + ext)
if os.path.isfile(ext_path):
if is_a_file(ext_path):
new_ext_path = \
archive_path.replace('.json', '.json.' + ext)
move_file(ext_path, new_ext_path,
@ -5754,7 +5755,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
post_cache_filename = \
os.path.join(post_cache_dir, post_filename)
post_cache_filename = post_cache_filename.replace('.json', '.html')
if os.path.isfile(post_cache_filename):
if is_a_file(post_cache_filename):
erase_file(post_cache_filename,
'EX: archive_posts_for_person unable to delete ' +
post_cache_filename)
@ -6026,7 +6027,7 @@ def get_public_post_domains_blocked(session, base_dir: str,
return []
blocking_filename = data_dir(base_dir) + '/blocking.txt'
if not os.path.isfile(blocking_filename):
if not is_a_file(blocking_filename):
return []
# read the blocked domains as a single string
@ -6086,7 +6087,7 @@ def check_domains(session, base_dir: str,
follower_warning_filename = data_dir(base_dir) + '/followerWarnings.txt'
update_follower_warnings: bool = False
follower_warning_str = ''
if os.path.isfile(follower_warning_filename):
if is_a_file(follower_warning_filename):
follower_warning_str = \
load_string(follower_warning_filename,
'EX: check_domains unable to read ' +
@ -6170,7 +6171,7 @@ def populate_replies_json(base_dir: str, nickname: str, domain: str,
acct_dir(base_dir, nickname, domain) + '/' + \
boxname + '/' + \
message_id2.replace('/', '#') + '.json'
if os.path.isfile(search_filename):
if is_a_file(search_filename):
if authorized or \
text_in_file(pub_str, search_filename):
post_json_object = load_json(search_filename)
@ -6197,7 +6198,7 @@ def populate_replies_json(base_dir: str, nickname: str, domain: str,
data_dir(base_dir) + '/inbox@' + \
domain + '/inbox/' + \
message_id2.replace('/', '#') + '.json'
if os.path.isfile(search_filename):
if is_a_file(search_filename):
if authorized or \
text_in_file(pub_str, search_filename):
# get the json of the reply and append it to
@ -6227,7 +6228,7 @@ def _reject_announce(announce_filename: str,
recent_posts_cache, debug)
# reject the post referenced by the announce activity object
if os.path.isfile(announce_filename + '.reject'):
if is_a_file(announce_filename + '.reject'):
return
save_flag_file(announce_filename + '.reject',
@ -6277,10 +6278,10 @@ def download_announce(session, base_dir: str, http_prefix: str,
announce_cache_dir + '/' + \
post_json_object['object'].replace('/', '#') + '.json'
if os.path.isfile(announce_filename + '.reject'):
if is_a_file(announce_filename + '.reject'):
return None
if os.path.isfile(announce_filename):
if is_a_file(announce_filename):
if debug:
print('Reading cached Announce content for ' +
post_json_object['object'])
@ -6735,12 +6736,12 @@ def is_muted_conv(base_dir: str, nickname: str, domain: str, post_id: str,
conv_muted_filename = \
acct_dir(base_dir, nickname, domain) + '/conversation/' + \
conversation_id.replace('/', '#') + '.muted'
if os.path.isfile(conv_muted_filename):
if is_a_file(conv_muted_filename):
return True
post_filename = locate_post(base_dir, nickname, domain, post_id)
if not post_filename:
return False
if os.path.isfile(post_filename + '.muted'):
if is_a_file(post_filename + '.muted'):
return True
return False
@ -6758,19 +6759,19 @@ def post_is_muted(base_dir: str, nickname: str, domain: str,
post_dir = acct_dir(base_dir, nickname, domain)
mute_filename = \
post_dir + '/inbox/' + message_id.replace('/', '#') + '.json.muted'
if os.path.isfile(mute_filename):
if is_a_file(mute_filename):
return True
is_muted: bool = False
mute_filename = \
post_dir + '/outbox/' + \
message_id.replace('/', '#') + '.json.muted'
if os.path.isfile(mute_filename):
if is_a_file(mute_filename):
is_muted = True
else:
mute_filename = \
data_dir(base_dir) + '/cache/announce/' + nickname + \
'/' + message_id.replace('/', '#') + '.json.muted'
if os.path.isfile(mute_filename):
if is_a_file(mute_filename):
is_muted = True
return is_muted
@ -6856,7 +6857,7 @@ def edited_post_filename(base_dir: str, nickname: str, domain: str,
actor_filename = \
acct_dir(base_dir, nickname, domain) + '/lastpost/' + \
actor.replace('/', '#')
if not os.path.isfile(actor_filename):
if not is_a_file(actor_filename):
return '', None
post_id = remove_id_ending(post_json_object['object']['id'])
lastpost_id = \
@ -6982,7 +6983,7 @@ def get_max_profile_posts(base_dir: str, nickname: str, domain: str,
max_posts_filename = \
acct_dir(base_dir, nickname, domain) + '/max_profile_posts.txt'
max_profile_posts: int = 4
if not os.path.isfile(max_posts_filename):
if not is_a_file(max_posts_filename):
return max_profile_posts
max_posts_str = \
load_string(max_posts_filename,

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "ActivityPub"
import os
from utils import locate_post
from utils import load_json
from utils import save_json
@ -19,6 +18,7 @@ from utils import get_actor_from_post
from data import load_list
from data import save_string
from data import append_string
from data import is_a_file
def is_vote(base_dir: str, nickname: str, domain: str,
@ -125,7 +125,7 @@ def question_update_votes(base_dir: str, nickname: str, domain: str,
voters_file_separator = ';;;'
voters_filename = question_post_filename.replace('.json', '.voters')
actor_url = get_actor_from_post(reply_json)
if not os.path.isfile(voters_filename):
if not is_a_file(voters_filename):
# create a new voters file
save_string(actor_url + voters_file_separator + reply_vote + '\n',
voters_filename,

View File

@ -7,12 +7,12 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Core"
import os
from utils import acct_dir
from utils import resembles_url
from utils import remove_html
from utils import text_in_file
from utils import has_object_dict
from data import is_a_file
def get_quote_toot_url(post_json_object: str) -> str:
@ -102,12 +102,12 @@ def quote_toots_allowed(base_dir: str, nickname: str, domain: str,
"""
account_dir = acct_dir(base_dir, nickname, domain)
quotes_enabled_filename = account_dir + '/.allowQuotes'
if os.path.isfile(quotes_enabled_filename):
if is_a_file(quotes_enabled_filename):
# check blocks on individual sending accounts
quotes_blocked_filename = account_dir + '/quotesblocked.txt'
if sender_nickname is None:
return True
if os.path.isfile(quotes_blocked_filename):
if is_a_file(quotes_blocked_filename):
sender_handle = sender_nickname + '@' + sender_domain
if text_in_file(sender_handle, quotes_blocked_filename, False):
# quote toots not permitted from this sender

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "ActivityPub"
import os
import re
import urllib.parse
from pprint import pprint
@ -41,6 +40,7 @@ from posts import get_person_box
from data import load_list
from data import save_string
from data import erase_file
from data import is_a_file
# the maximum number of reactions from individual actors which can be
# added to a post. Hence an adversary can't bombard you with sockpuppet
@ -486,7 +486,7 @@ def _update_common_reactions(base_dir: str, emoji_content: str) -> None:
"""
common_reactions_filename = data_dir(base_dir) + '/common_reactions.txt'
common_reactions = None
if os.path.isfile(common_reactions_filename):
if is_a_file(common_reactions_filename):
common_reactions: list[str] = \
load_list(common_reactions_filename,
'EX: unable to load common reactions file' +
@ -546,7 +546,7 @@ def update_reaction_collection(recent_posts_cache: {},
get_cached_post_filename(base_dir, nickname,
domain, post_json_object)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
erase_file(cached_post_filename,
'EX: update_reaction_collection unable to delete ' +
cached_post_filename)
@ -714,7 +714,7 @@ def undo_reaction_collection_entry(recent_posts_cache: {},
get_cached_post_filename(base_dir, nickname,
domain, post_json_object)
if cached_post_filename:
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
ex_text = \
'EX: undo_reaction_collection_entry ' + \
'unable to delete cached post ' + \

View File

@ -25,6 +25,7 @@ from timeFunctions import date_from_string_format
from data import save_string
from data import load_string
from data import prepend_string
from data import is_a_file
def get_book_link_from_content(content: str) -> str:
@ -273,7 +274,7 @@ def remove_reading_event(base_dir: str,
books_cache['readers'] = {}
if books_cache['readers'].get(actor):
reader_books_json = books_cache['readers'][actor]
elif os.path.isfile(reader_books_filename):
elif is_a_file(reader_books_filename):
# if not in cache then load from file
reader_books_json = load_json(reader_books_filename)
if not reader_books_json:
@ -396,7 +397,7 @@ def _update_recent_books_list(base_dir: str, book_id: str,
"""prepend a book to the recent books list
"""
recent_books_filename = data_dir(base_dir) + '/recent_books.txt'
if os.path.isfile(recent_books_filename):
if is_a_file(recent_books_filename):
ex_str: str = \
'EX: Failed to prepend entry to recent books ' + \
recent_books_filename + ' [ex]'
@ -414,7 +415,7 @@ def _deduplicate_recent_books_list(base_dir: str,
""" Deduplicate and limit the length of the recent books list
"""
recent_books_filename = data_dir(base_dir) + '/recent_books.txt'
if not os.path.isfile(recent_books_filename):
if not is_a_file(recent_books_filename):
return
# load recent books as a list
@ -497,7 +498,7 @@ def store_book_events(base_dir: str,
books_cache['readers'] = {}
if books_cache['readers'].get(actor):
reader_books_json = books_cache['readers'][actor]
elif os.path.isfile(reader_books_filename):
elif is_a_file(reader_books_filename):
# if not in cache then load from file
reader_books_json = load_json(reader_books_filename)
if _add_book_to_reader(reader_books_json, book_dict, debug):
@ -524,7 +525,7 @@ def store_book_events(base_dir: str,
book_id = book_url.replace('/', '#')
book_filename = books_path + '/' + book_id + '.json'
book_json = {}
if os.path.isfile(book_filename):
if is_a_file(book_filename):
book_json = load_json(book_filename)
_add_reader_to_book(book_json, book_dict)
if not save_json(book_json, book_filename):
@ -549,7 +550,7 @@ def html_profile_book_list(base_dir: str, actor: str, no_of_books: int,
reader_books_filename = \
readers_path + '/' + actor.replace('/', '#') + '.json'
reader_books_json = {}
if not os.path.isfile(reader_books_filename):
if not is_a_file(reader_books_filename):
return ''
reader_books_json = load_json(reader_books_filename)
if not reader_books_json.get('timeline'):

View File

@ -25,6 +25,7 @@ from utils import load_json
from data import load_string
from data import save_string
from data import erase_file
from data import is_a_file
def get_moved_accounts(base_dir: str, nickname: str, domain: str,
@ -32,7 +33,7 @@ def get_moved_accounts(base_dir: str, nickname: str, domain: str,
"""returns a dict of moved accounts
"""
moved_accounts_filename = data_dir(base_dir) + '/actors_moved.txt'
if not os.path.isfile(moved_accounts_filename):
if not is_a_file(moved_accounts_filename):
return {}
refollow_str = \
load_string(moved_accounts_filename,
@ -245,7 +246,7 @@ def update_moved_actors(base_dir: str, debug: bool) -> None:
if not is_account_dir(account):
continue
following_filename = dir_str + '/' + account + '/following.txt'
if not os.path.isfile(following_filename):
if not is_a_file(following_filename):
continue
following_str = \
load_string(following_filename,
@ -271,7 +272,7 @@ def update_moved_actors(base_dir: str, debug: bool) -> None:
if not actors_dict.get(handle):
continue
actor_filename = base_dir + '/cache/actors/' + actors_dict[handle]
if not os.path.isfile(actor_filename):
if not is_a_file(actor_filename):
continue
actor_json = load_json(actor_filename)
if not actor_json:
@ -306,7 +307,7 @@ def update_moved_actors(base_dir: str, debug: bool) -> None:
moved_accounts_filename = data_dir(base_dir) + '/actors_moved.txt'
if not moved_str:
if os.path.isfile(moved_accounts_filename):
if is_a_file(moved_accounts_filename):
erase_file(moved_accounts_filename,
'EX: update_moved_actors unable to remove ' +
moved_accounts_filename)

View File

@ -19,6 +19,7 @@ from status import get_status_number
from data import load_list
from data import save_string
from data import erase_file
from data import is_a_file
def _clear_role_status(base_dir: str, role: str) -> None:
@ -54,7 +55,7 @@ def _add_role(base_dir: str, nickname: str, domain: str,
"""
domain = remove_domain_port(domain)
role_file = data_dir(base_dir) + '/' + role_filename
if os.path.isfile(role_file):
if is_a_file(role_file):
# is this nickname already in the file?
lines: list[str] = \
@ -93,7 +94,7 @@ def _remove_role(base_dir: str, nickname: str, role_filename: str) -> None:
This is a file containing the nicknames of accounts having this role
"""
role_file = data_dir(base_dir) + '/' + role_filename
if not os.path.isfile(role_file):
if not is_a_file(role_file):
return
lines: list[str] = \
@ -224,7 +225,7 @@ def set_role(base_dir: str, nickname: str, domain: str,
if len(role) > 128:
return False
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if not os.path.isfile(actor_filename):
if not is_a_file(actor_filename):
return False
role_files = {
@ -274,7 +275,7 @@ def is_devops(base_dir: str, nickname: str) -> bool:
"""
devops_file = data_dir(base_dir) + '/devops.txt'
if not os.path.isfile(devops_file):
if not is_a_file(devops_file):
admin_name = get_config_param(base_dir, 'admin')
if not admin_name:
return False
@ -314,7 +315,7 @@ def set_roles_from_list(base_dir: str, domain: str, admin_nickname: str,
return
roles_filename = data_dir(base_dir) + '/' + list_filename
if not fields.get(list_name):
if os.path.isfile(roles_filename):
if is_a_file(roles_filename):
_clear_role_status(base_dir, role_name)
erase_file(roles_filename,
'EX: failed to remove roles file ' + roles_filename)

View File

@ -28,6 +28,7 @@ from data import save_string
from data import load_list
from data import erase_file
from data import move_file
from data import is_a_file
def _update_post_schedule(base_dir: str, handle: str, httpd,
@ -37,7 +38,7 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
"""
schedule_index_filename = \
acct_handle_dir(base_dir, handle) + '/schedule.index'
if not os.path.isfile(schedule_index_filename):
if not is_a_file(schedule_index_filename):
return
# get the current time as an int
@ -65,7 +66,7 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
post_filename = schedule_dir + post_id + '.json'
if delete_schedule_post:
# delete extraneous scheduled posts
if os.path.isfile(post_filename):
if is_a_file(post_filename):
ex_text = \
'EX: ' + \
'_update_post_schedule unable to delete ' + \
@ -87,7 +88,7 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
continue
if curr_time.time().minute < post_time.time().minute:
continue
if not os.path.isfile(post_filename):
if not is_a_file(post_filename):
print('WARN: schedule missing post_filename=' +
post_filename)
index_lines.remove(line)
@ -220,7 +221,7 @@ def run_post_schedule(base_dir: str, httpd, max_scheduled_posts: int):
# scheduled posts index for this account
schedule_index_filename = \
dir_str + '/' + account + '/schedule.index'
if not os.path.isfile(schedule_index_filename):
if not is_a_file(schedule_index_filename):
continue
_update_post_schedule(base_dir, account,
httpd, max_scheduled_posts)
@ -259,7 +260,7 @@ def remove_scheduled_posts(base_dir: str, nickname: str, domain: str) -> None:
# remove the index
schedule_index_filename = \
acct_dir(base_dir, nickname, domain) + '/schedule.index'
if os.path.isfile(schedule_index_filename):
if is_a_file(schedule_index_filename):
erase_file(schedule_index_filename,
'EX: remove_scheduled_posts unable to delete ' +
schedule_index_filename)
@ -269,7 +270,7 @@ def remove_scheduled_posts(base_dir: str, nickname: str, domain: str) -> None:
return
for scheduled_post_filename in os.listdir(scheduled_dir):
file_path = os.path.join(scheduled_dir, scheduled_post_filename)
if not os.path.isfile(file_path):
if not is_a_file(file_path):
continue
erase_file(file_path,
'EX: remove_scheduled_posts unable to delete ' +

View File

@ -22,6 +22,7 @@ from utils import get_followers_list
from utils import get_mutuals_of_person
from data import load_string
from data import save_string
from data import is_a_file
def load_searchable_by_default(base_dir: str) -> {}:
@ -35,7 +36,7 @@ def load_searchable_by_default(base_dir: str) -> {}:
continue
nickname = account.split('@')[0]
filename = os.path.join(dir_str, account) + '/.searchableByDefault'
if os.path.isfile(filename):
if is_a_file(filename):
text = load_string(filename,
'EX: unable to load searchableByDefault ' +
filename)
@ -55,7 +56,7 @@ def set_searchable_by(base_dir: str, nickname: str, domain: str,
filename = acct_dir(base_dir, nickname, domain) + '/.searchableByDefault'
# already the same state?
if os.path.isfile(filename):
if is_a_file(filename):
if text_in_file(searchable_by, filename, True):
return
@ -118,7 +119,7 @@ def _search_virtual_box_posts(base_dir: str, nickname: str, domain: str,
if '.json' not in post_filename:
break
post_filename = path + '/' + post_filename.strip()
if not os.path.isfile(post_filename):
if not is_a_file(post_filename):
continue
data = load_string(post_filename,
'EX: _search_virtual_box_posts ' +
@ -151,7 +152,7 @@ def search_box_posts(base_dir: str, nickname: str, domain: str,
path = acct_dir(base_dir, nickname, domain) + '/' + box_name
# is this a virtual box, such as direct messages?
if not os.path.isdir(path):
if os.path.isfile(path + '.index'):
if is_a_file(path + '.index'):
return _search_virtual_box_posts(base_dir, nickname, domain,
search_str, max_results, box_name)
return []

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Session"
import os
import requests
import json
import errno
@ -31,6 +30,7 @@ from data import save_string
from data import save_binary
from data import load_binary
from data import erase_file
from data import is_a_file
def create_session(proxy_type: str):
@ -552,7 +552,7 @@ def site_is_verified(session, base_dir: str, http_prefix: str,
verified_sites_filename = \
acct_dir(base_dir, nickname, domain) + '/verified_sites.txt'
verified_file_exists: bool = False
if os.path.isfile(verified_sites_filename):
if is_a_file(verified_sites_filename):
verified_file_exists = True
if text_in_file(url + '\n', verified_sites_filename, True):
return True
@ -748,7 +748,7 @@ def post_image(session, attach_image_filename: str, federation_list: [],
if not is_image_file(attach_image_filename):
print('Image must be png, jpg, jxl, webp, avif, heic, gif or svg')
return None
if not os.path.isfile(attach_image_filename):
if not is_a_file(attach_image_filename):
print('Image not found: ' + attach_image_filename)
return None
content_type = 'image/jpeg'
@ -832,7 +832,7 @@ def download_image(session, url: str, image_filename: str, debug: bool,
print('download_image: no session headers')
return False
if not os.path.isfile(image_filename) or force:
if not is_a_file(image_filename) or force:
try:
if debug:
print('Downloading image url: ' + url)
@ -846,7 +846,7 @@ def download_image(session, url: str, image_filename: str, debug: bool,
print('Image download failed with status ' +
str(result.status_code))
# remove partial download
if os.path.isfile(image_filename):
if is_a_file(image_filename):
erase_file(image_filename,
'EX: download_image unable to delete ' +
image_filename)

View File

@ -63,6 +63,7 @@ from cache import store_person_in_cache
from data import save_string
from data import load_string
from data import erase_file
from data import is_a_file
def _load_dfc_ids(base_dir: str, system_language: str,
@ -73,7 +74,7 @@ def _load_dfc_ids(base_dir: str, system_language: str,
"""
product_types_filename = \
base_dir + '/ontology/custom' + product_type.title() + 'Types.json'
if not os.path.isfile(product_types_filename):
if not is_a_file(product_types_filename):
product_types_filename = \
base_dir + '/ontology/' + product_type + 'Types.json'
product_types = load_json(product_types_filename)
@ -150,7 +151,7 @@ def remove_shared_item2(base_dir: str, nickname: str, domain: str,
"""
shares_filename = \
acct_dir(base_dir, nickname, domain) + '/' + shares_file_type + '.json'
if not os.path.isfile(shares_filename):
if not is_a_file(shares_filename):
print('ERROR: remove shared item, missing ' +
shares_file_type + '.json ' + shares_filename)
return
@ -170,7 +171,7 @@ def remove_shared_item2(base_dir: str, nickname: str, domain: str,
for ext in formats:
if not shares_json[item_id]['imageUrl'].endswith('.' + ext):
continue
if not os.path.isfile(item_idfile + '.' + ext):
if not is_a_file(item_idfile + '.' + ext):
continue
erase_file(item_idfile + '.' + ext,
'EX: remove_shared_item unable to delete ' +
@ -309,7 +310,7 @@ def _indicate_new_share_available(base_dir: str, http_prefix: str,
new_share_file = account_dir + '/.newShare'
else:
new_share_file = account_dir + '/.newWanted'
if os.path.isfile(new_share_file):
if is_a_file(new_share_file):
continue
account_nickname = handle.split('@')[0]
# does this account block you?
@ -352,7 +353,7 @@ def add_share(base_dir: str,
shares_filename = \
acct_dir(base_dir, nickname, domain) + '/' + shares_file_type + '.json'
shares_json = {}
if os.path.isfile(shares_filename):
if is_a_file(shares_filename):
shares_json = load_json(shares_filename)
duration = duration.lower()
@ -374,7 +375,7 @@ def add_share(base_dir: str,
acct_dir(base_dir, nickname, domain) + '/upload'
formats = get_image_extensions()
for ext in formats:
if not os.path.isfile(shares_image_filename + '.' + ext):
if not is_a_file(shares_image_filename + '.' + ext):
continue
image_filename = shares_image_filename + '.' + ext
move_image = True
@ -383,7 +384,7 @@ def add_share(base_dir: str,
# copy or move the image for the shared item to its destination
if image_filename:
if os.path.isfile(image_filename):
if is_a_file(image_filename):
if not os.path.isdir(base_dir + '/sharefiles'):
os.mkdir(base_dir + '/sharefiles')
if not os.path.isdir(base_dir + '/sharefiles/' + nickname):
@ -456,7 +457,7 @@ def expire_shares(base_dir: str, max_shares_on_profile: int,
continue
# regenerate shared items within actor attachment
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if not os.path.isfile(actor_filename):
if not is_a_file(actor_filename):
continue
actor_json = load_json(actor_filename)
if not actor_json:
@ -484,7 +485,7 @@ def _expire_shares_for_account(base_dir: str, nickname: str, domain: str,
handle = nickname + '@' + handle_domain
shares_filename = \
acct_handle_dir(base_dir, handle) + '/' + shares_file_type + '.json'
if not os.path.isfile(shares_filename):
if not is_a_file(shares_filename):
return 0
shares_json = load_json(shares_filename)
if not shares_json:
@ -503,7 +504,7 @@ def _expire_shares_for_account(base_dir: str, nickname: str, domain: str,
item_idfile = base_dir + '/sharefiles/' + nickname + '/' + item_id
formats = get_image_extensions()
for ext in formats:
if not os.path.isfile(item_idfile + '.' + ext):
if not is_a_file(item_idfile + '.' + ext):
continue
erase_file(item_idfile + '.' + ext,
'EX: _expire_shares_for_account unable to delete ' +
@ -563,7 +564,7 @@ def get_shares_feed_for_person(base_dir: str,
if header_only:
no_of_shares: int = 0
if os.path.isfile(shares_filename):
if is_a_file(shares_filename):
shares_json = load_json(shares_filename)
if shares_json:
no_of_shares = len(shares_json.items())
@ -600,7 +601,7 @@ def get_shares_feed_for_person(base_dir: str,
'type': 'OrderedCollectionPage'
}
if not os.path.isfile(shares_filename):
if not is_a_file(shares_filename):
return shares
curr_page: int = 1
page_ctr: int = 0
@ -1367,7 +1368,7 @@ def shares_catalog_account_endpoint(base_dir: str, http_prefix: str,
shares_filename = \
acct_dir(base_dir, nickname, domain) + '/' + shares_file_type + '.json'
if not os.path.isfile(shares_filename):
if not is_a_file(shares_filename):
if debug:
print(shares_file_type + '.json file not found: ' +
shares_filename)
@ -1465,7 +1466,7 @@ def shares_catalog_endpoint(base_dir: str, http_prefix: str,
shares_filename = \
acct_dir(base_dir, nickname, domain) + '/' + \
shares_file_type + '.json'
if not os.path.isfile(shares_filename):
if not is_a_file(shares_filename):
continue
print('Test 78363 ' + shares_filename)
shares_json = load_json(shares_filename)
@ -1559,7 +1560,7 @@ def generate_shared_item_federation_tokens(shared_items_federated_domains: [],
if base_dir:
tokens_filename = \
data_dir(base_dir) + '/sharedItemsFederationTokens.json'
if os.path.isfile(tokens_filename):
if is_a_file(tokens_filename):
tokens_json = load_json(tokens_filename)
if tokens_json is None:
tokens_json = {}
@ -1590,7 +1591,7 @@ def update_shared_item_federation_token(base_dir: str,
if base_dir:
tokens_filename = \
data_dir(base_dir) + '/sharedItemsFederationTokens.json'
if os.path.isfile(tokens_filename):
if is_a_file(tokens_filename):
if debug:
print('Update loading tokens for ' + token_domain_full)
tokens_json = load_json(tokens_filename)
@ -1650,7 +1651,7 @@ def create_shared_item_federation_token(base_dir: str,
if base_dir:
tokens_filename = \
data_dir(base_dir) + '/sharedItemsFederationTokens.json'
if os.path.isfile(tokens_filename):
if is_a_file(tokens_filename):
tokens_json = load_json(tokens_filename)
if tokens_json is None:
tokens_json = {}
@ -1696,7 +1697,7 @@ def authorize_shared_items(shared_items_federated_domains: [],
if not tokens_json:
tokens_filename = \
data_dir(base_dir) + '/sharedItemsFederationTokens.json'
if not os.path.isfile(tokens_filename):
if not is_a_file(tokens_filename):
if debug:
print('DEBUG: shared item federation tokens file missing ' +
tokens_filename)
@ -1825,7 +1826,7 @@ def _generate_next_shares_token_update(base_dir: str,
os.mkdir(token_update_dir)
token_update_filename = token_update_dir + '/.tokenUpdate'
next_update_sec = None
if os.path.isfile(token_update_filename):
if is_a_file(token_update_filename):
next_update_str = \
load_string(token_update_filename,
'EX: _generate_next_shares_token_update ' +
@ -1872,7 +1873,7 @@ def _regenerate_shares_token(base_dir: str, domain_full: str,
then they will receive the new token automatically
"""
token_update_filename = data_dir(base_dir) + '/.tokenUpdate'
if not os.path.isfile(token_update_filename):
if not is_a_file(token_update_filename):
return
next_update_sec = None
next_update_str = \
@ -1935,7 +1936,7 @@ def run_federated_shares_daemon(base_dir: str, httpd, http_prefix: str,
# load the tokens
tokens_filename = \
data_dir(base_dir) + '/sharedItemsFederationTokens.json'
if not os.path.isfile(tokens_filename):
if not is_a_file(tokens_filename):
time.sleep(file_check_interval_sec)
continue
tokens_json = load_json(tokens_filename)
@ -2256,7 +2257,7 @@ def get_share_category(base_dir: str, nickname: str, domain: str,
"""
shares_filename = \
acct_dir(base_dir, nickname, domain) + '/' + shares_file_type + '.json'
if not os.path.isfile(shares_filename):
if not is_a_file(shares_filename):
return ''
shares_json = load_json(shares_filename)
@ -2276,7 +2277,7 @@ def vf_proposal_from_id(base_dir: str, nickname: str, domain: str,
"""
shares_filename = \
acct_dir(base_dir, nickname, domain) + '/' + shares_file_type + '.json'
if not os.path.isfile(shares_filename):
if not is_a_file(shares_filename):
print('DEBUG: vf_proposal_from_id file not found ' + shares_filename)
return {}
@ -2390,7 +2391,7 @@ def add_shares_to_actor(base_dir: str,
# do shared items exist for this account?
shares_filename = \
acct_dir(base_dir, nickname, domain) + '/shares.json'
if not os.path.isfile(shares_filename):
if not is_a_file(shares_filename):
return changed
shares_json = load_json(shares_filename)
if not shares_json:

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Profile Metadata"
import os
from webfinger import webfinger_handle
from auth import create_basic_auth_header
from posts import get_person_box
@ -23,6 +22,7 @@ from utils import acct_dir
from utils import local_actor_url
from utils import has_actor
from utils import get_actor_from_post
from data import is_a_file
def set_skills_from_dict(actor_json: {}, skills_dict: {}) -> []:
@ -121,7 +121,7 @@ def set_skill_level(base_dir: str, nickname: str, domain: str,
if skill_level_percent < 0 or skill_level_percent > 100:
return False
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if not os.path.isfile(actor_filename):
if not is_a_file(actor_filename):
return False
actor_json = load_json(actor_filename)
@ -133,7 +133,7 @@ def get_skills(base_dir: str, nickname: str, domain: str) -> []:
"""Returns the skills for a given person
"""
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if not os.path.isfile(actor_filename):
if not is_a_file(actor_filename):
return False
actor_json = load_json(actor_filename)

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Accessibility"
import os
import html
import random
import urllib.parse
@ -35,6 +34,7 @@ from content import html_replace_inline_quotes
from data import load_list
from data import load_string
from data import save_string
from data import is_a_file
SPEAKER_REMOVE_CHARS = ('.\n', '. ', ',', ';', '?', '!')
@ -153,7 +153,7 @@ def _speaker_pronounce(base_dir: str, say_text: str, translate: {}) -> str:
"(": ",",
")": ","
}
if os.path.isfile(pronounce_filename):
if is_a_file(pronounce_filename):
pronounce_list: list[str] = \
load_list(pronounce_filename,
'EX: _speaker_pronounce unable to read ' +
@ -391,7 +391,7 @@ def get_ssml_box(base_dir: str, path: str,
nickname = nickname.split('/')[0]
speaker_filename = \
acct_dir(base_dir, nickname, domain) + '/speaker.json'
if not os.path.isfile(speaker_filename):
if not is_a_file(speaker_filename):
return None
speaker_json = load_json(speaker_filename)
if not speaker_json:
@ -541,7 +541,7 @@ def _post_to_speaker_json(base_dir: str, http_prefix: str,
follow_requests_list: list[str] = []
accounts_dir = acct_dir(base_dir, nickname, domain_full)
approve_follows_filename = accounts_dir + '/followrequests.txt'
if os.path.isfile(approve_follows_filename):
if is_a_file(approve_follows_filename):
follows: list[str] = \
load_list(approve_follows_filename,
'EX: _post_to_speaker_json unable to read ' +
@ -553,24 +553,24 @@ def _post_to_speaker_json(base_dir: str, http_prefix: str,
follow_requests_list = follows
post_dm: bool = False
dm_filename = accounts_dir + '/.newDM'
if os.path.isfile(dm_filename):
if is_a_file(dm_filename):
post_dm = True
post_reply: bool = False
reply_filename = accounts_dir + '/.newReply'
if os.path.isfile(reply_filename):
if is_a_file(reply_filename):
post_reply = True
liked_by = ''
like_filename = accounts_dir + '/.newLike'
if os.path.isfile(like_filename):
if is_a_file(like_filename):
liked_by = load_string(like_filename,
'EX: _post_to_speaker_json unable to read 2 ' +
like_filename)
if liked_by is None:
liked_by = ''
calendar_filename = accounts_dir + '/.newCalendar'
post_cal = os.path.isfile(calendar_filename)
post_cal = is_a_file(calendar_filename)
share_filename = accounts_dir + '/.newShare'
post_share = os.path.isfile(share_filename)
post_share = is_a_file(share_filename)
return _speaker_endpoint_json(speaker_name, summary,
content, say_content, image_description,

View File

@ -7,11 +7,11 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Web Interface"
import os
from shutil import copyfile
from utils import data_dir
from data import load_string
from data import erase_file
from data import is_a_file
def text_mode_browser(ua_str: str) -> bool:
@ -44,7 +44,7 @@ def get_text_mode_banner(base_dir: str) -> str:
"""Returns the banner used for shell browsers, like Lynx
"""
text_mode_banner_filename = data_dir(base_dir) + '/banner.txt'
if os.path.isfile(text_mode_banner_filename):
if is_a_file(text_mode_banner_filename):
banner_str = load_string(text_mode_banner_filename,
'EX: unable to load text mode banner ' +
text_mode_banner_filename)
@ -57,7 +57,7 @@ def get_text_mode_logo(base_dir: str) -> str:
"""Returns the login screen logo used for shell browsers, like Lynx
"""
text_mode_logo_filename = data_dir(base_dir) + '/logo.txt'
if not os.path.isfile(text_mode_logo_filename):
if not is_a_file(text_mode_logo_filename):
text_mode_logo_filename = base_dir + '/img/logo.txt'
logo_str = load_string(text_mode_logo_filename,
@ -74,7 +74,7 @@ def set_text_mode_theme(base_dir: str, name: str) -> None:
text_mode_logo_filename = \
base_dir + '/theme/' + name + '/logo.txt'
dir_str = data_dir(base_dir)
if os.path.isfile(text_mode_logo_filename):
if is_a_file(text_mode_logo_filename):
try:
copyfile(text_mode_logo_filename, dir_str + '/logo.txt')
except OSError:
@ -92,11 +92,11 @@ def set_text_mode_theme(base_dir: str, name: str) -> None:
# set the text mode banner which appears in browsers such as Lynx
text_mode_banner_filename = \
base_dir + '/theme/' + name + '/banner.txt'
if os.path.isfile(dir_str + '/banner.txt'):
if is_a_file(dir_str + '/banner.txt'):
erase_file(dir_str + '/banner.txt',
'EX: set_text_mode_theme unable to delete ' +
dir_str + '/banner.txt')
if os.path.isfile(text_mode_banner_filename):
if is_a_file(text_mode_banner_filename):
try:
copyfile(text_mode_banner_filename, dir_str + '/banner.txt')
except OSError:

View File

@ -32,12 +32,13 @@ from data import load_string
from data import save_string
from data import save_flag_file
from data import erase_file
from data import is_a_file
def import_theme(base_dir: str, filename: str) -> bool:
"""Imports a theme
"""
if not os.path.isfile(filename):
if not is_a_file(filename):
return False
temp_theme_dir = base_dir + '/imports/files'
if os.path.isdir(temp_theme_dir):
@ -46,7 +47,7 @@ def import_theme(base_dir: str, filename: str) -> bool:
unpack_archive(filename, temp_theme_dir, 'zip')
essential_theme_files = ('name.txt', 'theme.json')
for theme_file in essential_theme_files:
if not os.path.isfile(temp_theme_dir + '/' + theme_file):
if not is_a_file(temp_theme_dir + '/' + theme_file):
print('WARN: ' + theme_file +
' missing from imported theme')
return False
@ -79,7 +80,7 @@ def import_theme(base_dir: str, filename: str) -> bool:
# if the theme name in the default themes list?
default_themes_filename = base_dir + '/defaultthemes.txt'
if os.path.isfile(default_themes_filename):
if is_a_file(default_themes_filename):
test_str = new_theme_name.title() + '\n'
if text_in_file(test_str, default_themes_filename):
new_theme_name = new_theme_name + '2'
@ -93,19 +94,19 @@ def import_theme(base_dir: str, filename: str) -> bool:
if scan_themes_for_scripts(theme_dir):
rmtree(theme_dir, ignore_errors=False, onexc=None)
return False
return os.path.isfile(theme_dir + '/theme.json')
return is_a_file(theme_dir + '/theme.json')
def export_theme(base_dir: str, theme: str) -> bool:
"""Exports a theme as a zip file
"""
theme_dir = base_dir + '/theme/' + theme
if not os.path.isfile(theme_dir + '/theme.json'):
if not is_a_file(theme_dir + '/theme.json'):
return False
if not os.path.isdir(base_dir + '/exports'):
os.mkdir(base_dir + '/exports')
export_filename = base_dir + '/exports/' + theme + '.zip'
if os.path.isfile(export_filename):
if is_a_file(export_filename):
ex_text = \
'EX: export_theme unable to delete ' + str(export_filename)
erase_file(export_filename, ex_text)
@ -114,7 +115,7 @@ def export_theme(base_dir: str, theme: str) -> bool:
except BaseException:
print('EX: export_theme unable to archive ' +
base_dir + '/exports/' + str(theme))
return os.path.isfile(export_filename)
return is_a_file(export_filename)
def _get_theme_files() -> []:
@ -130,7 +131,7 @@ def is_news_theme_name(base_dir: str, theme_name: str) -> bool:
"""Returns true if the given theme is a news instance
"""
theme_dir = base_dir + '/theme/' + theme_name
if os.path.isfile(theme_dir + '/is_news_instance'):
if is_a_file(theme_dir + '/is_news_instance'):
return True
return False
@ -182,7 +183,7 @@ def _set_theme_in_config(base_dir: str, name: str) -> bool:
"""Sets the theme with the given name within config.json
"""
config_filename = base_dir + '/config.json'
if not os.path.isfile(config_filename):
if not is_a_file(config_filename):
return False
config_json = load_json(config_filename)
if not config_json:
@ -195,7 +196,7 @@ def _set_newswire_publish_as_icon(base_dir: str, use_icon: bool) -> bool:
"""Shows the newswire publish action as an icon or a button
"""
config_filename = base_dir + '/config.json'
if not os.path.isfile(config_filename):
if not is_a_file(config_filename):
return False
config_json = load_json(config_filename)
if not config_json:
@ -208,7 +209,7 @@ def _set_rss_icon_at_top(base_dir: str, at_top: bool) -> bool:
"""Whether to show RSS icon at the top of the timeline
"""
config_filename = base_dir + '/config.json'
if not os.path.isfile(config_filename):
if not is_a_file(config_filename):
return False
config_json = load_json(config_filename)
if not config_json:
@ -222,7 +223,7 @@ def _set_publish_button_at_top(base_dir: str, at_top: bool) -> bool:
in the newswire column
"""
config_filename = base_dir + '/config.json'
if not os.path.isfile(config_filename):
if not is_a_file(config_filename):
return False
config_json = load_json(config_filename)
if not config_json:
@ -237,7 +238,7 @@ def _set_full_width_timeline_button_header(base_dir: str,
calendar, etc as full width
"""
config_filename = base_dir + '/config.json'
if not os.path.isfile(config_filename):
if not is_a_file(config_filename):
return False
config_json = load_json(config_filename)
if not config_json:
@ -250,7 +251,7 @@ def get_theme(base_dir: str) -> str:
"""Gets the current theme name from config.json
"""
config_filename = base_dir + '/config.json'
if os.path.isfile(config_filename):
if is_a_file(config_filename):
config_json = load_json(config_filename)
if config_json:
if config_json.get('theme'):
@ -263,7 +264,7 @@ def _remove_theme(base_dir: str):
"""
theme_files = _get_theme_files()
for filename in theme_files:
if not os.path.isfile(base_dir + '/' + filename):
if not is_a_file(base_dir + '/' + filename):
continue
erase_file(base_dir + '/' + filename,
'EX: _remove_theme unable to delete ' +
@ -342,13 +343,13 @@ def _set_theme_from_dict(base_dir: str, name: str,
# Ensure that any custom CSS is mostly harmless.
# If not then just use the defaults
if dangerous_css(template_filename, allow_local_network_access) or \
not os.path.isfile(template_filename):
not is_a_file(template_filename):
# use default css
template_filename = base_dir + '/epicyon-' + filename
if filename == 'epicyon.css':
template_filename = base_dir + '/epicyon-profile.css'
if not os.path.isfile(template_filename):
if not is_a_file(template_filename):
continue
css: str = load_string(template_filename,
@ -406,7 +407,7 @@ def _set_background_format(base_dir: str,
if extension == 'jpg':
return
css_filename = base_dir + '/' + background_type + '.css'
if not os.path.isfile(css_filename):
if not is_a_file(css_filename):
return
css = load_string(css_filename,
@ -424,7 +425,7 @@ def enable_grayscale(base_dir: str) -> None:
theme_files = _get_theme_files()
for filename in theme_files:
template_filename = base_dir + '/' + filename
if not os.path.isfile(template_filename):
if not is_a_file(template_filename):
continue
css = load_string(template_filename,
'EX: enable_grayscale unable to read ' +
@ -441,7 +442,7 @@ def enable_grayscale(base_dir: str) -> None:
'EX: enable_grayscale unable to save ' +
filename + ' [ex]')
grayscale_filename = data_dir(base_dir) + '/.grayscale'
if not os.path.isfile(grayscale_filename):
if not is_a_file(grayscale_filename):
save_flag_file(grayscale_filename,
'EX: enable_grayscale unable to write ' +
grayscale_filename + ' [ex]')
@ -453,7 +454,7 @@ def disable_grayscale(base_dir: str) -> None:
theme_files = _get_theme_files()
for filename in theme_files:
template_filename = base_dir + '/' + filename
if not os.path.isfile(template_filename):
if not is_a_file(template_filename):
continue
css = load_string(template_filename,
'EX: disable_grayscale unable to read ' +
@ -468,7 +469,7 @@ def disable_grayscale(base_dir: str) -> None:
'EX: disable_grayscale unable to save ' +
filename + ' [ex]')
grayscale_filename = data_dir(base_dir) + '/.grayscale'
if os.path.isfile(grayscale_filename):
if is_a_file(grayscale_filename):
erase_file(grayscale_filename,
'EX: disable_grayscale unable to delete ' +
grayscale_filename)
@ -480,7 +481,7 @@ def _set_dyslexic_font(base_dir: str) -> bool:
theme_files = _get_theme_files()
for filename in theme_files:
template_filename = base_dir + '/' + filename
if not os.path.isfile(template_filename):
if not is_a_file(template_filename):
continue
css = load_string(template_filename,
@ -513,7 +514,7 @@ def _set_custom_font(base_dir: str):
}
for ext, ext_type in font_extension.items():
filename = base_dir + '/fonts/custom.' + ext
if os.path.isfile(filename):
if is_a_file(filename):
custom_font_ext = ext
custom_font_type = ext_type
if not custom_font_ext:
@ -522,7 +523,7 @@ def _set_custom_font(base_dir: str):
theme_files = _get_theme_files()
for filename in theme_files:
template_filename = base_dir + '/' + filename
if not os.path.isfile(template_filename):
if not is_a_file(template_filename):
continue
css = load_string(template_filename,
@ -559,7 +560,7 @@ def reset_theme_designer_settings(base_dir: str) -> None:
"""Resets the theme designer settings
"""
custom_variables_file = data_dir(base_dir) + '/theme.json'
if os.path.isfile(custom_variables_file):
if is_a_file(custom_variables_file):
if erase_file(custom_variables_file,
'EX: ' +
'unable to remove theme designer settings on reset'):
@ -578,7 +579,7 @@ def _read_variables_file(base_dir: str, theme_name: str,
# set custom theme parameters
custom_variables_file = data_dir(base_dir) + '/theme.json'
if os.path.isfile(custom_variables_file):
if is_a_file(custom_variables_file):
custom_theme_params = load_json(custom_variables_file)
if custom_theme_params:
for variable_name, value in custom_theme_params.items():
@ -601,7 +602,7 @@ def _set_theme_default(base_dir: str, allow_local_network_access: bool,
_set_theme_in_config(base_dir, name)
variables_file = base_dir + '/theme/' + name + '/theme.json'
if os.path.isfile(variables_file):
if is_a_file(variables_file):
_read_variables_file(base_dir, name, variables_file,
allow_local_network_access,
system_language)
@ -640,7 +641,7 @@ def _set_theme_fonts(base_dir: str, theme_name: str) -> None:
for filename in files:
if string_ends_with(filename, ('.woff2', '.woff', '.ttf', '.otf')):
dest_filename = fonts_dir + '/' + filename
if os.path.isfile(dest_filename):
if is_a_file(dest_filename):
# font already exists in the destination location
continue
copyfile(theme_fonts_dir + '/' + filename,
@ -690,7 +691,7 @@ def _set_theme_images(base_dir: str, name: str) -> None:
base_dir + '/theme/' + theme_name_lower + '/' + \
background_type + '_background' + '.' + ext
if os.path.isfile(background_image_filename):
if is_a_file(background_image_filename):
try:
copyfile(background_image_filename,
dir_str + '/' +
@ -701,16 +702,16 @@ def _set_theme_images(base_dir: str, name: str) -> None:
background_image_filename)
# background image was not found
# so remove any existing file
if os.path.isfile(dir_str + '/' +
background_type + '-background.' + ext):
if is_a_file(dir_str + '/' +
background_type + '-background.' + ext):
erase_file(dir_str + '/' +
background_type + '-background.' + ext,
'EX: _set_theme_images unable to delete ' +
dir_str + '/' +
background_type + '-background.' + ext)
if os.path.isfile(profile_image_filename) and \
os.path.isfile(banner_filename):
if is_a_file(profile_image_filename) and \
is_a_file(banner_filename):
try:
copyfile(profile_image_filename,
account_dir + '/image.png')
@ -726,7 +727,7 @@ def _set_theme_images(base_dir: str, name: str) -> None:
banner_filename)
try:
if os.path.isfile(search_banner_filename):
if is_a_file(search_banner_filename):
copyfile(search_banner_filename,
account_dir + '/search_banner.png')
except OSError:
@ -734,11 +735,10 @@ def _set_theme_images(base_dir: str, name: str) -> None:
search_banner_filename)
try:
if os.path.isfile(left_col_image_filename):
if is_a_file(left_col_image_filename):
copyfile(left_col_image_filename,
account_dir + '/left_col_image.png')
elif os.path.isfile(account_dir +
'/left_col_image.png'):
elif is_a_file(account_dir + '/left_col_image.png'):
erase_file(account_dir + '/left_col_image.png',
'EX: _set_theme_images unable to delete ' +
account_dir + '/left_col_image.png')
@ -747,12 +747,11 @@ def _set_theme_images(base_dir: str, name: str) -> None:
left_col_image_filename)
try:
if os.path.isfile(right_col_image_filename):
if is_a_file(right_col_image_filename):
copyfile(right_col_image_filename,
account_dir + '/right_col_image.png')
else:
if os.path.isfile(account_dir +
'/right_col_image.png'):
if is_a_file(account_dir + '/right_col_image.png'):
erase_file(account_dir + '/right_col_image.png',
'EX: _set_theme_images ' +
'unable to delete ' +
@ -770,16 +769,16 @@ def set_news_avatar(base_dir: str, name: str,
"""
nickname = 'news'
new_filename = base_dir + '/theme/' + name + '/icons/avatar_news.png'
if not os.path.isfile(new_filename):
if not is_a_file(new_filename):
new_filename = base_dir + '/theme/default/icons/avatar_news.png'
if not os.path.isfile(new_filename):
if not is_a_file(new_filename):
return
avatar_filename = \
local_actor_url(http_prefix, domain_full, nickname) + '.png'
avatar_filename = avatar_filename.replace('/', '-')
filename = base_dir + '/cache/avatars/' + avatar_filename
if os.path.isfile(filename):
if is_a_file(filename):
erase_file(filename,
'EX: set_news_avatar unable to delete ' + filename)
if os.path.isdir(base_dir + '/cache/avatars'):
@ -839,7 +838,7 @@ def set_theme(base_dir: str, name: str, domain: str,
# read theme settings from a json file in the theme directory
variables_file = base_dir + '/theme/' + name + '/theme.json'
if os.path.isfile(variables_file):
if is_a_file(variables_file):
_read_variables_file(base_dir, name, variables_file,
allow_local_network_access,
system_language)
@ -854,12 +853,12 @@ def set_theme(base_dir: str, name: str, domain: str,
base_dir + '/theme/' + name + '/icons/avatar_news.png'
dir_str = data_dir(base_dir)
if os.path.isdir(dir_str + '/news@' + domain):
if os.path.isfile(news_avatar_theme_filename):
if is_a_file(news_avatar_theme_filename):
news_avatar_filename = dir_str + '/news@' + domain + '/avatar.png'
copyfile(news_avatar_theme_filename, news_avatar_filename)
grayscale_filename = dir_str + '/.grayscale'
if os.path.isfile(grayscale_filename):
if is_a_file(grayscale_filename):
enable_grayscale(base_dir)
else:
disable_grayscale(base_dir)

View File

@ -16,6 +16,7 @@ from utils import data_dir
from utils import has_object_dict
from data import load_string
from data import save_string
from data import is_a_file
def convert_published_to_local_timezone(published, timezone: str) -> str:
@ -126,7 +127,7 @@ def get_account_timezone(base_dir: str, nickname: str, domain: str) -> str:
"""
tz_filename = \
acct_dir(base_dir, nickname, domain) + '/timezone.txt'
if not os.path.isfile(tz_filename):
if not is_a_file(tz_filename):
return None
timezone = load_string(tz_filename,
'EX: get_account_timezone unable to read ' +
@ -161,7 +162,7 @@ def load_account_timezones(base_dir: str) -> {}:
continue
acct_directory = os.path.join(dir_str, acct)
tz_filename = acct_directory + '/timezone.txt'
if not os.path.isfile(tz_filename):
if not is_a_file(tz_filename):
continue
timezone = \
load_string(tz_filename,

121
utils.py
View File

@ -28,6 +28,7 @@ from data import save_flag_file
from data import load_string
from data import append_string
from data import erase_file
from data import is_a_file
VALID_HASHTAG_CHARS = \
set('_0123456789' +
@ -468,7 +469,7 @@ def set_accounts_data_dir(base_dir: str, accounts_data_path: str) -> None:
return
accounts_data_path_filename = base_dir + '/data_path.txt'
if os.path.isfile(accounts_data_path_filename):
if is_a_file(accounts_data_path_filename):
# read the existing path
path: str = load_string(accounts_data_path_filename,
'EX: unable to read ' +
@ -497,7 +498,7 @@ def data_dir(base_dir: str) -> str:
# is an alternative path set?
accounts_data_path_filename: str = base_dir + '/data_path.txt'
if os.path.isfile(accounts_data_path_filename):
if is_a_file(accounts_data_path_filename):
path: str = load_string(accounts_data_path_filename,
'EX: unable to read ' +
accounts_data_path_filename)
@ -524,7 +525,7 @@ def refresh_newswire(base_dir: str) -> None:
"""Causes the newswire to be updates after a change to user accounts
"""
refresh_newswire_filename: str = data_dir(base_dir) + '/.refresh_newswire'
if os.path.isfile(refresh_newswire_filename):
if is_a_file(refresh_newswire_filename):
return
save_flag_file(refresh_newswire_filename,
'EX: refresh_newswire unable to write ' +
@ -697,7 +698,7 @@ def get_memorials(base_dir: str) -> str:
"""Returns the nicknames for memorial accounts
"""
memorial_file: str = data_dir(base_dir) + '/memorial'
if not os.path.isfile(memorial_file):
if not is_a_file(memorial_file):
return ''
memorial_str = load_string(memorial_file,
@ -730,7 +731,7 @@ def _create_config(base_dir: str) -> None:
"""Creates a configuration file
"""
config_filename: str = base_dir + '/config.json'
if os.path.isfile(config_filename):
if is_a_file(config_filename):
return
config_json: dict = {}
save_json(config_json, config_filename)
@ -745,7 +746,7 @@ def set_config_param(base_dir: str, variable_name: str,
_create_config(base_dir)
config_filename: str = base_dir + '/config.json'
config_json: dict = {}
if os.path.isfile(config_filename):
if is_a_file(config_filename):
config_json = load_json(config_filename)
if config_json is None:
config_json = {}
@ -776,7 +777,7 @@ def get_followers_list(base_dir: str,
"""
filename: str = acct_dir(base_dir, nickname, domain) + '/' + follow_file
if not os.path.isfile(filename):
if not is_a_file(filename):
return []
lines: list[str] = \
@ -825,7 +826,7 @@ def get_followers_of_person(base_dir: str,
if account == handle or \
string_starts_with(account, ('inbox@', 'Actor@', 'news@')):
continue
if not os.path.isfile(filename):
if not is_a_file(filename):
continue
following_list: list[str] = \
load_list(filename,
@ -1271,7 +1272,7 @@ def get_display_name(base_dir: str, actor: str, person_cache: {}) -> str:
# Try to obtain from the cached actors
cached_actor_filename: str = \
base_dir + '/cache/actors/' + (actor.replace('/', '#')) + '.json'
if os.path.isfile(cached_actor_filename):
if is_a_file(cached_actor_filename):
actor_json = load_json(cached_actor_filename)
if actor_json:
if actor_json.get('name'):
@ -1296,7 +1297,7 @@ def get_actor_type(base_dir: str, actor: str, person_cache: {}) -> str:
# Try to obtain from the cached actors
cached_actor_filename: str = \
base_dir + '/cache/actors/' + (actor.replace('/', '#')) + '.json'
if os.path.isfile(cached_actor_filename):
if is_a_file(cached_actor_filename):
actor_json = load_json(cached_actor_filename)
if actor_json:
if actor_json.get('type'):
@ -1370,7 +1371,7 @@ def get_gender_from_bio(base_dir: str, actor: str, person_cache: {},
# Try to obtain from the cached actors
cached_actor_filename: str = \
base_dir + '/cache/actors/' + (actor.replace('/', '#')) + '.json'
if os.path.isfile(cached_actor_filename):
if is_a_file(cached_actor_filename):
actor_json: dict = load_json(cached_actor_filename)
if not actor_json:
return default_gender
@ -1540,7 +1541,7 @@ def _set_default_pet_name(base_dir: str, nickname: str, domain: str,
petname_lookup_entry: str = follow_nickname + ' ' + \
follow_nickname + '@' + follow_domain + '\n'
if not os.path.isfile(petnames_filename):
if not is_a_file(petnames_filename):
# if there is no existing petnames lookup file
save_string(petname_lookup_entry, petnames_filename,
'EX: _set_default_pet_name unable to write ' +
@ -1604,7 +1605,7 @@ def follow_person(base_dir: str, nickname: str, domain: str,
# was this person previously unfollowed?
unfollowed_filename: str = \
acct_handle_dir(base_dir, handle) + '/unfollowed.txt'
if os.path.isfile(unfollowed_filename):
if is_a_file(unfollowed_filename):
if text_in_file(handle_to_follow, unfollowed_filename):
# remove them from the unfollowed file
new_lines: str = ''
@ -1627,7 +1628,7 @@ def follow_person(base_dir: str, nickname: str, domain: str,
if group_account:
handle_to_follow = '!' + handle_to_follow
filename = acct_handle_dir(base_dir, handle) + '/' + follow_file
if os.path.isfile(filename):
if is_a_file(filename):
if text_in_file(handle_to_follow, filename):
if debug:
print('DEBUG: follow already exists')
@ -1697,7 +1698,7 @@ def locate_news_votes(base_dir: str, domain: str,
account_dir: str = data_dir(base_dir) + '/news@' + domain + '/'
post_filename: str = account_dir + 'outbox/' + post_url
if os.path.isfile(post_filename):
if is_a_file(post_filename):
return post_filename
return None
@ -1723,18 +1724,18 @@ def locate_post(base_dir: str, nickname: str, domain: str,
account_dir: str = acct_dir(base_dir, nickname, domain) + '/'
for box_name in boxes:
post_filename: str = account_dir + box_name + '/' + post_url
if os.path.isfile(post_filename):
if is_a_file(post_filename):
return post_filename
# check news posts
account_dir = data_dir(base_dir) + '/news' + '@' + domain + '/'
post_filename: str = account_dir + 'outbox/' + post_url
if os.path.isfile(post_filename):
if is_a_file(post_filename):
return post_filename
# is it in the announce cache?
post_filename = base_dir + '/cache/announce/' + nickname + '/' + post_url
if os.path.isfile(post_filename):
if is_a_file(post_filename):
return post_filename
# print('WARN: unable to locate ' + nickname + ' ' + post_url)
@ -1749,7 +1750,7 @@ def get_reply_interval_hours(base_dir: str, nickname: str, domain: str,
"""
reply_interval_filename: str = \
acct_dir(base_dir, nickname, domain) + '/.reply_interval_hours'
if os.path.isfile(reply_interval_filename):
if is_a_file(reply_interval_filename):
hours_str: str = \
load_string(reply_interval_filename,
'EX: get_reply_interval_hours unable to read ' +
@ -1795,7 +1796,7 @@ def _remove_attachment(base_dir: str, http_prefix: str,
# remove the media
media_filename: str = base_dir + '/' + \
attachment_url.replace(http_prefix + '://' + domain + '/', '')
if os.path.isfile(media_filename):
if is_a_file(media_filename):
ex_text = \
'EX: _remove_attachment unable to delete media file ' + \
str(media_filename)
@ -1804,7 +1805,7 @@ def _remove_attachment(base_dir: str, http_prefix: str,
# remove from the log file
account_dir: str = acct_dir(base_dir, nickname, domain)
account_media_log_filename: str = account_dir + '/media_log.txt'
if os.path.isfile(account_media_log_filename):
if is_a_file(account_media_log_filename):
search_filename: str = media_filename.replace(base_dir, '')
media_log_text: str = \
load_string(account_media_log_filename,
@ -1818,7 +1819,7 @@ def _remove_attachment(base_dir: str, http_prefix: str,
nickname)
# remove the transcript
if os.path.isfile(media_filename + '.vtt'):
if is_a_file(media_filename + '.vtt'):
ex_text = \
'EX: _remove_attachment unable to delete media transcript ' + \
str(media_filename) + '.vtt'
@ -1826,7 +1827,7 @@ def _remove_attachment(base_dir: str, http_prefix: str,
# remove the etag
etag_filename: str = media_filename + '.etag'
if os.path.isfile(etag_filename):
if is_a_file(etag_filename):
ex_text = \
'EX: _remove_attachment unable to delete etag file ' + \
str(etag_filename)
@ -1838,7 +1839,7 @@ def remove_post_from_index(post_url: str, debug: bool,
index_file: str) -> None:
"""Removes a url from a box index
"""
if not os.path.isfile(index_file):
if not is_a_file(index_file):
return
post_id: str = remove_id_ending(post_url).strip("\n").strip("\r")
if not text_in_file(post_id, index_file):
@ -1888,7 +1889,7 @@ def _is_reply_to_blog_post(base_dir: str, nickname: str, domain: str,
return False
blogs_index_filename: str = \
acct_dir(base_dir, nickname, domain) + '/tlblogs.index'
if not os.path.isfile(blogs_index_filename):
if not is_a_file(blogs_index_filename):
return False
post_id: str = remove_id_ending(reply_id)
post_id = post_id.replace('/', '#')
@ -1904,7 +1905,7 @@ def _delete_post_remove_replies(base_dir: str, nickname: str, domain: str,
"""Removes replies when deleting a post
"""
replies_filename: str = post_filename.replace('.json', '.replies')
if not os.path.isfile(replies_filename):
if not is_a_file(replies_filename):
return
if debug:
print('DEBUG: removing replies to ' + post_filename)
@ -1919,7 +1920,7 @@ def _delete_post_remove_replies(base_dir: str, nickname: str, domain: str,
locate_post(base_dir, nickname, domain, reply_id_str)
if not reply_file:
continue
if not os.path.isfile(reply_file):
if not is_a_file(reply_file):
continue
delete_post(base_dir, http_prefix,
nickname, domain, reply_file, debug,
@ -1937,7 +1938,7 @@ def _is_bookmarked(base_dir: str, nickname: str, domain: str,
"""
bookmarks_index_filename: str = \
acct_dir(base_dir, nickname, domain) + '/bookmarks.index'
if os.path.isfile(bookmarks_index_filename):
if is_a_file(bookmarks_index_filename):
bookmark_index: str = post_filename.split('/')[-1] + '\n'
if text_in_file(bookmark_index, bookmarks_index_filename):
return True
@ -1985,14 +1986,14 @@ def delete_cached_html(base_dir: str, nickname: str, domain: str,
get_cached_post_filename(base_dir, nickname, domain, post_json_object)
if not cached_post_filename:
return
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
ex_text = \
'EX: delete_cached_html unable to delete cached post file ' + \
str(cached_post_filename)
erase_file(cached_post_filename, ex_text)
cached_post_filename = cached_post_filename.replace('.html', '.ssml')
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
ex_text = \
'EX: ' + \
'delete_cached_html unable to delete cached ssml post file ' + \
@ -2001,7 +2002,7 @@ def delete_cached_html(base_dir: str, nickname: str, domain: str,
cached_post_filename = \
cached_post_filename.replace('/postcache/', '/outbox/')
if os.path.isfile(cached_post_filename):
if is_a_file(cached_post_filename):
ex_text = \
'EX: delete_cached_html ' + \
'unable to delete cached outbox ssml post file ' + \
@ -2065,12 +2066,12 @@ def _delete_hashtags_on_post(base_dir: str, post_json_object: {}) -> None:
# find the index file for this tag
tag_map_filename: str = \
base_dir + '/tagmaps/' + tag['name'][1:] + '.txt'
if os.path.isfile(tag_map_filename):
if is_a_file(tag_map_filename):
_remove_post_id_from_tag_index(tag_map_filename, post_id)
# find the index file for this tag
tag_index_filename: str = \
base_dir + '/tags/' + tag['name'][1:] + '.txt'
if os.path.isfile(tag_index_filename):
if is_a_file(tag_index_filename):
_remove_post_id_from_tag_index(tag_index_filename, post_id)
@ -2101,7 +2102,7 @@ def _delete_conversation_post(base_dir: str, nickname: str, domain: str,
conversation_id = conversation_id.replace('/', '#')
post_id: str = post_json_object['object']['id']
conversation_filename: str = conversation_dir + '/' + conversation_id
if not os.path.isfile(conversation_filename):
if not is_a_file(conversation_filename):
return False
conversation_str: str = \
load_string(conversation_filename,
@ -2117,7 +2118,7 @@ def _delete_conversation_post(base_dir: str, nickname: str, domain: str,
'EX: _delete_conversation_post unable to write ' +
conversation_filename)
else:
if os.path.isfile(conversation_filename + '.muted'):
if is_a_file(conversation_filename + '.muted'):
ex_text = 'EX: _delete_conversation_post ' + \
'unable to remove conversation ' + \
str(conversation_filename) + '.muted'
@ -2336,7 +2337,7 @@ def delete_post(base_dir: str, http_prefix: str,
post_json_object, '',
debug, False)
if gemini_blog_filename:
if os.path.isfile(gemini_blog_filename):
if is_a_file(gemini_blog_filename):
ex_text = 'EX: delete_post unable to delete gemini post ' + \
str(gemini_blog_filename)
if erase_file(gemini_blog_filename, ex_text):
@ -2348,7 +2349,7 @@ def delete_post(base_dir: str, http_prefix: str,
post_json_object, '',
debug, False)
if markdown_blog_filename:
if os.path.isfile(markdown_blog_filename):
if is_a_file(markdown_blog_filename):
ex_text = 'EX: delete_post unable to delete markdown post ' + \
str(markdown_blog_filename)
if erase_file(markdown_blog_filename, ex_text):
@ -2360,7 +2361,7 @@ def delete_post(base_dir: str, http_prefix: str,
post_json_object, '',
debug, False)
if micron_blog_filename:
if os.path.isfile(micron_blog_filename):
if is_a_file(micron_blog_filename):
ex_text = 'EX: delete_post unable to delete micron post ' + \
str(micron_blog_filename)
if erase_file(micron_blog_filename, ex_text):
@ -2381,13 +2382,13 @@ def delete_post(base_dir: str, http_prefix: str,
)
for ext in extensions:
ext_filename: str = post_filename + '.' + ext
if os.path.isfile(ext_filename):
if is_a_file(ext_filename):
ex_text = 'EX: delete_post unable to remove ext ' + \
str(ext_filename)
erase_file(ext_filename, ex_text)
elif post_filename.endswith('.json'):
ext_filename = post_filename.replace('.json', '') + '.' + ext
if os.path.isfile(ext_filename):
if is_a_file(ext_filename):
ex_text = 'EX: delete_post unable to remove ext ' + \
str(ext_filename)
erase_file(ext_filename, ex_text)
@ -2594,7 +2595,7 @@ def no_of_active_accounts_monthly(base_dir: str, months: int) -> bool:
continue
last_used_filename: str = \
dir_str + '/' + account + '/.lastUsed'
if not os.path.isfile(last_used_filename):
if not is_a_file(last_used_filename):
continue
last_used: str = \
load_string(last_used_filename,
@ -2661,7 +2662,7 @@ def get_css(css_filename: str) -> str:
"""Retrieves the css for a given file, or from a cache
"""
# does the css file exist?
if not os.path.isfile(css_filename):
if not is_a_file(css_filename):
return None
css: str = load_string(css_filename,
@ -2674,10 +2675,10 @@ def get_css(css_filename: str) -> str:
def get_file_case_insensitive(path: str) -> str:
"""Returns a case specific filename given a case insensitive version of it
"""
if os.path.isfile(path):
if is_a_file(path):
return path
if path != path.lower():
if os.path.isfile(path.lower()):
if is_a_file(path.lower()):
return path.lower()
return None
@ -2784,7 +2785,7 @@ def load_translations_from_file(base_dir: str, language: str) -> ({}, str):
system_language: str = system_language.split('.')[0]
translations_file: str = base_dir + '/translations/' + \
system_language + '.json'
if not os.path.isfile(translations_file):
if not is_a_file(translations_file):
system_language: str = 'en'
translations_file: str = base_dir + '/translations/' + \
system_language + '.json'
@ -2802,7 +2803,7 @@ def dm_allowed_from_domain(base_dir: str,
"""
dm_allowed_instances_file: str = \
acct_dir(base_dir, nickname, domain) + '/dmAllowedInstances.txt'
if not os.path.isfile(dm_allowed_instances_file):
if not is_a_file(dm_allowed_instances_file):
return False
if text_in_file(sending_actor_domain + '\n', dm_allowed_instances_file):
return True
@ -3233,7 +3234,7 @@ def load_bold_reading(base_dir: str) -> {}:
if acct.startswith('inbox@') or acct.startswith('Actor@'):
continue
bold_reading_filename = dir_str + '/' + acct + '/.boldReading'
if os.path.isfile(bold_reading_filename):
if is_a_file(bold_reading_filename):
nickname = acct.split('@')[0]
bold_reading[nickname] = True
break
@ -3252,7 +3253,7 @@ def load_hide_follows(base_dir: str) -> {}:
if acct.startswith('inbox@') or acct.startswith('Actor@'):
continue
hide_follows_filename = dir_str + '/' + acct + '/.hideFollows'
if os.path.isfile(hide_follows_filename):
if is_a_file(hide_follows_filename):
nickname = acct.split('@')[0]
hide_follows[nickname] = True
break
@ -3273,7 +3274,7 @@ def load_hide_recent_posts(base_dir: str) -> {}:
continue
hide_recent_posts_filename: str = \
dir_str + '/' + acct + '/.hideRecentPosts'
if os.path.isfile(hide_recent_posts_filename):
if is_a_file(hide_recent_posts_filename):
nickname: str = acct.split('@')[0]
hide_recent_posts[nickname] = True
break
@ -3454,7 +3455,7 @@ def load_min_images_for_accounts(base_dir: str) -> []:
if not is_account_dir(account):
continue
filename = os.path.join(subdir, account) + '/.minimize_all_images'
if os.path.isfile(filename):
if is_a_file(filename):
min_images_for_accounts.append(account.split('@')[0])
break
return min_images_for_accounts
@ -3472,7 +3473,7 @@ def set_minimize_all_images(base_dir: str,
if minimize:
if nickname not in min_images_for_accounts:
min_images_for_accounts.append(nickname)
if not os.path.isfile(filename):
if not is_a_file(filename):
save_flag_file(filename,
'EX: set_minimize_all_images unable to write ' +
filename)
@ -3480,7 +3481,7 @@ def set_minimize_all_images(base_dir: str,
if nickname in min_images_for_accounts:
min_images_for_accounts.remove(nickname)
if os.path.isfile(filename):
if is_a_file(filename):
erase_file(filename,
'EX: unable to delete ' + filename)
@ -3499,7 +3500,7 @@ def load_reverse_timeline(base_dir: str) -> []:
domain: str = acct.split('@')[1]
reverse_filename: str = \
acct_dir(base_dir, nickname, domain) + '/.reverse_timeline'
if os.path.isfile(reverse_filename):
if is_a_file(reverse_filename):
if nickname not in reverse_sequence:
reverse_sequence.append(nickname)
break
@ -3520,12 +3521,12 @@ def save_reverse_timeline(base_dir: str, reverse_sequence: []) -> None:
reverse_filename: str = \
acct_dir(base_dir, nickname, domain) + '/.reverse_timeline'
if nickname in reverse_sequence:
if not os.path.isfile(reverse_filename):
if not is_a_file(reverse_filename):
save_flag_file(reverse_filename,
'EX: failed to save reverse ' +
reverse_filename)
else:
if os.path.isfile(reverse_filename):
if is_a_file(reverse_filename):
erase_file(reverse_filename,
'EX: failed to delete reverse ' +
reverse_filename)
@ -3766,7 +3767,7 @@ def get_status_count(base_dir: str) -> int:
def lines_in_file(filename: str) -> int:
"""Returns the number of lines in a file
"""
if os.path.isfile(filename):
if is_a_file(filename):
text: str = load_string(filename,
'EX: lines_in_file error reading ' + filename)
if text:
@ -4077,7 +4078,7 @@ def set_premium_account(base_dir: str, nickname: str, domain: str,
""" Set or clear the premium account flag
"""
premium_filename: str = acct_dir(base_dir, nickname, domain) + '/.premium'
if os.path.isfile(premium_filename):
if is_a_file(premium_filename):
if not flag_state:
if not erase_file(premium_filename,
'EX: unable to remove premium flag ' +
@ -4139,7 +4140,7 @@ def get_image_file(base_dir: str, name: str, directory: str,
for ext in banner_extensions:
banner_file_test: str = im_name + '.' + ext
banner_filename_test: str = directory + '/' + banner_file_test
if not os.path.isfile(banner_filename_test):
if not is_a_file(banner_filename_test):
continue
banner_file = banner_file_test
banner_filename = banner_filename_test
@ -4152,7 +4153,7 @@ def get_image_file(base_dir: str, name: str, directory: str,
for ext in banner_extensions:
banner_file_test: str = name + '.' + ext
banner_filename_test: str = directory + '/' + banner_file_test
if not os.path.isfile(banner_filename_test):
if not is_a_file(banner_filename_test):
continue
banner_file = name + '_' + curr_theme + '.' + ext
banner_filename = banner_filename_test
@ -4211,7 +4212,7 @@ def load_instance_software(base_dir: str) -> []:
"""
instance_software_filename: str = \
data_dir(base_dir) + '/instance_software.json'
if os.path.isfile(instance_software_filename):
if is_a_file(instance_software_filename):
instance_software_json: dict = load_json(instance_software_filename)
if instance_software_json:
return instance_software_json

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Web Interface"
import os
from shutil import copyfile
from utils import data_dir
from utils import get_config_param
@ -15,6 +14,7 @@ from webapp_utils import html_header_with_website_markup
from webapp_utils import html_footer
from markdown import markdown_to_html
from data import load_string
from data import is_a_file
def html_about(base_dir: str, http_prefix: str,
@ -24,17 +24,17 @@ def html_about(base_dir: str, http_prefix: str,
"""
admin_nickname = get_config_param(base_dir, 'admin')
dir_str = data_dir(base_dir)
if not os.path.isfile(dir_str + '/about.md'):
if not is_a_file(dir_str + '/about.md'):
copyfile(base_dir + '/default_about.md',
dir_str + '/about.md')
if os.path.isfile(dir_str + '/login-background-custom.jpg'):
if not os.path.isfile(dir_str + '/login-background.jpg'):
if is_a_file(dir_str + '/login-background-custom.jpg'):
if not is_a_file(dir_str + '/login-background.jpg'):
copyfile(dir_str + '/login-background-custom.jpg',
dir_str + '/login-background.jpg')
about_text = 'Information about this instance goes here.'
if os.path.isfile(dir_str + '/about.md'):
if is_a_file(dir_str + '/about.md'):
about_text = load_string(dir_str + '/about.md',
'EX: html_about unable to read ' +
dir_str + '/about.md')
@ -43,7 +43,7 @@ def html_about(base_dir: str, http_prefix: str,
about_form: str = ''
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
instance_title = \

View File

@ -16,6 +16,7 @@ from utils import acct_dir
from webapp_utils import html_header_with_external_style
from webapp_utils import html_footer
from webapp_utils import get_banner_file
from data import is_a_file
def load_access_keys_for_accounts(base_dir: str, key_shortcuts: {},
@ -29,7 +30,7 @@ def load_access_keys_for_accounts(base_dir: str, key_shortcuts: {},
continue
account_dir = os.path.join(dir_str, acct)
access_keys_filename = account_dir + '/access_keys.json'
if not os.path.isfile(access_keys_filename):
if not is_a_file(access_keys_filename):
continue
nickname = acct.split('@')[0]
access_keys = load_json(access_keys_filename)
@ -51,7 +52,7 @@ def html_access_keys(base_dir: str,
"""
access_keys_filename = \
acct_dir(base_dir, nickname, domain) + '/access_keys.json'
if os.path.isfile(access_keys_filename):
if is_a_file(access_keys_filename):
access_keys_from_file = load_json(access_keys_filename)
if access_keys_from_file:
access_keys = access_keys_from_file
@ -61,7 +62,7 @@ def html_access_keys(base_dir: str,
access_keys_form: str = ''
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
instance_title = \

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Calendar"
import os
from auth import create_password
from datetime import datetime
from datetime import date
@ -40,6 +39,7 @@ from webapp_utils import html_hide_from_screen_reader
from webapp_utils import html_keyboard_navigation
from maps import html_open_street_map
from data import erase_file
from data import is_a_file
def html_calendar_delete_confirm(translate: {}, base_dir: str,
@ -69,7 +69,7 @@ def html_calendar_delete_confirm(translate: {}, base_dir: str,
delete_post_str = None
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
instance_title = \
@ -131,12 +131,12 @@ def _html_calendar_day(person_cache: {}, translate: {},
"""
account_dir = acct_dir(base_dir, nickname, domain)
calendar_file = account_dir + '/.newCalendar'
if os.path.isfile(calendar_file):
if is_a_file(calendar_file):
erase_file(calendar_file,
'EX: _html_calendar_day unable to delete ' + calendar_file)
css_filename = base_dir + '/epicyon-calendar.css'
if os.path.isfile(base_dir + '/calendar.css'):
if is_a_file(base_dir + '/calendar.css'):
css_filename = base_dir + '/calendar.css'
cal_actor = actor
@ -519,7 +519,7 @@ def html_calendar(person_cache: {}, translate: {},
# print('days_in_month ' + str(month_number) + ': ' + str(days_in_month))
css_filename = base_dir + '/epicyon-calendar.css'
if os.path.isfile(base_dir + '/calendar.css'):
if is_a_file(base_dir + '/calendar.css'):
css_filename = base_dir + '/calendar.css'
cal_actor = actor

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Web Interface Columns"
import os
from flags import is_editor
from flags import is_artist
from utils import replace_strings
@ -27,13 +26,14 @@ from webapp_utils import edit_text_field
from shares import share_category_icon
from data import load_list
from data import load_string
from data import is_a_file
def _links_exist(base_dir: str) -> bool:
"""Returns true if links have been created
"""
links_filename = data_dir(base_dir) + '/links.txt'
return os.path.isfile(links_filename)
return is_a_file(links_filename)
def _get_left_column_shares(base_dir: str,
@ -141,7 +141,7 @@ def get_left_column_content(base_dir: str, nickname: str, domain_full: str,
# show the image at the top of the column
edit_image_class = 'leftColEdit'
if os.path.isfile(left_column_image_filename):
if is_a_file(left_column_image_filename):
edit_image_class = 'leftColEditImage'
html_str += \
'\n <center>\n <img class="leftColImg" ' + \
@ -225,7 +225,7 @@ def get_left_column_content(base_dir: str, nickname: str, domain_full: str,
links_filename = data_dir(base_dir) + '/links.txt'
links_file_contains_entries: bool = False
links_list: list[str] = None
if os.path.isfile(links_filename):
if is_a_file(links_filename):
links_list = \
load_list(links_filename,
'EX: get_left_column_content unable to read ' +
@ -390,7 +390,7 @@ def html_links_mobile(base_dir: str,
# the css filename
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
# is the user a site editor?
@ -469,7 +469,7 @@ def html_edit_links(translate: {}, base_dir: str, path: str,
return ''
css_filename = base_dir + '/epicyon-links.css'
if os.path.isfile(base_dir + '/links.css'):
if is_a_file(base_dir + '/links.css'):
css_filename = base_dir + '/links.css'
# filename of the banner shown at the top
@ -515,7 +515,7 @@ def html_edit_links(translate: {}, base_dir: str, path: str,
links_filename = data_dir(base_dir) + '/links.txt'
links_str: str = ''
if os.path.isfile(links_filename):
if is_a_file(links_filename):
links_str = load_string(links_filename,
'EX: html_edit_links unable to read ' +
links_filename)
@ -543,7 +543,7 @@ def html_edit_links(translate: {}, base_dir: str, path: str,
if nickname == admin_nickname:
about_filename = data_dir(base_dir) + '/about.md'
about_str: str = ''
if os.path.isfile(about_filename):
if is_a_file(about_filename):
about_str = \
load_string(about_filename,
'EX: html_edit_links unable to read 2 ' +
@ -566,7 +566,7 @@ def html_edit_links(translate: {}, base_dir: str, path: str,
tos_filename = data_dir(base_dir) + '/tos.md'
tos_str: str = ''
if os.path.isfile(tos_filename):
if is_a_file(tos_filename):
tos_str = load_string(tos_filename,
'EX: html_edit_links unable to read 3 ' +
tos_filename)
@ -588,7 +588,7 @@ def html_edit_links(translate: {}, base_dir: str, path: str,
specification_filename = data_dir(base_dir) + '/activitypub.md'
specification_str: str = ''
if os.path.isfile(specification_filename):
if is_a_file(specification_filename):
specification_str = \
load_string(specification_filename,
'EX: html_edit_links unable to read 4 ' +

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Web Interface Columns"
import os
from content import remove_long_words
from content import limit_repeated_words
from flags import is_editor
@ -37,6 +36,7 @@ from webapp_utils import edit_text_field
from textmode import text_mode_browser
from data import load_list
from data import load_string
from data import is_a_file
def _votes_indicator(total_votes: int, positive_voting: bool) -> str:
@ -105,7 +105,7 @@ def get_right_column_content(base_dir: str, nickname: str, domain_full: str,
# show the image at the top of the column
edit_image_class = 'rightColEdit'
if os.path.isfile(right_column_image_filename):
if is_a_file(right_column_image_filename):
edit_image_class = 'rightColEditImage'
html_str += \
'\n <center>\n' + \
@ -175,7 +175,7 @@ def get_right_column_content(base_dir: str, nickname: str, domain_full: str,
# 3. show the edit icon
if editor:
dir_str = data_dir(base_dir)
if os.path.isfile(dir_str + '/newswiremoderation.txt'):
if is_a_file(dir_str + '/newswiremoderation.txt'):
# show the edit icon highlighted
html_str += \
' <a href="' + \
@ -269,7 +269,7 @@ def _html_newswire(base_dir: str, newswire: {}, nickname: str, moderator: bool,
if favicon_url:
cached_favicon_filename = \
get_fav_filename_from_url(base_dir, favicon_url)
if os.path.isfile(cached_favicon_filename):
if is_a_file(cached_favicon_filename):
favicon_url = \
cached_favicon_filename.replace(base_dir, '')
else:
@ -279,7 +279,7 @@ def _html_newswire(base_dir: str, newswire: {}, nickname: str, moderator: bool,
get_fav_filename_from_url(base_dir, favicon_url)
cached_favicon_filename = \
cached_favicon_filename.replace('.ico', '.' + ext)
if os.path.isfile(cached_favicon_filename):
if is_a_file(cached_favicon_filename):
favicon_url = \
cached_favicon_filename.replace(base_dir, '')
@ -383,7 +383,7 @@ def html_citations(base_dir: str, nickname: str, domain: str,
citations_filename = \
acct_dir(base_dir, nickname, domain) + '/.citations.txt'
citations_selected: list[str] = []
if os.path.isfile(citations_filename):
if is_a_file(citations_filename):
citations_separator = '#####'
citations: list[str] = \
load_list(citations_filename,
@ -401,7 +401,7 @@ def html_citations(base_dir: str, nickname: str, domain: str,
# the css filename
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
instance_title = \
@ -506,7 +506,7 @@ def html_newswire_mobile(base_dir: str, nickname: str,
# the css filename
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
if nickname == 'news':
@ -592,7 +592,7 @@ def html_edit_newswire(translate: {}, base_dir: str, path: str,
return ''
css_filename = base_dir + '/epicyon-links.css'
if os.path.isfile(base_dir + '/links.css'):
if is_a_file(base_dir + '/links.css'):
css_filename = base_dir + '/links.css'
# filename of the banner shown at the top
@ -638,7 +638,7 @@ def html_edit_newswire(translate: {}, base_dir: str, path: str,
newswire_filename = data_dir(base_dir) + '/newswire.txt'
newswire_str: str = ''
if os.path.isfile(newswire_filename):
if is_a_file(newswire_filename):
newswire_str = \
load_string(newswire_filename,
'EX: html_edit_newswire unable to read ' +
@ -664,7 +664,7 @@ def html_edit_newswire(translate: {}, base_dir: str, path: str,
filter_str: str = ''
filter_filename = \
data_dir(base_dir) + '/news@' + domain + '/filters.txt'
if os.path.isfile(filter_filename):
if is_a_file(filter_filename):
filter_str = \
load_string(filter_filename,
'EX: html_edit_newswire unable to read 2 ' +
@ -699,7 +699,7 @@ def html_edit_newswire(translate: {}, base_dir: str, path: str,
hashtag_rules_str: str = ''
hashtag_rules_filename = data_dir(base_dir) + '/hashtagrules.txt'
if os.path.isfile(hashtag_rules_filename):
if is_a_file(hashtag_rules_filename):
hashtag_rules_str = \
load_string(hashtag_rules_filename,
'EX: html_edit_newswire unable to read 3 ' +
@ -753,7 +753,7 @@ def html_edit_news_post(translate: {}, base_dir: str, path: str,
return ''
css_filename = base_dir + '/epicyon-links.css'
if os.path.isfile(base_dir + '/links.css'):
if is_a_file(base_dir + '/links.css'):
css_filename = base_dir + '/links.css'
instance_title = \

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Web Interface"
import os
from shutil import copyfile
from utils import get_mutuals_of_person
from utils import data_dir
@ -25,6 +24,7 @@ from webapp_utils import set_custom_background
from webapp_utils import html_header_with_external_style
from webapp_utils import html_footer
from webapp_post import individual_post_as_html
from data import is_a_file
def html_confirm_delete(server,
@ -75,7 +75,7 @@ def html_confirm_delete(server,
delete_post_str = None
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
instance_title = \
@ -86,7 +86,7 @@ def html_confirm_delete(server,
preload_images)
timezone = get_account_timezone(base_dir, nickname, domain)
mitm: bool = False
if os.path.isfile(post_filename.replace('.json', '') + '.mitm'):
if is_a_file(post_filename.replace('.json', '') + '.mitm'):
mitm = True
bold_reading: bool = False
if server.bold_reading.get(nickname):
@ -162,7 +162,7 @@ def html_confirm_remove_shared_item(translate: {},
domain_full = get_full_domain(domain, port)
shares_file = \
acct_dir(base_dir, nickname, domain) + '/' + shares_file_type + '.json'
if not os.path.isfile(shares_file):
if not is_a_file(shares_file):
print('ERROR: no ' + shares_file_type + ' file ' + shares_file)
return None
shares_json = load_json(shares_file)
@ -180,7 +180,7 @@ def html_confirm_remove_shared_item(translate: {},
set_custom_background(base_dir, 'shares-background', 'follow-background')
css_filename = base_dir + '/epicyon-follow.css'
if os.path.isfile(base_dir + '/follow.css'):
if is_a_file(base_dir + '/follow.css'):
css_filename = base_dir + '/follow.css'
instance_title = get_config_param(base_dir, 'instanceTitle')
@ -232,13 +232,13 @@ def html_confirm_follow(translate: {}, base_dir: str,
follow_domain, _ = get_domain_from_actor(follow_actor)
dir_str = data_dir(base_dir)
if os.path.isfile(dir_str + '/follow-background-custom.jpg'):
if not os.path.isfile(dir_str + '/follow-background.jpg'):
if is_a_file(dir_str + '/follow-background-custom.jpg'):
if not is_a_file(dir_str + '/follow-background.jpg'):
copyfile(dir_str + '/follow-background-custom.jpg',
dir_str + '/follow-background.jpg')
css_filename = base_dir + '/epicyon-follow.css'
if os.path.isfile(base_dir + '/follow.css'):
if is_a_file(base_dir + '/follow.css'):
css_filename = base_dir + '/follow.css'
instance_title = get_config_param(base_dir, 'instanceTitle')
@ -290,13 +290,13 @@ def html_confirm_unfollow(translate: {}, base_dir: str,
follow_domain, _ = get_domain_from_actor(follow_actor)
dir_str = data_dir(base_dir)
if os.path.isfile(dir_str + '/follow-background-custom.jpg'):
if not os.path.isfile(dir_str + '/follow-background.jpg'):
if is_a_file(dir_str + '/follow-background-custom.jpg'):
if not is_a_file(dir_str + '/follow-background.jpg'):
copyfile(dir_str + '/follow-background-custom.jpg',
dir_str + '/follow-background.jpg')
css_filename = base_dir + '/epicyon-follow.css'
if os.path.isfile(base_dir + '/follow.css'):
if is_a_file(base_dir + '/follow.css'):
css_filename = base_dir + '/follow.css'
instance_title = get_config_param(base_dir, 'instanceTitle')
@ -345,7 +345,7 @@ def html_confirm_unblock(translate: {}, base_dir: str,
set_custom_background(base_dir, 'block-background', 'follow-background')
css_filename = base_dir + '/epicyon-follow.css'
if os.path.isfile(base_dir + '/follow.css'):
if is_a_file(base_dir + '/follow.css'):
css_filename = base_dir + '/follow.css'
instance_title = get_config_param(base_dir, 'instanceTitle')
@ -394,7 +394,7 @@ def html_confirm_block(translate: {}, base_dir: str,
set_custom_background(base_dir, 'block-background', 'follow-background')
css_filename = base_dir + '/epicyon-follow.css'
if os.path.isfile(base_dir + '/follow.css'):
if is_a_file(base_dir + '/follow.css'):
css_filename = base_dir + '/follow.css'
instance_title = get_config_param(base_dir, 'instanceTitle')

View File

@ -8,7 +8,6 @@ __status__ = "Production"
__module_group__ = "Timeline"
import os
from conversation import download_conversation_posts
from flags import is_public_post
from utils import is_private_browser
@ -27,6 +26,7 @@ from webapp_utils import html_post_separator
from webapp_utils import html_footer
from webapp_utils import get_banner_file
from webapp_post import individual_post_as_html
from data import is_a_file
def html_conversation_view(authorized: bool, post_id: str,
@ -78,7 +78,7 @@ def html_conversation_view(authorized: bool, post_id: str,
return None
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
instance_title = \

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Web Interface"
import os
from flags import is_public_post_from_url
from flags import is_premium_account
from utils import get_mutuals_of_person
@ -55,6 +54,7 @@ from person import get_person_notes
from textmode import text_mode_browser
from data import load_list
from data import load_string
from data import is_a_file
def _html_new_post_drop_down(scope_icon: str, scope_description: str,
@ -184,7 +184,7 @@ def _html_new_post_drop_down(scope_icon: str, scope_description: str,
# whether to show votes
show_vote_file = account_dir + '/.noVotes'
if not os.path.isfile(show_vote_file):
if not is_a_file(show_vote_file):
drop_down_content += \
'<li><a href="' + path_base + \
'/newquestion"><img loading="lazy" decoding="async" ' + \
@ -566,7 +566,7 @@ def html_new_post(edit_post_params: {},
# custom report header with any additional instructions
dir_str = data_dir(base_dir)
if os.path.isfile(dir_str + '/report.txt'):
if is_a_file(dir_str + '/report.txt'):
custom_report_text = \
load_string(dir_str + '/report.txt',
'EX: html_new_post unable to read ' +
@ -609,7 +609,7 @@ def html_new_post(edit_post_params: {},
# load post template if it exists
dir_str = data_dir(base_dir)
if os.path.isfile(dir_str + '/newpost.txt'):
if is_a_file(dir_str + '/newpost.txt'):
new_post_text = \
load_string(dir_str + '/newpost.txt',
'EX: html_new_post unable to read ' +
@ -618,7 +618,7 @@ def html_new_post(edit_post_params: {},
new_post_text: str = ''
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
if '?' in path:
@ -931,7 +931,7 @@ def html_new_post(edit_post_params: {},
if endpoint == 'newblog':
citations_filename = \
acct_dir(base_dir, nickname, domain) + '/.citations.txt'
if os.path.isfile(citations_filename):
if is_a_file(citations_filename):
citations_str = '<div class="container">\n'
citations_str += '<p><label class="labels">' + \
translate['Citations'] + ':</label></p>\n'

View File

@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Timeline"
import os
from flags import is_system_account
from utils import get_mutuals_of_person
from utils import get_domain_from_actor
@ -22,6 +21,7 @@ from webapp_utils import header_buttons_front_screen
from webapp_column_left import get_left_column_content
from webapp_column_right import get_right_column_content
from webapp_post import individual_post_as_html
from data import is_a_file
def _html_front_screen_posts(recent_posts_cache: {}, max_recent_posts: int,
@ -207,7 +207,7 @@ def html_front_screen(signing_priv_key_pem: str,
profile_str = profile_header_str
css_filename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
if is_a_file(base_dir + '/epicyon.css'):
css_filename = base_dir + '/epicyon.css'
license_str: str = ''

View File

@ -43,6 +43,7 @@ from webapp_utils import html_footer
from data import load_string
from data import save_string
from data import load_line
from data import is_a_file
def get_hashtag_categories_feed(base_dir: str,
@ -106,7 +107,7 @@ def html_hash_tag_swarm(base_dir: str, actor: str, translate: {}) -> str:
# This avoids needing to repeatedly load the blocked file for each hashtag
blocked_str: str = ''
global_blocking_filename = data_dir(base_dir) + '/blocking.txt'
if os.path.isfile(global_blocking_filename):
if is_a_file(global_blocking_filename):
blocked_str = \
load_string(global_blocking_filename,
'EX: html_hash_tag_swarm unable to read ' +
@ -119,7 +120,7 @@ def html_hash_tag_swarm(base_dir: str, actor: str, translate: {}) -> str:
if not fname.endswith('.txt'):
continue
tags_filename = os.path.join(base_dir + '/tags', fname)
if not os.path.isfile(tags_filename):
if not is_a_file(tags_filename):
continue
# get last modified datetime
@ -186,7 +187,7 @@ def html_hash_tag_swarm(base_dir: str, actor: str, translate: {}) -> str:
tag_swarm.append(hash_tag_name)
category_filename = \
tags_filename.replace('.txt', '.category')
if os.path.isfile(category_filename):
if is_a_file(category_filename):
category_str = \
get_hashtag_category(base_dir, hash_tag_name)
if category_str and \
@ -201,7 +202,7 @@ def html_hash_tag_swarm(base_dir: str, actor: str, translate: {}) -> str:
tag_map_filename = \
os.path.join(base_dir + '/tagmaps',
hash_tag_name + '.txt')
if os.path.isfile(tag_map_filename):
if is_a_file(tag_map_filename):
if category_str not in swarm_map:
swarm_map.append(category_str)
break
@ -237,7 +238,7 @@ def html_hash_tag_swarm(base_dir: str, actor: str, translate: {}) -> str:
tag_display_name = tag_name
tag_map_filename = \
os.path.join(base_dir + '/tagmaps', tag_name + '.txt')
if os.path.isfile(tag_map_filename):
if is_a_file(tag_map_filename):
tag_display_name = '📌' + tag_name
tag_swarm_str += \
'<a href="' + actor + '/tags/' + tag_name + \
@ -265,7 +266,7 @@ def html_search_hashtag_category(translate: {},
set_custom_background(base_dir, 'search-background', 'follow-background')
css_filename = base_dir + '/epicyon-search.css'
if os.path.isfile(base_dir + '/search.css'):
if is_a_file(base_dir + '/search.css'):
css_filename = base_dir + '/search.css'
instance_title = \
@ -279,7 +280,7 @@ def html_search_hashtag_category(translate: {},
search_banner_file, search_banner_filename = \
get_search_banner_file(base_dir, search_nickname, domain, theme)
if os.path.isfile(search_banner_filename):
if is_a_file(search_banner_filename):
html_str += '<a href="' + actor + '/search">\n'
html_str += '<img loading="lazy" decoding="async" ' + \
'class="timeline-banner" src="' + \
@ -299,7 +300,7 @@ def html_search_hashtag_category(translate: {},
tag_display_name = tag_name
tag_map_filename = \
os.path.join(base_dir + '/tagmaps', tag_name + '.txt')
if os.path.isfile(tag_map_filename):
if is_a_file(tag_map_filename):
tag_display_name = '📌' + tag_name
html_str += \
@ -321,7 +322,7 @@ def _update_cached_hashtag_swarm(base_dir: str, nickname: str, domain: str,
cached_hashtag_swarm_filename = \
acct_dir(base_dir, nickname, domain) + '/.hashtagSwarm'
save_swarm = True
if os.path.isfile(cached_hashtag_swarm_filename):
if is_a_file(cached_hashtag_swarm_filename):
last_modified = file_last_modified(cached_hashtag_swarm_filename)
modified_date = None
try:
@ -373,7 +374,7 @@ def _store_tag_name(base_dir: str, nickname: str,
add_tag_map_links(tag_maps_dir, tag_name, map_links,
published, post_url)
hashtag_added: bool = False
if not os.path.isfile(tags_filename):
if not is_a_file(tags_filename):
if save_string(tag_line, tags_filename,
'EX: store_hash_tags unable to write ' + tags_filename):
hashtag_added = True
@ -395,7 +396,7 @@ def _store_tag_name(base_dir: str, nickname: str,
# automatically assign a category to the tag if possible
category_filename = tags_dir + '/' + tag_name + '.category'
if not os.path.isfile(category_filename):
if not is_a_file(category_filename):
hashtag_categories = \
get_hashtag_categories(base_dir, False, None)
category_str = \

Some files were not shown because too many files have changed in this diff Show More