diff --git a/announce.py b/announce.py index dc32bc0fa..fdfc91c73 100644 --- a/announce.py +++ b/announce.py @@ -19,7 +19,7 @@ from utils import urlPermitted from utils import getNicknameFromActor from utils import getDomainFromActor from utils import locatePost -from utils import saveJson +from utils import save_json from utils import undoAnnounceCollectionEntry from utils import updateAnnounceCollection from utils import local_actor_url @@ -158,7 +158,7 @@ def createAnnounce(session, base_dir: str, federation_list: [], if saveToFile: outboxDir = createOutboxDir(nickname, domain, base_dir) filename = outboxDir + '/' + newAnnounceId.replace('/', '#') + '.json' - saveJson(newAnnounce, filename) + save_json(newAnnounce, filename) announceNickname = None announceDomain = None diff --git a/availability.py b/availability.py index 431e39114..935aba564 100644 --- a/availability.py +++ b/availability.py @@ -17,7 +17,7 @@ from utils import get_full_domain from utils import getNicknameFromActor from utils import getDomainFromActor from utils import loadJson -from utils import saveJson +from utils import save_json from utils import acct_dir from utils import local_actor_url from utils import hasActor @@ -36,7 +36,7 @@ def setAvailability(base_dir: str, nickname: str, domain: str, actor_json = loadJson(actorFilename) if actor_json: actor_json['availability'] = status - saveJson(actor_json, actorFilename) + save_json(actor_json, actorFilename) return True diff --git a/blocking.py b/blocking.py index dfc2d11b3..2010783c7 100644 --- a/blocking.py +++ b/blocking.py @@ -19,7 +19,7 @@ from utils import has_object_dict from utils import isAccountDir from utils import getCachedPostFilename from utils import loadJson -from utils import saveJson +from utils import save_json from utils import fileLastModified from utils import setConfigParam from utils import has_users_path @@ -581,7 +581,7 @@ def mutePost(base_dir: str, nickname: str, domain: str, port: int, itemsList.append(newIgnore) postJsonObj['ignores']['totalItems'] = igIt postJsonObj['muted'] = True - if saveJson(post_json_object, postFilename): + if save_json(post_json_object, postFilename): print('mutePost: saved ' + postFilename) # remove cached post so that the muted version gets recreated @@ -708,7 +708,7 @@ def unmutePost(base_dir: str, nickname: str, domain: str, port: int, igItLen = len(postJsonObj['ignores']['items']) postJsonObj['ignores']['totalItems'] = igItLen postJsonObj['muted'] = False - saveJson(post_json_object, postFilename) + save_json(post_json_object, postFilename) # remove cached post so that the muted version gets recreated # with its content text and/or image diff --git a/bookmarks.py b/bookmarks.py index 0ef12e888..ef259fd1c 100644 --- a/bookmarks.py +++ b/bookmarks.py @@ -22,7 +22,7 @@ from utils import getDomainFromActor from utils import locatePost from utils import getCachedPostFilename from utils import loadJson -from utils import saveJson +from utils import save_json from utils import has_object_dict from utils import acct_dir from utils import local_actor_url @@ -122,7 +122,7 @@ def undoBookmarksCollectionEntry(recentPostsCache: {}, else: bmItLen = len(post_json_object['object']['bookmarks']['items']) post_json_object['object']['bookmarks']['totalItems'] = bmItLen - saveJson(post_json_object, postFilename) + save_json(post_json_object, postFilename) def bookmarkedByPerson(post_json_object: {}, @@ -220,7 +220,7 @@ def updateBookmarksCollection(recentPostsCache: {}, print('DEBUG: saving post with bookmarks added') pprint(post_json_object) - saveJson(post_json_object, postFilename) + save_json(post_json_object, postFilename) # prepend to the index bookmarksIndexFilename = \ diff --git a/cache.py b/cache.py index 26e82845f..8b3ceab7b 100644 --- a/cache.py +++ b/cache.py @@ -12,7 +12,7 @@ import datetime from session import urlExists from session import getJson from utils import loadJson -from utils import saveJson +from utils import save_json from utils import getFileCaseInsensitive from utils import get_user_paths @@ -74,7 +74,7 @@ def storePersonInCache(base_dir: str, personUrl: str, cacheFilename = base_dir + '/cache/actors/' + \ personUrl.replace('/', '#') + '.json' if not os.path.isfile(cacheFilename): - saveJson(personJson, cacheFilename) + save_json(personJson, cacheFilename) def getPersonFromCache(base_dir: str, personUrl: str, person_cache: {}, diff --git a/content.py b/content.py index 24811e34a..c2fc74332 100644 --- a/content.py +++ b/content.py @@ -16,7 +16,7 @@ from utils import removeDomainPort from utils import isValidLanguage from utils import get_image_extensions from utils import loadJson -from utils import saveJson +from utils import save_json from utils import fileLastModified from utils import getLinkPrefixes from utils import dangerousMarkup @@ -282,7 +282,7 @@ def _saveCustomEmoji(session, base_dir: str, emojiName: str, url: str, emojiJson = {} if not emojiJson.get(emojiName): emojiJson[emojiName] = emojiName - saveJson(emojiJson, emojiJsonFilename) + save_json(emojiJson, emojiJsonFilename) if debug: print('EX: Saved custom emoji ' + emojiJsonFilename) elif debug: diff --git a/daemon.py b/daemon.py index 8e3e95715..5516feec0 100644 --- a/daemon.py +++ b/daemon.py @@ -298,7 +298,7 @@ from utils import getDomainFromActor from utils import getStatusNumber from utils import urlPermitted from utils import loadJson -from utils import saveJson +from utils import save_json from utils import isSuspended from utils import dangerousMarkup from utils import refresh_newswire @@ -429,8 +429,8 @@ class PubServer(BaseHTTPRequestHandler): for ua in removeCrawlers: del self.server.knownCrawlers[ua] # save the list of crawlers - saveJson(self.server.knownCrawlers, - self.server.base_dir + '/accounts/knownCrawlers.json') + save_json(self.server.knownCrawlers, + self.server.base_dir + '/accounts/knownCrawlers.json') self.server.lastKnownCrawler = curr_time def _get_instance_url(self, callingDomain: str) -> str: @@ -2112,7 +2112,7 @@ class PubServer(BaseHTTPRequestHandler): if saveKeys: accessKeysFilename = \ acct_dir(base_dir, nickname, domain) + '/accessKeys.json' - saveJson(accessKeys, accessKeysFilename) + save_json(accessKeys, accessKeysFilename) if not self.server.keyShortcuts.get(nickname): self.server.keyShortcuts[nickname] = accessKeys.copy() @@ -4653,8 +4653,8 @@ class PubServer(BaseHTTPRequestHandler): newswireStateFilename = \ base_dir + '/accounts/.newswirestate.json' try: - saveJson(self.server.newswire, - newswireStateFilename) + save_json(self.server.newswire, + newswireStateFilename) except Exception as ex: print('ERROR: saving newswire state, ' + str(ex)) @@ -4665,7 +4665,7 @@ class PubServer(BaseHTTPRequestHandler): newsId) # save the news post - saveJson(post_json_object, postFilename) + save_json(post_json_object, postFilename) # redirect back to the default timeline if self.server.news_instance: @@ -6497,7 +6497,7 @@ class PubServer(BaseHTTPRequestHandler): randomizeActorImages(actor_json) addActorUpdateTimestamp(actor_json) # save the actor - saveJson(actor_json, actorFilename) + save_json(actor_json, actorFilename) webfingerUpdate(base_dir, nickname, domain, onion_domain, @@ -6515,7 +6515,7 @@ class PubServer(BaseHTTPRequestHandler): actorCacheFilename = \ base_dir + '/cache/actors/' + \ actor_json['id'].replace('/', '#') + '.json' - saveJson(actor_json, actorCacheFilename) + save_json(actor_json, actorCacheFilename) # send profile update to followers pubNumber, pubDate = getStatusNumber() updateActorJson = getActorUpdateJson(actor_json) @@ -7969,12 +7969,12 @@ class PubServer(BaseHTTPRequestHandler): newswireStateFilename = \ base_dir + '/accounts/.newswirestate.json' try: - saveJson(newswire, newswireStateFilename) + save_json(newswire, newswireStateFilename) except Exception as ex: print('ERROR: saving newswire state, ' + str(ex)) if filename: - saveJson(newswireItem[votesIndex], - filename + '.votes') + save_json(newswireItem[votesIndex], + filename + '.votes') else: print('No newswire item with date: ' + dateStr + ' ' + str(newswire)) @@ -8023,12 +8023,12 @@ class PubServer(BaseHTTPRequestHandler): newswireStateFilename = \ base_dir + '/accounts/.newswirestate.json' try: - saveJson(newswire, newswireStateFilename) + save_json(newswire, newswireStateFilename) except Exception as ex: print('ERROR: saving newswire state, ' + str(ex)) if filename: - saveJson(newswireItem[votesIndex], - filename + '.votes') + save_json(newswireItem[votesIndex], + filename + '.votes') else: print('No newswire item with date: ' + dateStr + ' ' + str(newswire)) @@ -16829,14 +16829,14 @@ class PubServer(BaseHTTPRequestHandler): replaceTwitter(post_json_object, self.server.twitter_replacement_domain, self.server.system_language) - saveJson(post_json_object, postFilename) + save_json(post_json_object, postFilename) # also save to the news actor if nickname != 'news': postFilename = \ postFilename.replace('#users#' + nickname + '#', '#users#news#') - saveJson(post_json_object, postFilename) + save_json(post_json_object, postFilename) print('Edited blog post, resaved ' + postFilename) return 1 else: diff --git a/devices.py b/devices.py index be377950e..8ef19aa1a 100644 --- a/devices.py +++ b/devices.py @@ -32,7 +32,7 @@ __module_group__ = "Security" import os from utils import loadJson -from utils import saveJson +from utils import save_json from utils import acct_dir from utils import local_actor_url @@ -136,7 +136,7 @@ def E2EEaddDevice(base_dir: str, nickname: str, domain: str, } } deviceFilename = personDir + '/devices/' + deviceId + '.json' - return saveJson(deviceDict, deviceFilename) + return save_json(deviceDict, deviceFilename) def E2EEdevicesCollection(base_dir: str, nickname: str, domain: str, diff --git a/fitnessFunctions.py b/fitnessFunctions.py index 35fec3735..944070966 100644 --- a/fitnessFunctions.py +++ b/fitnessFunctions.py @@ -12,7 +12,7 @@ import time from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter from utils import get_config_param -from utils import saveJson +from utils import save_json def fitnessPerformance(startTime, fitnessState: {}, @@ -124,4 +124,4 @@ def fitnessThread(base_dir: str, fitness: {}): while True: # every 10 mins time.sleep(60 * 10) - saveJson(fitness, fitness_filename) + save_json(fitness, fitness_filename) diff --git a/follow.py b/follow.py index 215a926ce..4979a6e30 100644 --- a/follow.py +++ b/follow.py @@ -24,7 +24,7 @@ from utils import followPerson from posts import sendSignedJson from posts import getPersonBox from utils import loadJson -from utils import saveJson +from utils import save_json from utils import isAccountDir from utils import get_user_paths from utils import acct_dir @@ -711,7 +711,7 @@ def storeFollowRequest(base_dir: str, if not os.path.isdir(requestsDir): os.mkdir(requestsDir) followActivityfilename = requestsDir + '/' + approveHandle + '.follow' - return saveJson(followJson, followActivityfilename) + return save_json(followJson, followActivityfilename) def followedAccountAccepts(session, base_dir: str, http_prefix: str, diff --git a/happening.py b/happening.py index cc2ae8722..266ae1439 100644 --- a/happening.py +++ b/happening.py @@ -14,7 +14,7 @@ from datetime import timedelta from utils import isPublicPost from utils import loadJson -from utils import saveJson +from utils import save_json from utils import locatePost from utils import has_object_dict from utils import acct_dir @@ -92,7 +92,7 @@ def saveEventPost(base_dir: str, handle: str, postId: str, eventTime.strftime("%d") + '_' + eventJson['uuid'] eventFilename = eventsYearPath + '/' + eventId + '.json' - saveJson(eventJson, eventFilename) + save_json(eventJson, eventFilename) # save to the events timeline tlEventsFilename = base_dir + '/accounts/' + handle + '/events.txt' diff --git a/inbox.py b/inbox.py index 7ce7935f8..bcc02f19f 100644 --- a/inbox.py +++ b/inbox.py @@ -55,7 +55,7 @@ from utils import locatePost from utils import deletePost from utils import removeModerationPostFromIndex from utils import loadJson -from utils import saveJson +from utils import save_json from utils import undoLikesCollectionEntry from utils import undoReactionCollectionEntry from utils import hasGroupType @@ -591,7 +591,7 @@ def savePostToInboxQueue(base_dir: str, http_prefix: str, if debug: print('Inbox queue item created') - saveJson(newQueueItem, filename) + save_json(newQueueItem, filename) return filename @@ -887,7 +887,7 @@ def _personReceiveUpdate(base_dir: str, storePersonInCache(base_dir, personJson['id'], personJson, person_cache, True) # save to cache on file - if saveJson(personJson, actorFilename): + if save_json(personJson, actorFilename): if debug: print('actor updated for ' + personJson['id']) @@ -924,7 +924,7 @@ def _receiveUpdateToQuestion(recentPostsCache: {}, message_json: {}, # does the actor match? if post_json_object['actor'] != message_json['actor']: return - saveJson(message_json, postFilename) + save_json(message_json, postFilename) # ensure that the cached post is removed if it exists, so # that it then will be recreated cachedPostFilename = \ @@ -3526,7 +3526,7 @@ def _inboxAfterInitial(recentPostsCache: {}, max_recent_posts: int, signing_priv_key_pem) # save the post to file - if saveJson(post_json_object, destinationFilename): + if save_json(post_json_object, destinationFilename): _lowFrequencyPostNotification(base_dir, http_prefix, nickname, domain, port, handle, postIsDM, jsonObj) @@ -4487,7 +4487,7 @@ def runInboxQueue(recentPostsCache: {}, max_recent_posts: int, sharedInboxPostFilename = \ queueJson['destination'].replace(inboxHandle, inboxHandle) if not os.path.isfile(sharedInboxPostFilename): - saveJson(queueJson['post'], sharedInboxPostFilename) + save_json(queueJson['post'], sharedInboxPostFilename) lists_enabled = get_config_param(base_dir, "lists_enabled") content_license_url = get_config_param(base_dir, "content_license_url") diff --git a/like.py b/like.py index fb4655df2..fe2f537d5 100644 --- a/like.py +++ b/like.py @@ -25,7 +25,7 @@ from utils import undoLikesCollectionEntry from utils import hasGroupType from utils import local_actor_url from utils import loadJson -from utils import saveJson +from utils import save_json from utils import removePostFromCache from utils import getCachedPostFilename from posts import sendSignedJson @@ -474,4 +474,4 @@ def updateLikesCollection(recentPostsCache: {}, if debug: print('DEBUG: saving post with likes added') pprint(post_json_object) - saveJson(post_json_object, postFilename) + save_json(post_json_object, postFilename) diff --git a/newsdaemon.py b/newsdaemon.py index adf18c617..2edf060a8 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -29,7 +29,7 @@ from utils import get_base_content_from_post from utils import removeHtml from utils import get_full_domain from utils import loadJson -from utils import saveJson +from utils import save_json from utils import getStatusNumber from utils import clearFromPostCaches from utils import dangerousMarkup @@ -731,7 +731,7 @@ def _convertRSStoActivityPub(base_dir: str, http_prefix: str, blog, translate) clearFromPostCaches(base_dir, recentPostsCache, postId) - if saveJson(blog, filename): + if save_json(blog, filename): _updateFeedsOutboxIndex(base_dir, domain, postId + '.json') # Save a file containing the time when the post arrived @@ -817,7 +817,7 @@ def runNewswireDaemon(base_dir: str, httpd, httpd.newswire = newNewswire if newNewswire: - saveJson(httpd.newswire, newswireStateFilename) + save_json(httpd.newswire, newswireStateFilename) print('Newswire updated') else: print('No new newswire') diff --git a/newswire.py b/newswire.py index e58b60d8a..1b8d4c417 100644 --- a/newswire.py +++ b/newswire.py @@ -26,7 +26,7 @@ from utils import firstParagraphFromString from utils import isPublicPost from utils import locatePost from utils import loadJson -from utils import saveJson +from utils import save_json from utils import isSuspended from utils import containsInvalidChars from utils import removeHtml @@ -1124,7 +1124,7 @@ def _addBlogsToNewswire(base_dir: str, domain: str, newswire: {}, # save the moderation queue details for later display newswireModerationFilename = base_dir + '/accounts/newswiremoderation.txt' if sortedModerationDict: - saveJson(sortedModerationDict, newswireModerationFilename) + save_json(sortedModerationDict, newswireModerationFilename) else: # remove the file if there is nothing to moderate if os.path.isfile(newswireModerationFilename): diff --git a/outbox.py b/outbox.py index 307501510..86e2261d7 100644 --- a/outbox.py +++ b/outbox.py @@ -26,7 +26,7 @@ from utils import getDomainFromActor from utils import dangerousMarkup from utils import is_featured_writer from utils import loadJson -from utils import saveJson +from utils import save_json from utils import acct_dir from utils import local_actor_url from utils import hasActor @@ -167,7 +167,7 @@ def _outboxPersonReceiveUpdate(recentPostsCache: {}, actorChanged = True # save actor to file if actorChanged: - saveJson(actor_json, actorFilename) + save_json(actor_json, actorFilename) if debug: print('actor saved: ' + actorFilename) if debug: diff --git a/person.py b/person.py index dc9a504d2..d39ce9113 100644 --- a/person.py +++ b/person.py @@ -47,7 +47,7 @@ from utils import getStatusNumber from utils import get_full_domain from utils import validNickname from utils import loadJson -from utils import saveJson +from utils import save_json from utils import setConfigParam from utils import get_config_param from utils import refresh_newswire @@ -151,7 +151,7 @@ def setProfileImage(base_dir: str, http_prefix: str, personJson[iconFilenameBase]['url'] = \ local_actor_url(http_prefix, nickname, fullDomain) + \ '/' + iconFilename - saveJson(personJson, personFilename) + save_json(personJson, personFilename) cmd = \ '/usr/bin/convert ' + image_filename + ' -size ' + \ @@ -497,7 +497,7 @@ def _createPersonBase(base_dir: str, nickname: str, domain: str, port: int, handle + '/queue'): os.mkdir(base_dir + peopleSubdir + '/' + handle + '/queue') filename = base_dir + peopleSubdir + '/' + handle + '.json' - saveJson(newPerson, filename) + save_json(newPerson, filename) # save to cache if not os.path.isdir(base_dir + '/cache'): @@ -506,7 +506,7 @@ def _createPersonBase(base_dir: str, nickname: str, domain: str, port: int, os.mkdir(base_dir + '/cache/actors') cacheFilename = base_dir + '/cache/actors/' + \ newPerson['id'].replace('/', '#') + '.json' - saveJson(newPerson, cacheFilename) + save_json(newPerson, cacheFilename) # save the private key privateKeysSubdir = '/keys/private' @@ -840,14 +840,14 @@ def personUpgradeActor(base_dir: str, personJson: {}, getDefaultPersonContext() ], - saveJson(personJson, filename) + save_json(personJson, filename) # also update the actor within the cache actorCacheFilename = \ base_dir + '/accounts/cache/actors/' + \ personJson['id'].replace('/', '#') + '.json' if os.path.isfile(actorCacheFilename): - saveJson(personJson, actorCacheFilename) + save_json(personJson, actorCacheFilename) # update domain/@nickname in actors cache actorCacheFilename = \ @@ -855,7 +855,7 @@ def personUpgradeActor(base_dir: str, personJson: {}, replaceUsersWithAt(personJson['id']).replace('/', '#') + \ '.json' if os.path.isfile(actorCacheFilename): - saveJson(personJson, actorCacheFilename) + save_json(personJson, actorCacheFilename) def personLookup(domain: str, path: str, base_dir: str) -> {}: @@ -1013,7 +1013,7 @@ def setDisplayNickname(base_dir: str, nickname: str, domain: str, if not personJson: return False personJson['name'] = displayName - saveJson(personJson, filename) + save_json(personJson, filename) return True @@ -1034,7 +1034,7 @@ def setBio(base_dir: str, nickname: str, domain: str, bio: str) -> bool: return False personJson['summary'] = bio - saveJson(personJson, filename) + save_json(personJson, filename) return True diff --git a/posts.py b/posts.py index 447a9bceb..db9af351e 100644 --- a/posts.py +++ b/posts.py @@ -60,7 +60,7 @@ from utils import deletePost from utils import validNickname from utils import locatePost from utils import loadJson -from utils import saveJson +from utils import save_json from utils import get_config_param from utils import locateNewsVotes from utils import locateNewsArrival @@ -931,7 +931,7 @@ def savePostToBox(base_dir: str, http_prefix: str, postId: str, boxDir = createPersonDir(nickname, domain, base_dir, boxname) filename = boxDir + '/' + postId.replace('/', '#') + '.json' - saveJson(post_json_object, filename) + save_json(post_json_object, filename) return filename @@ -4737,7 +4737,7 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str, replaceYouTube(post_json_object, yt_replace_domain, system_language) replaceTwitter(post_json_object, twitter_replacement_domain, system_language) - if saveJson(post_json_object, announceFilename): + if save_json(post_json_object, announceFilename): return post_json_object return None diff --git a/question.py b/question.py index 2d2a5fb2d..8b997347f 100644 --- a/question.py +++ b/question.py @@ -10,7 +10,7 @@ __module_group__ = "ActivityPub" import os from utils import locatePost from utils import loadJson -from utils import saveJson +from utils import save_json from utils import has_object_dict @@ -116,7 +116,7 @@ def questionUpdateVotes(base_dir: str, nickname: str, domain: str, if not questionTotalsChanged: return None, None # save the question with altered totals - saveJson(questionJson, questionPostFilename) + save_json(questionJson, questionPostFilename) return questionJson, questionPostFilename diff --git a/reaction.py b/reaction.py index 57030bc92..a1a1d0dea 100644 --- a/reaction.py +++ b/reaction.py @@ -27,7 +27,7 @@ from utils import undoReactionCollectionEntry from utils import hasGroupType from utils import local_actor_url from utils import loadJson -from utils import saveJson +from utils import save_json from utils import removePostFromCache from utils import getCachedPostFilename from utils import containsInvalidChars @@ -510,7 +510,7 @@ def updateReactionCollection(recentPostsCache: {}, if debug: print('DEBUG: saving post with emoji reaction added') pprint(post_json_object) - saveJson(post_json_object, postFilename) + save_json(post_json_object, postFilename) def htmlEmojiReactions(post_json_object: {}, interactive: bool, diff --git a/roles.py b/roles.py index 4e7d92e48..4af1e1484 100644 --- a/roles.py +++ b/roles.py @@ -9,7 +9,7 @@ __module_group__ = "Profile Metadata" import os from utils import loadJson -from utils import saveJson +from utils import save_json from utils import getStatusNumber from utils import removeDomainPort from utils import acct_dir @@ -38,7 +38,7 @@ def _clearRoleStatus(base_dir: str, role: str) -> None: if role in rolesList: rolesList.remove(role) setRolesFromList(actor_json, rolesList) - saveJson(actor_json, filename) + save_json(actor_json, filename) def clearEditorStatus(base_dir: str) -> None: @@ -266,7 +266,7 @@ def setRole(base_dir: str, nickname: str, domain: str, setRolesFromList(actor_json, rolesList) actorChanged = True if actorChanged: - saveJson(actor_json, actorFilename) + save_json(actor_json, actorFilename) return True diff --git a/shares.py b/shares.py index 4e94f4e4c..d1132b3d1 100644 --- a/shares.py +++ b/shares.py @@ -29,7 +29,7 @@ from utils import get_config_param from utils import get_full_domain from utils import validNickname from utils import loadJson -from utils import saveJson +from utils import save_json from utils import get_image_extensions from utils import removeDomainPort from utils import isAccountDir @@ -153,7 +153,7 @@ def removeSharedItem(base_dir: str, nickname: str, domain: str, itemIDfile + '.' + ext) # remove the item itself del sharesJson[itemID] - saveJson(sharesJson, sharesFilename) + save_json(sharesJson, sharesFilename) else: print('ERROR: share index "' + itemID + '" does not exist in ' + sharesFilename) @@ -389,7 +389,7 @@ def addShare(base_dir: str, "itemCurrency": currency } - saveJson(sharesJson, sharesFilename) + save_json(sharesJson, sharesFilename) _indicateNewShareAvailable(base_dir, http_prefix, nickname, domain, domain_full, @@ -443,7 +443,7 @@ def _expireSharesForAccount(base_dir: str, nickname: str, domain: str, except OSError: print('EX: _expireSharesForAccount unable to delete ' + itemIDfile + '.' + ext) - saveJson(sharesJson, sharesFilename) + save_json(sharesJson, sharesFilename) def getSharesFeedForPerson(base_dir: str, @@ -1394,7 +1394,7 @@ def generateSharedItemFederationTokens(shared_items_federated_domains: [], if not tokensAdded: return tokensJson if base_dir: - saveJson(tokensJson, tokensFilename) + save_json(tokensJson, tokensFilename) return tokensJson @@ -1426,7 +1426,7 @@ def updateSharedItemFederationToken(base_dir: str, if updateRequired: tokensJson[tokenDomainFull] = newToken if base_dir: - saveJson(tokensJson, tokensFilename) + save_json(tokensJson, tokensFilename) return tokensJson @@ -1456,7 +1456,7 @@ def mergeSharedItemTokens(base_dir: str, domain_full: str, if base_dir and changed: tokensFilename = \ base_dir + '/accounts/sharedItemsFederationTokens.json' - saveJson(tokensJson, tokensFilename) + save_json(tokensJson, tokensFilename) return tokensJson @@ -1478,7 +1478,7 @@ def createSharedItemFederationToken(base_dir: str, if force or not tokensJson.get(tokenDomainFull): tokensJson[tokenDomainFull] = secrets.token_urlsafe(64) if base_dir: - saveJson(tokensJson, tokensFilename) + save_json(tokensJson, tokensFilename) return tokensJson @@ -1587,7 +1587,7 @@ def _updateFederatedSharesCache(session, shared_items_federated_domains: [], federatedDomainFull) continue catalogFilename = catalogsDir + '/' + federatedDomainFull + '.json' - if saveJson(catalogJson, catalogFilename): + if save_json(catalogJson, catalogFilename): print('Downloaded shared items catalog for ' + federatedDomainFull) sharesJson = _dfcToSharesFormat(catalogJson, base_dir, system_language, @@ -1596,7 +1596,7 @@ def _updateFederatedSharesCache(session, shared_items_federated_domains: [], sharesFilename = \ catalogsDir + '/' + federatedDomainFull + '.' + \ sharesFileType + '.json' - saveJson(sharesJson, sharesFilename) + save_json(sharesJson, sharesFilename) print('Converted shares catalog for ' + federatedDomainFull) else: time.sleep(2) diff --git a/speaker.py b/speaker.py index 0b9a45791..72b12ef3f 100644 --- a/speaker.py +++ b/speaker.py @@ -21,7 +21,7 @@ from utils import getGenderFromBio from utils import getDisplayName from utils import removeHtml from utils import loadJson -from utils import saveJson +from utils import save_json from utils import isPGPEncrypted from utils import has_object_dict from utils import acct_dir @@ -549,4 +549,4 @@ def updateSpeaker(base_dir: str, http_prefix: str, translate, announcingActor, theme_name) speakerFilename = acct_dir(base_dir, nickname, domain) + '/speaker.json' - saveJson(speakerJson, speakerFilename) + save_json(speakerJson, speakerFilename) diff --git a/tests.py b/tests.py index 3503ff768..26a794225 100644 --- a/tests.py +++ b/tests.py @@ -79,7 +79,7 @@ from utils import getNicknameFromActor from utils import getDomainFromActor from utils import copytree from utils import loadJson -from utils import saveJson +from utils import save_json from utils import getStatusNumber from utils import getFollowersOfPerson from utils import removeHtml @@ -3473,7 +3473,7 @@ def _testJsonString() -> None: testJson = { "content": messageStr } - assert saveJson(testJson, filename) + assert save_json(testJson, filename) receivedJson = loadJson(filename, 0) assert receivedJson assert receivedJson['content'] == messageStr @@ -3497,7 +3497,7 @@ def _testSaveLoadJson(): os.remove(testFilename) except OSError: pass - assert saveJson(testJson, testFilename) + assert save_json(testJson, testFilename) assert os.path.isfile(testFilename) testLoadJson = loadJson(testFilename) assert(testLoadJson) @@ -5754,7 +5754,7 @@ def _translateOntology(base_dir: str) -> None: changed = True if not changed: continue - saveJson(ontologyJson, filename + '.new') + save_json(ontologyJson, filename + '.new') def _testCanReplyTo(base_dir: str) -> None: diff --git a/theme.py b/theme.py index fc57282ca..6dffdcc41 100644 --- a/theme.py +++ b/theme.py @@ -10,7 +10,7 @@ __module_group__ = "Web Interface" import os from utils import isAccountDir from utils import loadJson -from utils import saveJson +from utils import save_json from utils import get_image_extensions from utils import copytree from utils import acct_dir @@ -171,7 +171,7 @@ def _setThemeInConfig(base_dir: str, name: str) -> bool: if not configJson: return False configJson['theme'] = name - return saveJson(configJson, config_filename) + return save_json(configJson, config_filename) def _setNewswirePublishAsIcon(base_dir: str, useIcon: bool) -> bool: @@ -184,7 +184,7 @@ def _setNewswirePublishAsIcon(base_dir: str, useIcon: bool) -> bool: if not configJson: return False configJson['show_publish_as_icon'] = useIcon - return saveJson(configJson, config_filename) + return save_json(configJson, config_filename) def _setIconsAsButtons(base_dir: str, useButtons: bool) -> bool: @@ -198,7 +198,7 @@ def _setIconsAsButtons(base_dir: str, useButtons: bool) -> bool: if not configJson: return False configJson['icons_as_buttons'] = useButtons - return saveJson(configJson, config_filename) + return save_json(configJson, config_filename) def _setRssIconAtTop(base_dir: str, atTop: bool) -> bool: @@ -211,7 +211,7 @@ def _setRssIconAtTop(base_dir: str, atTop: bool) -> bool: if not configJson: return False configJson['rss_icon_at_top'] = atTop - return saveJson(configJson, config_filename) + return save_json(configJson, config_filename) def _setPublishButtonAtTop(base_dir: str, atTop: bool) -> bool: @@ -225,7 +225,7 @@ def _setPublishButtonAtTop(base_dir: str, atTop: bool) -> bool: if not configJson: return False configJson['publish_button_at_top'] = atTop - return saveJson(configJson, config_filename) + return save_json(configJson, config_filename) def _setFullWidthTimelineButtonHeader(base_dir: str, fullWidth: bool) -> bool: @@ -239,7 +239,7 @@ def _setFullWidthTimelineButtonHeader(base_dir: str, fullWidth: bool) -> bool: if not configJson: return False configJson['full_width_tl_button_header'] = fullWidth - return saveJson(configJson, config_filename) + return save_json(configJson, config_filename) def getTheme(base_dir: str) -> str: @@ -497,7 +497,7 @@ def setThemeFromDesigner(base_dir: str, theme_name: str, domain: str, allow_local_network_access: bool, system_language: str): customThemeFilename = base_dir + '/accounts/theme.json' - saveJson(themeParams, customThemeFilename) + save_json(themeParams, customThemeFilename) setTheme(base_dir, theme_name, domain, allow_local_network_access, system_language) diff --git a/utils.py b/utils.py index 8433f648e..d5ee71221 100644 --- a/utils.py +++ b/utils.py @@ -502,7 +502,7 @@ def _create_config(base_dir: str) -> None: return config_json = { } - saveJson(config_json, config_filename) + save_json(config_json, config_filename) def setConfigParam(base_dir: str, variableName: str, variableValue) -> None: @@ -514,7 +514,7 @@ def setConfigParam(base_dir: str, variableName: str, variableValue) -> None: if os.path.isfile(config_filename): configJson = loadJson(config_filename) configJson[variableName] = variableValue - saveJson(configJson, config_filename) + save_json(configJson, config_filename) def get_config_param(base_dir: str, variableName: str): @@ -654,7 +654,7 @@ def removeAvatarFromCache(base_dir: str, actorStr: str) -> None: 'unable to delete cached avatar ' + str(avatarFilename)) -def saveJson(jsonObject: {}, filename: str) -> bool: +def save_json(jsonObject: {}, filename: str) -> bool: """Saves json to a file """ tries = 0 @@ -664,7 +664,7 @@ def saveJson(jsonObject: {}, filename: str) -> bool: fp.write(json.dumps(jsonObject)) return True except OSError: - print('EX: saveJson ' + str(tries)) + print('EX: save_json ' + str(tries)) time.sleep(1) tries += 1 return False @@ -2267,7 +2267,7 @@ def undoLikesCollectionEntry(recentPostsCache: {}, itlen = len(obj['likes']['items']) obj['likes']['totalItems'] = itlen - saveJson(post_json_object, postFilename) + save_json(post_json_object, postFilename) def undoReactionCollectionEntry(recentPostsCache: {}, @@ -2333,7 +2333,7 @@ def undoReactionCollectionEntry(recentPostsCache: {}, itlen = len(obj['reactions']['items']) obj['reactions']['totalItems'] = itlen - saveJson(post_json_object, postFilename) + save_json(post_json_object, postFilename) def undoAnnounceCollectionEntry(recentPostsCache: {}, @@ -2400,7 +2400,7 @@ def undoAnnounceCollectionEntry(recentPostsCache: {}, itlen = len(post_json_object['object']['shares']['items']) post_json_object['object']['shares']['totalItems'] = itlen - saveJson(post_json_object, postFilename) + save_json(post_json_object, postFilename) def updateAnnounceCollection(recentPostsCache: {}, @@ -2473,7 +2473,7 @@ def updateAnnounceCollection(recentPostsCache: {}, if debug: print('DEBUG: saving post with shares (announcements) added') pprint(post_json_object) - saveJson(post_json_object, postFilename) + save_json(post_json_object, postFilename) def weekDayOfMonthStart(monthNumber: int, year: int) -> int: diff --git a/webfinger.py b/webfinger.py index 3ff9b6b26..3bfe096ca 100644 --- a/webfinger.py +++ b/webfinger.py @@ -15,7 +15,7 @@ from cache import getWebfingerFromCache from utils import get_full_domain from utils import loadJson from utils import loadJsonOnionify -from utils import saveJson +from utils import save_json from utils import getProtocolPrefixes from utils import removeDomainPort from utils import get_user_paths @@ -122,11 +122,11 @@ def storeWebfingerEndpoint(nickname: str, domain: str, port: int, if not os.path.isdir(base_dir + wfSubdir): os.mkdir(base_dir + wfSubdir) filename = base_dir + wfSubdir + '/' + handle + '.json' - saveJson(wfJson, filename) + save_json(wfJson, filename) if nickname == 'inbox': handle = originalDomain + '@' + domain filename = base_dir + wfSubdir + '/' + handle + '.json' - saveJson(wfJson, filename) + save_json(wfJson, filename) return True @@ -447,5 +447,5 @@ def webfingerUpdate(base_dir: str, nickname: str, domain: str, return if _webfingerUpdateFromProfile(wfJson, actor_json): - if saveJson(wfJson, filename): + if save_json(wfJson, filename): storeWebfingerInCache(handle, wfJson, cached_webfingers)