Snake case

main
Bob Mottram 2021-12-27 19:26:54 +00:00
parent 7e3e299873
commit 6ecc96c043
2 changed files with 31 additions and 29 deletions

View File

@ -52,7 +52,7 @@ from utils import get_full_domain
from utils import get_followers_list from utils import get_followers_list
from utils import is_evil from utils import is_evil
from utils import get_status_number from utils import get_status_number
from utils import createPersonDir from utils import create_person_dir
from utils import urlPermitted from utils import urlPermitted
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import get_domain_from_actor from utils import get_domain_from_actor
@ -892,7 +892,7 @@ def deleteAllPosts(base_dir: str,
if boxname != 'inbox' and boxname != 'outbox' and \ if boxname != 'inbox' and boxname != 'outbox' and \
boxname != 'tlblogs' and boxname != 'tlnews': boxname != 'tlblogs' and boxname != 'tlnews':
return return
boxDir = createPersonDir(nickname, domain, base_dir, boxname) boxDir = create_person_dir(nickname, domain, base_dir, boxname)
for deleteFilename in os.scandir(boxDir): for deleteFilename in os.scandir(boxDir):
deleteFilename = deleteFilename.name deleteFilename = deleteFilename.name
filePath = os.path.join(boxDir, deleteFilename) filePath = os.path.join(boxDir, deleteFilename)
@ -928,7 +928,7 @@ def savePostToBox(base_dir: str, http_prefix: str, post_id: str,
post_json_object['object']['id'] = post_id post_json_object['object']['id'] = post_id
post_json_object['object']['atomUri'] = post_id post_json_object['object']['atomUri'] = post_id
boxDir = createPersonDir(nickname, domain, base_dir, boxname) boxDir = create_person_dir(nickname, domain, base_dir, boxname)
filename = boxDir + '/' + post_id.replace('/', '#') + '.json' filename = boxDir + '/' + post_id.replace('/', '#') + '.json'
save_json(post_json_object, filename) save_json(post_json_object, filename)
@ -3394,7 +3394,7 @@ def createOutbox(session, base_dir: str, nickname: str, domain: str,
def createModeration(base_dir: str, nickname: str, domain: str, port: int, def createModeration(base_dir: str, nickname: str, domain: str, port: int,
http_prefix: str, itemsPerPage: int, headerOnly: bool, http_prefix: str, itemsPerPage: int, headerOnly: bool,
pageNumber: int) -> {}: pageNumber: int) -> {}:
boxDir = createPersonDir(nickname, domain, base_dir, 'inbox') boxDir = create_person_dir(nickname, domain, base_dir, 'inbox')
boxname = 'moderation' boxname = 'moderation'
domain = get_full_domain(domain, port) domain = get_full_domain(domain, port)
@ -3952,7 +3952,7 @@ def archivePostsForPerson(http_prefix: str, nickname: str, domain: str,
if archive_dir: if archive_dir:
if not os.path.isdir(archive_dir): if not os.path.isdir(archive_dir):
os.mkdir(archive_dir) os.mkdir(archive_dir)
boxDir = createPersonDir(nickname, domain, base_dir, boxname) boxDir = create_person_dir(nickname, domain, base_dir, boxname)
postsInBox = os.scandir(boxDir) postsInBox = os.scandir(boxDir)
noOfPosts = 0 noOfPosts = 0
for f in postsInBox: for f in postsInBox:

View File

@ -784,8 +784,8 @@ def removeInvalidChars(text: str) -> str:
return text return text
def createPersonDir(nickname: str, domain: str, base_dir: str, def create_person_dir(nickname: str, domain: str, base_dir: str,
dir_name: str) -> str: dir_name: str) -> str:
"""Create a directory for a person """Create a directory for a person
""" """
handle = nickname + '@' + domain handle = nickname + '@' + domain
@ -800,16 +800,18 @@ def createPersonDir(nickname: str, domain: str, base_dir: str,
def create_outbox_dir(nickname: str, domain: str, base_dir: str) -> str: def create_outbox_dir(nickname: str, domain: str, base_dir: str) -> str:
"""Create an outbox for a person """Create an outbox for a person
""" """
return createPersonDir(nickname, domain, base_dir, 'outbox') return create_person_dir(nickname, domain, base_dir, 'outbox')
def create_inbox_queue_dir(nickname: str, domain: str, base_dir: str) -> str: def create_inbox_queue_dir(nickname: str, domain: str, base_dir: str) -> str:
"""Create an inbox queue and returns the feed filename and directory """Create an inbox queue and returns the feed filename and directory
""" """
return createPersonDir(nickname, domain, base_dir, 'queue') return create_person_dir(nickname, domain, base_dir, 'queue')
def domain_permitted(domain: str, federation_list: []): def domain_permitted(domain: str, federation_list: []) -> bool:
"""Is the given domain permitted according to the federation list?
"""
if len(federation_list) == 0: if len(federation_list) == 0:
return True return True
domain = remove_domain_port(domain) domain = remove_domain_port(domain)
@ -1100,8 +1102,8 @@ def get_domain_from_actor(actor: str) -> (str, int):
return domain, port return domain, port
def _setDefaultPetName(base_dir: str, nickname: str, domain: str, def _set_default_pet_name(base_dir: str, nickname: str, domain: str,
followNickname: str, followDomain: str) -> None: follow_nickname: str, follow_domain: str) -> None:
"""Sets a default petname """Sets a default petname
This helps especially when using onion or i2p address This helps especially when using onion or i2p address
""" """
@ -1109,8 +1111,8 @@ def _setDefaultPetName(base_dir: str, nickname: str, domain: str,
userPath = acct_dir(base_dir, nickname, domain) userPath = acct_dir(base_dir, nickname, domain)
petnamesFilename = userPath + '/petnames.txt' petnamesFilename = userPath + '/petnames.txt'
petnameLookupEntry = followNickname + ' ' + \ petnameLookupEntry = follow_nickname + ' ' + \
followNickname + '@' + followDomain + '\n' follow_nickname + '@' + follow_domain + '\n'
if not os.path.isfile(petnamesFilename): if not os.path.isfile(petnamesFilename):
# if there is no existing petnames lookup file # if there is no existing petnames lookup file
with open(petnamesFilename, 'w+') as petnamesFile: with open(petnamesFilename, 'w+') as petnamesFile:
@ -1122,7 +1124,7 @@ def _setDefaultPetName(base_dir: str, nickname: str, domain: str,
if petnamesStr: if petnamesStr:
petnamesList = petnamesStr.split('\n') petnamesList = petnamesStr.split('\n')
for pet in petnamesList: for pet in petnamesList:
if pet.startswith(followNickname + ' '): if pet.startswith(follow_nickname + ' '):
# petname already exists # petname already exists
return return
# petname doesn't already exist # petname doesn't already exist
@ -1131,21 +1133,21 @@ def _setDefaultPetName(base_dir: str, nickname: str, domain: str,
def follow_person(base_dir: str, nickname: str, domain: str, def follow_person(base_dir: str, nickname: str, domain: str,
followNickname: str, followDomain: str, follow_nickname: str, follow_domain: str,
federation_list: [], debug: bool, federation_list: [], debug: bool,
group_account: bool, group_account: bool,
follow_file: str = 'following.txt') -> bool: follow_file: str = 'following.txt') -> bool:
"""Adds a person to the follow list """Adds a person to the follow list
""" """
followDomainStrLower = followDomain.lower().replace('\n', '') follow_domainStrLower = follow_domain.lower().replace('\n', '')
if not domain_permitted(followDomainStrLower, if not domain_permitted(follow_domainStrLower,
federation_list): federation_list):
if debug: if debug:
print('DEBUG: follow of domain ' + print('DEBUG: follow of domain ' +
followDomain + ' not permitted') follow_domain + ' not permitted')
return False return False
if debug: if debug:
print('DEBUG: follow of domain ' + followDomain) print('DEBUG: follow of domain ' + follow_domain)
if ':' in domain: if ':' in domain:
domainOnly = remove_domain_port(domain) domainOnly = remove_domain_port(domain)
@ -1157,11 +1159,11 @@ def follow_person(base_dir: str, nickname: str, domain: str,
print('WARN: account for ' + handle + ' does not exist') print('WARN: account for ' + handle + ' does not exist')
return False return False
if ':' in followDomain: if ':' in follow_domain:
followDomainOnly = remove_domain_port(followDomain) follow_domainOnly = remove_domain_port(follow_domain)
handleToFollow = followNickname + '@' + followDomainOnly handleToFollow = follow_nickname + '@' + follow_domainOnly
else: else:
handleToFollow = followNickname + '@' + followDomain handleToFollow = follow_nickname + '@' + follow_domain
if group_account: if group_account:
handleToFollow = '!' + handleToFollow handleToFollow = '!' + handleToFollow
@ -1182,7 +1184,7 @@ def follow_person(base_dir: str, nickname: str, domain: str,
if not os.path.isdir(base_dir + '/accounts'): if not os.path.isdir(base_dir + '/accounts'):
os.mkdir(base_dir + '/accounts') os.mkdir(base_dir + '/accounts')
handleToFollow = followNickname + '@' + followDomain handleToFollow = follow_nickname + '@' + follow_domain
if group_account: if group_account:
handleToFollow = '!' + handleToFollow handleToFollow = '!' + handleToFollow
filename = base_dir + '/accounts/' + handle + '/' + follow_file filename = base_dir + '/accounts/' + handle + '/' + follow_file
@ -1217,13 +1219,13 @@ def follow_person(base_dir: str, nickname: str, domain: str,
# if following a person add them to the list of # if following a person add them to the list of
# calendar follows # calendar follows
print('DEBUG: adding ' + print('DEBUG: adding ' +
followNickname + '@' + followDomain + ' to calendar of ' + follow_nickname + '@' + follow_domain + ' to calendar of ' +
nickname + '@' + domain) nickname + '@' + domain)
add_person_to_calendar(base_dir, nickname, domain, add_person_to_calendar(base_dir, nickname, domain,
followNickname, followDomain) follow_nickname, follow_domain)
# add a default petname # add a default petname
_setDefaultPetName(base_dir, nickname, domain, _set_default_pet_name(base_dir, nickname, domain,
followNickname, followDomain) follow_nickname, follow_domain)
return True return True