diff --git a/auth.py b/auth.py index ff28418e3..f0d59b080 100644 --- a/auth.py +++ b/auth.py @@ -26,6 +26,7 @@ from data import load_list from data import move_file from data import is_a_file from data import is_a_dir +from data import makedir def _hash_password(password: str) -> str: @@ -191,7 +192,7 @@ def store_basic_credentials(base_dir: str, dir_str = data_dir(base_dir) if not is_a_dir(dir_str): - os.mkdir(dir_str) + makedir(dir_str) password_file = dir_str + '/passwords' store_str = nickname + ':' + _hash_password(password) diff --git a/categories.py b/categories.py index d09fa28c1..b0ec2123d 100644 --- a/categories.py +++ b/categories.py @@ -19,6 +19,7 @@ from data import save_string from data import erase_file from data import is_a_file from data import is_a_dir +from data import makedir MAX_TAG_LENGTH = 42 @@ -244,7 +245,7 @@ def set_hashtag_category(base_dir: str, hashtag: str, category: str, return False if not is_a_dir(base_dir + '/tags'): - os.mkdir(base_dir + '/tags') + makedir(base_dir + '/tags') category_filename = base_dir + '/tags/' + hashtag + '.category' if force: # don't overwrite any existing categories diff --git a/content.py b/content.py index ebd24945e..340c9cb47 100644 --- a/content.py +++ b/content.py @@ -58,6 +58,7 @@ from data import append_string from data import erase_file from data import is_a_file from data import is_a_dir +from data import makedir MUSIC_SITES = ('soundcloud.com', 'bandcamp.com', 'resonate.coop') @@ -377,7 +378,7 @@ def _save_custom_emoji(session, base_dir: str, emoji_name: str, url: str, emoji_name = emoji_name.replace(':', '').strip().lower() custom_emoji_dir = base_dir + '/emojicustom' if not is_a_dir(custom_emoji_dir): - os.mkdir(custom_emoji_dir) + makedir(custom_emoji_dir) emoji_image_filename = custom_emoji_dir + '/' + emoji_name + '.' + ext if not download_image(session, url, emoji_image_filename, debug, False): diff --git a/conversation.py b/conversation.py index d8c1b0493..3bd393bc0 100644 --- a/conversation.py +++ b/conversation.py @@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Timeline" -import os from utils import has_object_dict from utils import acct_dir from utils import remove_id_ending @@ -27,6 +26,7 @@ from data import append_string from data import erase_file from data import is_a_file from data import is_a_dir +from data import makedir def _get_conversation_filename(base_dir: str, nickname: str, domain: str, @@ -45,7 +45,7 @@ def _get_conversation_filename(base_dir: str, nickname: str, domain: str, return None conversation_dir = acct_dir(base_dir, nickname, domain) + '/conversation' if not is_a_dir(conversation_dir): - os.mkdir(conversation_dir) + makedir(conversation_dir) if post_json_object['object'].get('conversation'): conversation_id = post_json_object['object']['conversation'] elif post_json_object['object'].get('context'): diff --git a/daemon.py b/daemon.py index a5a49c95e..8855fa984 100644 --- a/daemon.py +++ b/daemon.py @@ -108,6 +108,7 @@ from poison import load_2grams from data import load_string from data import is_a_file from data import is_a_dir +from data import makedir class PubServer(BaseHTTPRequestHandler): @@ -701,7 +702,7 @@ def run_daemon(accounts_data_dir: str, dir_str = data_dir(base_dir) if not is_a_dir(dir_str): print('Creating accounts directory') - os.mkdir(dir_str) + makedir(dir_str) httpd = None try: @@ -1244,25 +1245,25 @@ def run_daemon(accounts_data_dir: str, httpd.domain_full) if not is_a_dir(base_dir + '/cache'): - os.mkdir(base_dir + '/cache') + makedir(base_dir + '/cache') if not is_a_dir(base_dir + '/cache/actors'): print('Creating actors cache') - os.mkdir(base_dir + '/cache/actors') + makedir(base_dir + '/cache/actors') if not is_a_dir(base_dir + '/cache/announce'): print('Creating announce cache') - os.mkdir(base_dir + '/cache/announce') + makedir(base_dir + '/cache/announce') if not is_a_dir(base_dir + '/cache/avatars'): print('Creating avatars cache') - os.mkdir(base_dir + '/cache/avatars') + makedir(base_dir + '/cache/avatars') archive_dir = base_dir + '/archive' if not is_a_dir(archive_dir): print('Creating archive') - os.mkdir(archive_dir) + makedir(archive_dir) if not is_a_dir(base_dir + '/sharefiles'): print('Creating shared item files directory') - os.mkdir(base_dir + '/sharefiles') + makedir(base_dir + '/sharefiles') print('THREAD: Creating fitness thread') httpd.thrFitness = \ diff --git a/daemon_post_profile.py b/daemon_post_profile.py index 596b29ab4..791e70784 100644 --- a/daemon_post_profile.py +++ b/daemon_post_profile.py @@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Daemon POST" -import os import errno from webfinger import webfinger_update from socket import error as SocketError @@ -153,6 +152,7 @@ from data import save_flag_file from data import erase_file from data import is_a_file from data import is_a_dir +from data import makedir def _profile_post_deactivate_account(base_dir: str, nickname: str, domain: str, @@ -470,7 +470,7 @@ def _profile_post_import_theme(base_dir: str, nickname: str, """ if fields.get('importTheme'): if not is_a_dir(base_dir + '/imports'): - os.mkdir(base_dir + '/imports') + makedir(base_dir + '/imports') filename_base = base_dir + '/imports/newtheme.zip' if is_a_file(filename_base): erase_file(filename_base, @@ -2725,7 +2725,7 @@ def profile_edit(self, calling_domain: str, cookie: str, filename_base = data_dir(base_dir) + '/login.temp' elif m_type == 'importTheme': if not is_a_dir(base_dir + '/imports'): - os.mkdir(base_dir + '/imports') + makedir(base_dir + '/imports') filename_base = base_dir + '/imports/newtheme.zip' if is_a_file(filename_base): erase_file(filename_base, diff --git a/data.py b/data.py index 20020082a..703ee7f7c 100644 --- a/data.py +++ b/data.py @@ -189,3 +189,9 @@ def is_a_dir(directory: str) -> bool: """Returns true if the given directory exists """ return os.path.isdir(directory) + + +def makedir(directory: str) -> None: + """Creates a directory + """ + os.mkdir(directory) diff --git a/desktop_client.py b/desktop_client.py index 82b04c31c..3a5a95e6c 100644 --- a/desktop_client.py +++ b/desktop_client.py @@ -77,6 +77,7 @@ from data import load_string from data import prepend_string from data import is_a_file from data import is_a_dir +from data import makedir def _desktop_help() -> None: @@ -159,9 +160,9 @@ def _create_desktop_config(actor: str) -> None: """ home_dir = str(Path.home()) if not is_a_dir(home_dir + '/.config'): - os.mkdir(home_dir + '/.config') + makedir(home_dir + '/.config') if not is_a_dir(home_dir + '/.config/epicyon'): - os.mkdir(home_dir + '/.config/epicyon') + makedir(home_dir + '/.config/epicyon') nickname = get_nickname_from_actor(actor) domain, port = get_domain_from_actor(actor) handle = nickname + '@' + domain @@ -169,7 +170,7 @@ def _create_desktop_config(actor: str) -> None: handle += '_' + str(port) read_posts_dir = home_dir + '/.config/epicyon/' + handle if not is_a_dir(read_posts_dir): - os.mkdir(read_posts_dir) + makedir(read_posts_dir) def _mark_post_as_read(actor: str, post_id: str, post_category: str) -> None: diff --git a/epicyon.py b/epicyon.py index e461e3dfb..ce9f5c3d6 100644 --- a/epicyon.py +++ b/epicyon.py @@ -139,6 +139,7 @@ from data import save_string from data import load_list from data import is_a_file from data import is_a_dir +from data import makedir def str2bool(value_str) -> bool: @@ -1591,13 +1592,13 @@ def _command_options() -> None: # create cache for actors if not is_a_dir(base_dir + '/cache'): - os.mkdir(base_dir + '/cache') + makedir(base_dir + '/cache') if not is_a_dir(base_dir + '/cache/actors'): print('Creating actors cache') - os.mkdir(base_dir + '/cache/actors') + makedir(base_dir + '/cache/actors') if not is_a_dir(base_dir + '/cache/announce'): print('Creating announce cache') - os.mkdir(base_dir + '/cache/announce') + makedir(base_dir + '/cache/announce') # set the theme in config.json theme_name = get_config_param(base_dir, 'theme') diff --git a/follow.py b/follow.py index 464071fde..edf934a86 100644 --- a/follow.py +++ b/follow.py @@ -53,6 +53,7 @@ from data import erase_file from data import move_file from data import is_a_file from data import is_a_dir +from data import makedir def create_initial_last_seen(base_dir: str, http_prefix: str) -> None: @@ -71,7 +72,7 @@ def create_initial_last_seen(base_dir: str, http_prefix: str) -> None: continue last_seen_dir = account_dir + '/lastseen' if not is_a_dir(last_seen_dir): - os.mkdir(last_seen_dir) + makedir(last_seen_dir) following_handles: list[str] = \ load_list(following_filename, 'EX: create_initial_last_seen ' + @@ -317,10 +318,10 @@ def unfollow_account(base_dir: str, nickname: str, domain: str, handle_to_unfollow = '!' + handle_to_unfollow dir_str = data_dir(base_dir) if not is_a_dir(dir_str): - os.mkdir(dir_str) + makedir(dir_str) handle_dir = acct_handle_dir(base_dir, handle) if not is_a_dir(handle_dir): - os.mkdir(handle_dir) + makedir(handle_dir) accounts_dir = acct_dir(base_dir, nickname, domain) filename = accounts_dir + '/' + follow_file @@ -384,10 +385,10 @@ def clear_follows(base_dir: str, nickname: str, domain: str, """ dir_str = data_dir(base_dir) if not is_a_dir(dir_str): - os.mkdir(dir_str) + makedir(dir_str) accounts_dir = acct_dir(base_dir, nickname, domain) if not is_a_dir(accounts_dir): - os.mkdir(accounts_dir) + makedir(accounts_dir) filename = accounts_dir + '/' + follow_file if is_a_file(filename): erase_file(filename, @@ -732,7 +733,7 @@ def store_follow_request(base_dir: str, # We don't rely upon the inbox because items in there could expire requests_dir = accounts_dir + '/requests' if not is_a_dir(requests_dir): - os.mkdir(requests_dir) + makedir(requests_dir) follow_activity_filename = requests_dir + '/' + approve_handle + '.follow' return save_json(follow_json, follow_activity_filename) diff --git a/gemini.py b/gemini.py index 351a4f9c1..fbcf73082 100644 --- a/gemini.py +++ b/gemini.py @@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Timeline" -import os import shutil from utils import acct_dir from utils import remove_html @@ -19,6 +18,7 @@ from utils import get_gemini_blog_published from utils import get_gemini_blog_filename from data import save_string from data import is_a_dir +from data import makedir def blog_to_gemini(base_dir: str, nickname: str, domain: str, @@ -88,7 +88,7 @@ def blog_to_gemini(base_dir: str, nickname: str, domain: str, else: gemini_blog_dir = account_dir + '/geminitest' if not is_a_dir(gemini_blog_dir): - os.mkdir(gemini_blog_dir) + makedir(gemini_blog_dir) gemini_blog_filename = \ get_gemini_blog_filename(base_dir, nickname, domain, diff --git a/git.py b/git.py index 9fe09a262..27837e663 100644 --- a/git.py +++ b/git.py @@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Profile Metadata" -import os import html from utils import remove_link_tracking from utils import acct_dir @@ -20,6 +19,7 @@ from utils import string_contains from data import save_string from data import is_a_file from data import is_a_dir +from data import makedir def _git_format_content(content: str) -> str: @@ -204,10 +204,10 @@ def receive_git_patch(base_dir: str, nickname: str, domain: str, project_name = \ _get_git_project_name(base_dir, nickname, domain, subject) if not is_a_dir(patches_dir): - os.mkdir(patches_dir) + makedir(patches_dir) project_dir = patches_dir + '/' + project_name if not is_a_dir(project_dir): - os.mkdir(project_dir) + makedir(project_dir) patch_filename = \ project_dir + '/' + patch_subject + '.patch' break diff --git a/happening.py b/happening.py index ee8d0988c..d4756c709 100644 --- a/happening.py +++ b/happening.py @@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Core" -import os from uuid import UUID from hashlib import md5 from datetime import datetime @@ -44,6 +43,7 @@ from data import prepend_string from data import erase_file from data import is_a_file from data import is_a_dir +from data import makedir def _strings_are_digits(strings_list: []) -> bool: @@ -122,7 +122,7 @@ def save_event_post(base_dir: str, handle: str, post_id: str, print('WARN: Account does not exist at ' + handle_dir) calendar_path = handle_dir + '/calendar' if not is_a_dir(calendar_path): - os.mkdir(calendar_path) + makedir(calendar_path) # get the year, month and day from the event event_time = date_from_string_format(event_json['startTime'], @@ -146,11 +146,11 @@ def save_event_post(base_dir: str, handle: str, post_id: str, # as a separate json file events_path = handle_dir + '/events' if not is_a_dir(events_path): - os.mkdir(events_path) + makedir(events_path) events_year_path = \ handle_dir + '/events/' + str(event_year) if not is_a_dir(events_year_path): - os.mkdir(events_year_path) + makedir(events_year_path) event_id = str(event_year) + '-' + event_time.strftime("%m") + '-' + \ event_time.strftime("%d") + '_' + event_json['uuid'] event_filename = events_year_path + '/' + event_id + '.json' @@ -173,7 +173,7 @@ def save_event_post(base_dir: str, handle: str, post_id: str, # create a directory for the calendar year if not is_a_dir(calendar_path + '/' + str(event_year)): - os.mkdir(calendar_path + '/' + str(event_year)) + makedir(calendar_path + '/' + str(event_year)) # calendar month file containing event post Ids calendar_filename = calendar_path + '/' + str(event_year) + \ diff --git a/inbox.py b/inbox.py index 74a9db814..8a87ab71f 100644 --- a/inbox.py +++ b/inbox.py @@ -146,6 +146,7 @@ from data import prepend_string from data import erase_file from data import is_a_file from data import is_a_dir +from data import makedir def _store_last_post_id(base_dir: str, nickname: str, domain: str, @@ -173,7 +174,7 @@ def _store_last_post_id(base_dir: str, nickname: str, domain: str, lastpost_dir = account_dir + '/lastpost' if not is_a_dir(lastpost_dir): if is_a_dir(account_dir): - os.mkdir(lastpost_dir) + makedir(lastpost_dir) actor_filename = lastpost_dir + '/' + actor.replace('/', '#') save_string(post_id, actor_filename, 'EX: Unable to write last post id to ' + actor_filename) @@ -1332,7 +1333,7 @@ def _update_last_seen(base_dir: str, handle: str, actor: str) -> None: return last_seen_path = account_path + '/lastseen' if not is_a_dir(last_seen_path): - os.mkdir(last_seen_path) + makedir(last_seen_path) last_seen_filename = \ last_seen_path + '/' + actor.replace('/', '#') + '.txt' curr_time = date_utcnow() diff --git a/markdown.py b/markdown.py index 3bcf158e4..4ab146aca 100644 --- a/markdown.py +++ b/markdown.py @@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Web Interface" -import os import shutil from utils import acct_dir from utils import remove_html @@ -19,6 +18,7 @@ from utils import get_micron_blog_filename from utils import get_gemini_blog_published from data import save_string from data import is_a_dir +from data import makedir def _markdown_get_sections(markdown: str) -> []: @@ -547,7 +547,7 @@ def blog_to_markdown(base_dir: str, nickname: str, domain: str, else: markdown_blog_dir = account_dir + '/markdowntest' if not is_a_dir(markdown_blog_dir): - os.mkdir(markdown_blog_dir) + makedir(markdown_blog_dir) markdown_blog_filename = \ get_markdown_blog_filename(base_dir, nickname, domain, @@ -623,7 +623,7 @@ def blog_to_micron(base_dir: str, nickname: str, domain: str, else: micron_blog_dir = account_dir + '/microntest' if not is_a_dir(micron_blog_dir): - os.mkdir(micron_blog_dir) + makedir(micron_blog_dir) micron_blog_filename = \ get_micron_blog_filename(base_dir, nickname, domain, diff --git a/media.py b/media.py index 4cfc7355f..370505a48 100644 --- a/media.py +++ b/media.py @@ -39,6 +39,7 @@ from data import erase_file from data import move_file from data import is_a_file from data import is_a_dir +from data import makedir # music file ID3 v1 genres @@ -547,9 +548,9 @@ def create_media_dirs(base_dir: str, media_path: str) -> None: """Creates stored media directories """ if not is_a_dir(base_dir + '/media'): - os.mkdir(base_dir + '/media') + makedir(base_dir + '/media') if not is_a_dir(base_dir + '/' + media_path): - os.mkdir(base_dir + '/' + media_path) + makedir(base_dir + '/' + media_path) def get_media_path() -> str: @@ -774,9 +775,9 @@ def archive_media(base_dir: str, archive_directory: str, if archive_directory: if not is_a_dir(archive_directory): - os.mkdir(archive_directory) + makedir(archive_directory) if not is_a_dir(archive_directory + '/media'): - os.mkdir(archive_directory + '/media') + makedir(archive_directory + '/media') for _, dirs, _ in os.walk(base_dir + '/media'): for week_dir in dirs: diff --git a/newsdaemon.py b/newsdaemon.py index 78a0ac572..465572993 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -50,6 +50,7 @@ from data import prepend_string from data import erase_file from data import is_a_file from data import is_a_dir +from data import makedir def _update_feeds_outbox_index(base_dir: str, domain: str, @@ -453,7 +454,7 @@ def _create_news_mirror(base_dir: str, domain: str, mirror_dir = data_dir(base_dir) + '/newsmirror' if not is_a_dir(mirror_dir): - os.mkdir(mirror_dir) + makedir(mirror_dir) # count the directories no_of_dirs: int = 0 @@ -562,7 +563,7 @@ def _convert_rss_to_activitypub(base_dir: str, http_prefix: str, base_path = data_dir(base_dir) + '/news@' + domain + '/outbox' if not is_a_dir(base_path): - os.mkdir(base_path) + makedir(base_path) # oldest items first newswire_reverse = OrderedDict(sorted(newswire.items(), reverse=False)) diff --git a/newswire.py b/newswire.py index 720e49b4a..81d0d4387 100644 --- a/newswire.py +++ b/newswire.py @@ -60,6 +60,7 @@ from data import save_binary from data import erase_file from data import is_a_file from data import is_a_dir +from data import makedir def _remove_cdata(text: str) -> str: @@ -190,7 +191,7 @@ def _download_newswire_feed_favicon(session, base_dir: str, # create cached favicons directory if needed if not is_a_dir(base_dir + '/favicons'): - os.mkdir(base_dir + '/favicons') + makedir(base_dir + '/favicons') # check svg for dubious scripts if fav_url.endswith('.svg'): diff --git a/outbox.py b/outbox.py index dbf3ec301..7aa7f8593 100644 --- a/outbox.py +++ b/outbox.py @@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Timeline" -import os from shutil import copyfile from auth import create_password from posts import is_image_media @@ -77,6 +76,7 @@ from data import erase_file from data import move_file from data import is_a_file from data import is_a_dir +from data import makedir def _localonly_not_local(message_json: {}, domain_full: str) -> bool: @@ -605,7 +605,7 @@ def post_message_to_outbox(session, translate: {}, blogs_dir = \ data_dir(base_dir) + '/news@' + domain + '/tlblogs' if not is_a_dir(blogs_dir): - os.mkdir(blogs_dir) + makedir(blogs_dir) copyfile(saved_filename, blogs_dir + '/' + saved_post_id) inbox_update_index('tlblogs', base_dir, 'news@' + domain, diff --git a/person.py b/person.py index c05fc6a49..db0a9bd1f 100644 --- a/person.py +++ b/person.py @@ -100,6 +100,7 @@ from data import erase_file from data import move_file from data import is_a_file from data import is_a_dir +from data import makedir def generate_rsa_key() -> (str, str): @@ -605,26 +606,26 @@ def _create_person_base(base_dir: str, nickname: str, domain: str, port: int, if save_to_file: # save person to file if not is_a_dir(base_dir): - os.mkdir(base_dir) + makedir(base_dir) people_subdir = data_dir(base_dir) if not is_a_dir(people_subdir): - os.mkdir(people_subdir) + makedir(people_subdir) if not is_a_dir(people_subdir + '/' + handle): - os.mkdir(people_subdir + '/' + handle) + makedir(people_subdir + '/' + handle) if not is_a_dir(people_subdir + '/' + handle + '/inbox'): - os.mkdir(people_subdir + '/' + handle + '/inbox') + makedir(people_subdir + '/' + handle + '/inbox') if not is_a_dir(people_subdir + '/' + handle + '/outbox'): - os.mkdir(people_subdir + '/' + handle + '/outbox') + makedir(people_subdir + '/' + handle + '/outbox') if not is_a_dir(people_subdir + '/' + handle + '/queue'): - os.mkdir(people_subdir + '/' + handle + '/queue') + makedir(people_subdir + '/' + handle + '/queue') filename = people_subdir + '/' + handle + '.json' save_json(new_person, filename) # save to cache if not is_a_dir(base_dir + '/cache'): - os.mkdir(base_dir + '/cache') + makedir(base_dir + '/cache') if not is_a_dir(base_dir + '/cache/actors'): - os.mkdir(base_dir + '/cache/actors') + makedir(base_dir + '/cache/actors') cache_filename = base_dir + '/cache/actors/' + \ new_person['id'].replace('/', '#') + '.json' save_json(new_person, cache_filename) @@ -632,9 +633,9 @@ def _create_person_base(base_dir: str, nickname: str, domain: str, port: int, # save the private key private_keys_subdir = '/keys/private' if not is_a_dir(base_dir + '/keys'): - os.mkdir(base_dir + '/keys') + makedir(base_dir + '/keys') if not is_a_dir(base_dir + private_keys_subdir): - os.mkdir(base_dir + private_keys_subdir) + makedir(base_dir + private_keys_subdir) filename = base_dir + private_keys_subdir + '/' + handle + '.key' save_string(private_key_pem, filename, 'EX: _create_person_base unable to save 1 ' + filename) @@ -642,7 +643,7 @@ def _create_person_base(base_dir: str, nickname: str, domain: str, port: int, # save the public key public_keys_subdir = '/keys/public' if not is_a_dir(base_dir + public_keys_subdir): - os.mkdir(base_dir + public_keys_subdir) + makedir(base_dir + public_keys_subdir) filename = base_dir + public_keys_subdir + '/' + handle + '.pem' save_string(public_key_pem, filename, 'EX: _create_person_base unable to save 2 ' + filename) @@ -777,10 +778,10 @@ def create_person(base_dir: str, nickname: str, domain: str, port: int, dir_str = data_dir(base_dir) if not is_a_dir(dir_str): - os.mkdir(dir_str) + makedir(dir_str) account_dir = acct_dir(base_dir, nickname, domain) if not is_a_dir(account_dir): - os.mkdir(account_dir) + makedir(account_dir) if manual_follower_approval: follow_dms_filename = \ @@ -1580,20 +1581,20 @@ def deactivate_account(base_dir: str, nickname: str, domain: str) -> bool: return False deactivated_dir = base_dir + '/deactivated' if not is_a_dir(deactivated_dir): - os.mkdir(deactivated_dir) + makedir(deactivated_dir) shutil.move(account_dir, deactivated_dir + '/' + handle) if is_a_file(base_dir + '/wfendpoints/' + handle + '.json'): deactivated_webfinger_dir = base_dir + '/wfdeactivated' if not is_a_dir(deactivated_webfinger_dir): - os.mkdir(deactivated_webfinger_dir) + makedir(deactivated_webfinger_dir) shutil.move(base_dir + '/wfendpoints/' + handle + '.json', deactivated_webfinger_dir + '/' + handle + '.json') if is_a_dir(base_dir + '/sharefiles/' + nickname): deactivated_sharefiles_dir = base_dir + '/sharefilesdeactivated' if not is_a_dir(deactivated_sharefiles_dir): - os.mkdir(deactivated_sharefiles_dir) + makedir(deactivated_sharefiles_dir) shutil.move(base_dir + '/sharefiles/' + nickname, deactivated_sharefiles_dir + '/' + nickname) @@ -1743,7 +1744,7 @@ def set_person_notes(base_dir: str, nickname: str, domain: str, handle = handle[1:] notes_dir = acct_dir(base_dir, nickname, domain) + '/notes' if not is_a_dir(notes_dir): - os.mkdir(notes_dir) + makedir(notes_dir) notes_filename = notes_dir + '/' + handle + '.txt' if not save_string(notes, notes_filename, 'EX: set_person_notes unable to write ' + diff --git a/posts.py b/posts.py index 333660e7c..6439ee0b5 100644 --- a/posts.py +++ b/posts.py @@ -154,6 +154,7 @@ from data import erase_file from data import move_file from data import is_a_file from data import is_a_dir +from data import makedir def convert_post_content_to_html(message_json: {}) -> None: @@ -1081,7 +1082,7 @@ def _update_hashtags_index(base_dir: str, tag: {}, new_post_id: str, # create hashtags directory tags_dir = base_dir + '/tags' if not is_a_dir(tags_dir): - os.mkdir(tags_dir) + makedir(tags_dir) tag_name = tag['name'] tags_filename = tags_dir + '/' + tag_name[1:] + '.txt' @@ -5323,11 +5324,11 @@ def archive_posts(base_dir: str, http_prefix: str, archive_dir: str, if archive_dir: if not is_a_dir(archive_dir): - os.mkdir(archive_dir) + makedir(archive_dir) if archive_dir: if not is_a_dir(archive_dir + '/accounts'): - os.mkdir(archive_dir + '/accounts') + makedir(archive_dir + '/accounts') dir_str = data_dir(base_dir) for _, dirs, _ in os.walk(dir_str): @@ -5339,11 +5340,11 @@ def archive_posts(base_dir: str, http_prefix: str, archive_dir: str, if archive_dir: archive_handle_dir = acct_handle_dir(archive_dir, handle) if not is_a_dir(archive_handle_dir): - os.mkdir(archive_handle_dir) + makedir(archive_handle_dir) if not is_a_dir(archive_handle_dir + '/inbox'): - os.mkdir(archive_handle_dir + '/inbox') + makedir(archive_handle_dir + '/inbox') if not is_a_dir(archive_handle_dir + '/outbox'): - os.mkdir(archive_handle_dir + '/outbox') + makedir(archive_handle_dir + '/outbox') archive_subdir = archive_handle_dir + '/inbox' archive_posts_for_person(http_prefix, nickname, domain, base_dir, @@ -5564,7 +5565,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str, return if archive_dir: if not is_a_dir(archive_dir): - os.mkdir(archive_dir) + makedir(archive_dir) box_dir = create_person_dir(nickname, domain, base_dir, boxname) posts_in_box = os.scandir(box_dir) no_of_posts: int = 0 @@ -6270,7 +6271,7 @@ def download_announce(session, base_dir: str, http_prefix: str, # get the announced post announce_cache_dir = base_dir + '/cache/announce/' + nickname if not is_a_dir(announce_cache_dir): - os.mkdir(announce_cache_dir) + makedir(announce_cache_dir) post_id = None if post_json_object.get('id'): diff --git a/reading.py b/reading.py index 99fceac9c..5a7ded1b6 100644 --- a/reading.py +++ b/reading.py @@ -8,7 +8,6 @@ __status__ = "Production" __module_group__ = "Core" -import os from collections import OrderedDict from utils import data_dir from utils import get_post_attachments @@ -27,6 +26,7 @@ from data import load_string from data import prepend_string from data import is_a_file from data import is_a_dir +from data import makedir def get_book_link_from_content(content: str) -> str: @@ -475,15 +475,15 @@ def store_book_events(base_dir: str, dir_str = data_dir(base_dir) reading_path = dir_str + '/reading' if not is_a_dir(dir_str): - os.mkdir(dir_str) + makedir(dir_str) if not is_a_dir(reading_path): - os.mkdir(reading_path) + makedir(reading_path) books_path = reading_path + '/books' if not is_a_dir(books_path): - os.mkdir(books_path) + makedir(books_path) readers_path = reading_path + '/readers' if not is_a_dir(readers_path): - os.mkdir(readers_path) + makedir(readers_path) actor = book_dict['actor'] book_url = remove_id_ending(book_dict['href']) diff --git a/shares.py b/shares.py index a5db3f71b..a9dbc7a0b 100644 --- a/shares.py +++ b/shares.py @@ -65,6 +65,7 @@ from data import load_string from data import erase_file from data import is_a_file from data import is_a_dir +from data import makedir def _load_dfc_ids(base_dir: str, system_language: str, @@ -387,9 +388,9 @@ def add_share(base_dir: str, if image_filename: if is_a_file(image_filename): if not is_a_dir(base_dir + '/sharefiles'): - os.mkdir(base_dir + '/sharefiles') + makedir(base_dir + '/sharefiles') if not is_a_dir(base_dir + '/sharefiles/' + nickname): - os.mkdir(base_dir + '/sharefiles/' + nickname) + makedir(base_dir + '/sharefiles/' + nickname) item_idfile = base_dir + '/sharefiles/' + nickname + '/' + item_id formats = get_image_extensions() for ext in formats: @@ -1735,13 +1736,13 @@ def _update_federated_shares_cache(session, shared_items_federated_domains: [], # create directories where catalogs will be stored cache_dir = base_dir + '/cache' if not is_a_dir(cache_dir): - os.mkdir(cache_dir) + makedir(cache_dir) if shares_file_type == 'shares': catalogs_dir = cache_dir + '/catalogs' else: catalogs_dir = cache_dir + '/wantedItems' if not is_a_dir(catalogs_dir): - os.mkdir(catalogs_dir) + makedir(catalogs_dir) as_header = { "Accept": "application/ld+json", @@ -1822,9 +1823,9 @@ def _generate_next_shares_token_update(base_dir: str, """ token_update_dir = data_dir(base_dir) if not is_a_dir(base_dir): - os.mkdir(base_dir) + makedir(base_dir) if not is_a_dir(token_update_dir): - os.mkdir(token_update_dir) + makedir(token_update_dir) token_update_filename = token_update_dir + '/.tokenUpdate' next_update_sec = None if is_a_file(token_update_filename): diff --git a/tests.py b/tests.py index fbd955384..6785cd41e 100644 --- a/tests.py +++ b/tests.py @@ -249,6 +249,7 @@ from data import load_string from data import save_string from data import erase_file from data import is_a_dir +from data import makedir TEST_SERVER_GROUP_RUNNING = False @@ -332,7 +333,7 @@ def _test_http_signed_get(base_dir: str): path = base_dir + '/.testHttpsigGET' if is_a_dir(path): shutil.rmtree(path, ignore_errors=False) - os.mkdir(path) + makedir(path) os.chdir(path) nickname = 'testactor' @@ -612,7 +613,7 @@ def _test_httpsig_base(with_digest: bool, base_dir: str): path = base_dir + '/.testHttpsigBase' if is_a_dir(path): shutil.rmtree(path, ignore_errors=False) - os.mkdir(path) + makedir(path) os.chdir(path) algorithm = 'rsa-sha256' @@ -773,7 +774,7 @@ def create_server_alice(path: str, domain: str, port: int, print('Creating test server: Alice on port ' + str(port)) if is_a_dir(path): shutil.rmtree(path, ignore_errors=False) - os.mkdir(path) + makedir(path) os.chdir(path) shared_items_federated_domains: list[str] = [] system_language: str = 'en' @@ -978,7 +979,7 @@ def create_server_bob(path: str, domain: str, port: int, print('Creating test server: Bob on port ' + str(port)) if is_a_dir(path): shutil.rmtree(path, ignore_errors=False) - os.mkdir(path) + makedir(path) os.chdir(path) shared_items_federated_domains: list[str] = [] system_language: str = 'en' @@ -1183,7 +1184,7 @@ def create_server_eve(path: str, domain: str, port: int, federation_list: [], print('Creating test server: Eve on port ' + str(port)) if is_a_dir(path): shutil.rmtree(path, ignore_errors=False) - os.mkdir(path) + makedir(path) os.chdir(path) shared_items_federated_domains: list[str] = [] nickname: str = 'eve' @@ -1308,7 +1309,7 @@ def create_server_group(path: str, domain: str, port: int, print('Creating test server: Group on port ' + str(port)) if is_a_dir(path): shutil.rmtree(path, ignore_errors=False) - os.mkdir(path) + makedir(path) os.chdir(path) shared_items_federated_domains: list[str] = [] # system_language = 'en' @@ -1425,7 +1426,7 @@ def test_post_message_between_servers(base_dir: str) -> None: if is_a_dir(base_dir + '/.tests'): shutil.rmtree(base_dir + '/.tests', ignore_errors=False) - os.mkdir(base_dir + '/.tests') + makedir(base_dir + '/.tests') # create the servers alice_dir = base_dir + '/.tests/alice' @@ -1785,7 +1786,7 @@ def test_follow_between_servers(base_dir: str) -> None: if is_a_dir(base_dir + '/.tests'): shutil.rmtree(base_dir + '/.tests', ignore_errors=False) - os.mkdir(base_dir + '/.tests') + makedir(base_dir + '/.tests') # create the servers alice_dir = base_dir + '/.tests/alice' @@ -1995,7 +1996,7 @@ def test_shared_items_federation(base_dir: str) -> None: if is_a_dir(base_dir + '/.tests'): shutil.rmtree(base_dir + '/.tests', ignore_errors=False) - os.mkdir(base_dir + '/.tests') + makedir(base_dir + '/.tests') # create the servers alice_dir = base_dir + '/.tests/alice' @@ -2157,7 +2158,7 @@ def test_shared_items_federation(base_dir: str) -> None: print('Bob publishes some shared items') if is_a_dir(bob_dir + '/ontology'): shutil.rmtree(bob_dir + '/ontology', ignore_errors=False) - os.mkdir(bob_dir + '/ontology') + makedir(bob_dir + '/ontology') copyfile(base_dir + '/img/logo.png', bob_dir + '/logo.png') copyfile(base_dir + '/ontology/foodTypes.json', bob_dir + '/ontology/foodTypes.json') @@ -2472,7 +2473,7 @@ def test_group_follow(base_dir: str) -> None: if is_a_dir(base_dir + '/.tests'): shutil.rmtree(base_dir + '/.tests', ignore_errors=False) - os.mkdir(base_dir + '/.tests') + makedir(base_dir + '/.tests') # create the servers alice_dir = base_dir + '/.tests/alice' @@ -2905,7 +2906,7 @@ def _test_followers_of_person(base_dir: str) -> None: base_dir = curr_dir + '/.tests_followersofperson' if is_a_dir(base_dir): shutil.rmtree(base_dir, ignore_errors=False) - os.mkdir(base_dir) + makedir(base_dir) os.chdir(base_dir) create_person(base_dir, nickname, domain, port, http_prefix, True, False, password) @@ -2955,7 +2956,7 @@ def _test_followers_on_domain(base_dir: str) -> None: base_dir = curr_dir + '/.tests_nooffollowersOndomain' if is_a_dir(base_dir): shutil.rmtree(base_dir, ignore_errors=False) - os.mkdir(base_dir) + makedir(base_dir) os.chdir(base_dir) create_person(base_dir, nickname, domain, port, http_prefix, True, False, password) @@ -3022,7 +3023,7 @@ def _test_group_followers(base_dir: str) -> None: base_dir = curr_dir + '/.tests_testgroupfollowers' if is_a_dir(base_dir): shutil.rmtree(base_dir, ignore_errors=False) - os.mkdir(base_dir) + makedir(base_dir) os.chdir(base_dir) create_person(base_dir, nickname, domain, port, http_prefix, True, False, password) @@ -3068,7 +3069,7 @@ def _test_follows(base_dir: str) -> None: base_dir = curr_dir + '/.tests_testfollows' if is_a_dir(base_dir): shutil.rmtree(base_dir, ignore_errors=False) - os.mkdir(base_dir) + makedir(base_dir) os.chdir(base_dir) create_person(base_dir, nickname, domain, port, http_prefix, True, False, password) @@ -3160,7 +3161,7 @@ def _test_create_person_account(base_dir: str): base_dir: str = curr_dir + '/.tests_createperson' if is_a_dir(base_dir): shutil.rmtree(base_dir, ignore_errors=False) - os.mkdir(base_dir) + makedir(base_dir) os.chdir(base_dir) private_key_pem, public_key_pem, person, wf_endpoint = \ @@ -3300,7 +3301,7 @@ def _test_authentication(base_dir: str) -> None: base_dir = curr_dir + '/.tests_authentication' if is_a_dir(base_dir): shutil.rmtree(base_dir, ignore_errors=False) - os.mkdir(base_dir) + makedir(base_dir) os.chdir(base_dir) assert store_basic_credentials(base_dir, 'othernick', 'otherpass') @@ -3352,7 +3353,7 @@ def test_client_to_server(base_dir: str): if is_a_dir(base_dir + '/.tests'): shutil.rmtree(base_dir + '/.tests', ignore_errors=False) - os.mkdir(base_dir + '/.tests') + makedir(base_dir + '/.tests') # create the servers alice_dir = base_dir + '/.tests/alice' @@ -4218,16 +4219,16 @@ def _test_addemoji(base_dir: str): base_dir_original = base_dir path = base_dir + '/.tests' if not is_a_dir(path): - os.mkdir(path) + makedir(path) path = base_dir + '/.tests/emoji' if is_a_dir(path): shutil.rmtree(path, ignore_errors=False) - os.mkdir(path) + makedir(path) base_dir = path path = base_dir + '/emoji' if is_a_dir(path): shutil.rmtree(path, ignore_errors=False) - os.mkdir(path) + makedir(path) copytree(base_dir_original + '/emoji', base_dir + '/emoji', False, None) os.chdir(base_dir) private_key_pem, public_key_pem, person, wf_endpoint = \ @@ -6867,7 +6868,7 @@ def test_update_actor(base_dir: str): if is_a_dir(base_dir + '/.tests'): shutil.rmtree(base_dir + '/.tests', ignore_errors=False) - os.mkdir(base_dir + '/.tests') + makedir(base_dir + '/.tests') # create the server alice_dir = base_dir + '/.tests/alice' @@ -7783,7 +7784,7 @@ def _test_httpsig_base_new(with_digest: bool, base_dir: str, path = base_dir + '/.testHttpsigBaseNew' if is_a_dir(path): shutil.rmtree(path, ignore_errors=False) - os.mkdir(path) + makedir(path) os.chdir(path) content_type = 'application/activity+json' @@ -8959,7 +8960,7 @@ def _test_book_link(base_dir: str): base_dir2 = base_dir + '/.testbookevents' if is_a_dir(base_dir2): shutil.rmtree(base_dir2, ignore_errors=False) - os.mkdir(base_dir2) + makedir(base_dir2) content = 'Not a link' result = get_book_link_from_content(content) diff --git a/theme.py b/theme.py index fd1e85a10..aba916f43 100644 --- a/theme.py +++ b/theme.py @@ -34,6 +34,7 @@ from data import save_flag_file from data import erase_file from data import is_a_file from data import is_a_dir +from data import makedir def import_theme(base_dir: str, filename: str) -> bool: @@ -44,7 +45,7 @@ def import_theme(base_dir: str, filename: str) -> bool: temp_theme_dir = base_dir + '/imports/files' if is_a_dir(temp_theme_dir): rmtree(temp_theme_dir, ignore_errors=False, onexc=None) - os.mkdir(temp_theme_dir) + makedir(temp_theme_dir) unpack_archive(filename, temp_theme_dir, 'zip') essential_theme_files = ('name.txt', 'theme.json') for theme_file in essential_theme_files: @@ -88,7 +89,7 @@ def import_theme(base_dir: str, filename: str) -> bool: theme_dir = base_dir + '/theme/' + new_theme_name if not is_a_dir(theme_dir): - os.mkdir(theme_dir) + makedir(theme_dir) copytree(temp_theme_dir, theme_dir, False, None) if is_a_dir(temp_theme_dir): rmtree(temp_theme_dir, ignore_errors=False, onexc=None) @@ -105,7 +106,7 @@ def export_theme(base_dir: str, theme: str) -> bool: if not is_a_file(theme_dir + '/theme.json'): return False if not is_a_dir(base_dir + '/exports'): - os.mkdir(base_dir + '/exports') + makedir(base_dir + '/exports') export_filename = base_dir + '/exports/' + theme + '.zip' if is_a_file(export_filename): ex_text = \ diff --git a/utils.py b/utils.py index 7ff993291..2fb4da733 100644 --- a/utils.py +++ b/utils.py @@ -30,6 +30,7 @@ from data import append_string from data import erase_file from data import is_a_file from data import is_a_dir +from data import makedir VALID_HASHTAG_CHARS = \ set('_0123456789' + @@ -1037,10 +1038,10 @@ def create_person_dir(nickname: str, domain: str, base_dir: str, handle: str = nickname + '@' + domain handle_dir: str = acct_handle_dir(base_dir, handle) if not is_a_dir(handle_dir): - os.mkdir(handle_dir) + makedir(handle_dir) box_dir: str = acct_handle_dir(base_dir, handle) + '/' + dir_name if not is_a_dir(box_dir): - os.mkdir(box_dir) + makedir(box_dir) return box_dir @@ -1624,7 +1625,7 @@ def follow_person(base_dir: str, nickname: str, domain: str, dir_str: str = data_dir(base_dir) if not is_a_dir(dir_str): - os.mkdir(dir_str) + makedir(dir_str) handle_to_follow = follow_nickname + '@' + follow_domain if group_account: handle_to_follow = '!' + handle_to_follow diff --git a/webapp_hashtagswarm.py b/webapp_hashtagswarm.py index 153275868..6b258db71 100644 --- a/webapp_hashtagswarm.py +++ b/webapp_hashtagswarm.py @@ -45,6 +45,7 @@ from data import save_string from data import load_line from data import is_a_file from data import is_a_dir +from data import makedir def get_hashtag_categories_feed(base_dir: str, @@ -431,7 +432,7 @@ def store_hash_tags(base_dir: str, nickname: str, domain: str, # add tags directory if it doesn't exist if not is_a_dir(tags_dir): print('Creating tags directory') - os.mkdir(tags_dir) + makedir(tags_dir) # obtain any map links and these can be associated with hashtags # get geolocations from content @@ -459,7 +460,7 @@ def store_hash_tags(base_dir: str, nickname: str, domain: str, # add tagmaps directory if it doesn't exist if not is_a_dir(tag_maps_dir): print('Creating tagmaps directory') - os.mkdir(tag_maps_dir) + makedir(tag_maps_dir) post_url = remove_id_ending(post_json_object['id']) post_url = post_url.replace('/', '#') diff --git a/webapp_post.py b/webapp_post.py index d2e88ffa9..1e87c0dbc 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Web Interface" -import os import time import urllib.parse from dateutil.parser import parse @@ -150,6 +149,7 @@ from data import save_string from data import save_flag_file from data import is_a_file from data import is_a_dir +from data import makedir # maximum length for display name within html posts MAX_DISPLAY_NAME_LENGTH = 42 @@ -573,7 +573,7 @@ def _save_individual_post_as_html_to_cache(base_dir: str, # create the cache directory if needed if not is_a_dir(html_post_cache_dir): - os.mkdir(html_post_cache_dir) + makedir(html_post_cache_dir) if save_string(post_html, cached_post_filename, 'ERROR: saving post to cache, [ex]'): diff --git a/webfinger.py b/webfinger.py index 90a1b81c5..6bf77af93 100644 --- a/webfinger.py +++ b/webfinger.py @@ -7,7 +7,6 @@ __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "ActivityPub" -import os import urllib.parse from session import get_json from session import get_json_valid @@ -31,6 +30,7 @@ from utils import get_domain_from_actor from utils import is_yggdrasil_url from data import is_a_file from data import is_a_dir +from data import makedir def _parse_handle(handle: str) -> (str, str, bool): @@ -162,7 +162,7 @@ def store_webfinger_endpoint(nickname: str, domain: str, port: int, handle = nickname + '@' + domain wf_subdir = '/wfendpoints' if not is_a_dir(base_dir + wf_subdir): - os.mkdir(base_dir + wf_subdir) + makedir(base_dir + wf_subdir) filename = base_dir + wf_subdir + '/' + handle + '.json' save_json(wf_json, filename) if nickname == 'inbox':