From 6953b2cd4381c792766c58c4f30ea2498d23f8d7 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 25 Nov 2021 18:42:38 +0000 Subject: [PATCH] More specific exceptions --- auth.py | 64 +++++++++---- blocking.py | 71 ++++++++++----- blog.py | 15 ++- bookmarks.py | 25 +++-- cache.py | 3 +- categories.py | 25 +++-- content.py | 16 ++-- conversation.py | 15 +-- daemon.py | 196 ++++++++++++++++++++-------------------- delete.py | 3 +- devices.py | 3 +- follow.py | 9 +- inbox.py | 54 ++++------- like.py | 3 +- manualapprove.py | 6 +- media.py | 6 +- newsdaemon.py | 6 +- newswire.py | 3 +- outbox.py | 3 +- person.py | 21 ++--- posts.py | 5 +- reaction.py | 3 +- schedule.py | 12 +-- session.py | 3 +- shares.py | 9 +- tests.py | 6 +- theme.py | 34 +++---- utils.py | 48 ++++------ webapp_calendar.py | 3 +- webapp_minimalbutton.py | 10 +- webapp_timeline.py | 15 +-- webapp_utils.py | 3 +- 32 files changed, 342 insertions(+), 356 deletions(-) diff --git a/auth.py b/auth.py index 8b1df333e..42dac82b9 100644 --- a/auth.py +++ b/auth.py @@ -163,21 +163,38 @@ def storeBasicCredentials(baseDir: str, nickname: str, password: str) -> bool: storeStr = nickname + ':' + _hashPassword(password) if os.path.isfile(passwordFile): if nickname + ':' in open(passwordFile).read(): - with open(passwordFile, 'r') as fin: - with open(passwordFile + '.new', 'w+') as fout: - for line in fin: - if not line.startswith(nickname + ':'): - fout.write(line) - else: - fout.write(storeStr + '\n') - os.rename(passwordFile + '.new', passwordFile) + try: + with open(passwordFile, 'r') as fin: + with open(passwordFile + '.new', 'w+') as fout: + for line in fin: + if not line.startswith(nickname + ':'): + fout.write(line) + else: + fout.write(storeStr + '\n') + except OSError: + print('WARN: unable to save password ' + passwordFile) + return False + + try: + os.rename(passwordFile + '.new', passwordFile) + except OSError: + print('WARN: unable to save password 2') + return False else: # append to password file - with open(passwordFile, 'a+') as passfile: - passfile.write(storeStr + '\n') + try: + with open(passwordFile, 'a+') as passfile: + passfile.write(storeStr + '\n') + except OSError: + print('WARN: unable to append password') + return False else: - with open(passwordFile, 'w+') as passfile: - passfile.write(storeStr + '\n') + try: + with open(passwordFile, 'w+') as passfile: + passfile.write(storeStr + '\n') + except OSError: + print('WARN: unable to create password file') + return False return True @@ -187,12 +204,21 @@ def removePassword(baseDir: str, nickname: str) -> None: """ passwordFile = baseDir + '/accounts/passwords' if os.path.isfile(passwordFile): - with open(passwordFile, 'r') as fin: - with open(passwordFile + '.new', 'w+') as fout: - for line in fin: - if not line.startswith(nickname + ':'): - fout.write(line) - os.rename(passwordFile + '.new', passwordFile) + try: + with open(passwordFile, 'r') as fin: + with open(passwordFile + '.new', 'w+') as fout: + for line in fin: + if not line.startswith(nickname + ':'): + fout.write(line) + except OSError: + print('WARN: unable to remove password from file') + return + + try: + os.rename(passwordFile + '.new', passwordFile) + except OSError: + print('WARN: unable to remove password from file 2') + return def authorize(baseDir: str, path: str, authHeader: str, debug: bool) -> bool: @@ -254,6 +280,6 @@ def recordLoginFailure(baseDir: str, ipAddress: str, 'Disconnecting invalid user epicyon ' + ipAddress + ' port 443: ' + 'Too many authentication failures [preauth]\n') - except BaseException: + except OSError: print('EX: recordLoginFailure failed ' + str(failureLog)) pass diff --git a/blocking.py b/blocking.py index 75644c522..8c48aa1d7 100644 --- a/blocking.py +++ b/blocking.py @@ -146,11 +146,17 @@ def removeGlobalBlock(baseDir: str, if os.path.isfile(unblockingFilename): if unblockHandle in open(unblockingFilename).read(): with open(unblockingFilename, 'r') as fp: - with open(unblockingFilename + '.new', 'w+') as fpnew: - for line in fp: - handle = line.replace('\n', '').replace('\r', '') - if unblockHandle not in line: - fpnew.write(handle + '\n') + try: + with open(unblockingFilename + '.new', 'w+') as fpnew: + for line in fp: + handle = \ + line.replace('\n', '').replace('\r', '') + if unblockHandle not in line: + fpnew.write(handle + '\n') + except OSError: + print('WARN: failed to remove global block ' + + unblockingFilename) + return False if os.path.isfile(unblockingFilename + '.new'): os.rename(unblockingFilename + '.new', unblockingFilename) return True @@ -159,12 +165,17 @@ def removeGlobalBlock(baseDir: str, if os.path.isfile(unblockingFilename): if unblockHashtag + '\n' in open(unblockingFilename).read(): with open(unblockingFilename, 'r') as fp: - with open(unblockingFilename + '.new', 'w+') as fpnew: - for line in fp: - blockLine = \ - line.replace('\n', '').replace('\r', '') - if unblockHashtag not in line: - fpnew.write(blockLine + '\n') + try: + with open(unblockingFilename + '.new', 'w+') as fpnew: + for line in fp: + blockLine = \ + line.replace('\n', '').replace('\r', '') + if unblockHashtag not in line: + fpnew.write(blockLine + '\n') + except OSError: + print('WARN: failed to remove global hashtag block ' + + unblockingFilename) + return False if os.path.isfile(unblockingFilename + '.new'): os.rename(unblockingFilename + '.new', unblockingFilename) return True @@ -181,11 +192,15 @@ def removeBlock(baseDir: str, nickname: str, domain: str, if os.path.isfile(unblockingFilename): if unblockHandle in open(unblockingFilename).read(): with open(unblockingFilename, 'r') as fp: - with open(unblockingFilename + '.new', 'w+') as fpnew: - for line in fp: - handle = line.replace('\n', '').replace('\r', '') - if unblockHandle not in line: - fpnew.write(handle + '\n') + try: + with open(unblockingFilename + '.new', 'w+') as fpnew: + for line in fp: + handle = line.replace('\n', '').replace('\r', '') + if unblockHandle not in line: + fpnew.write(handle + '\n') + except OSError: + print('WARN: failed to remove block ' + unblockingFilename) + return False if os.path.isfile(unblockingFilename + '.new'): os.rename(unblockingFilename + '.new', unblockingFilename) return True @@ -553,9 +568,13 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int, else: print('MUTE: cached post not found ' + cachedPostFilename) - with open(postFilename + '.muted', 'w+') as muteFile: - muteFile.write('\n') - print('MUTE: ' + postFilename + '.muted file added') + try: + with open(postFilename + '.muted', 'w+') as muteFile: + muteFile.write('\n') + print('MUTE: ' + postFilename + '.muted file added') + except OSError: + print('WARN: Failed to save mute file ' + postFilename + '.muted') + return # if the post is in the recent posts cache then mark it as muted if recentPostsCache.get('index'): @@ -882,11 +901,15 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None: break # write the allow file - with open(allowFilename, 'w+') as allowFile: - allowFile.write(domainFull + '\n') - for d in allowedDomains: - allowFile.write(d + '\n') - print('Broch mode enabled') + try: + with open(allowFilename, 'w+') as allowFile: + allowFile.write(domainFull + '\n') + for d in allowedDomains: + allowFile.write(d + '\n') + print('Broch mode enabled') + except OSError: + print('WARN: Broch mode not enabled due to file write') + return setConfigParam(baseDir, "brochMode", enabled) diff --git a/blog.py b/blog.py index a136d36d0..2adca3da0 100644 --- a/blog.py +++ b/blog.py @@ -91,11 +91,16 @@ def _noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {}, if lines and removals: print('Rewriting ' + postFilename + ' to remove ' + str(len(removals)) + ' entries') - with open(postFilename, 'w+') as f: - for replyPostId in lines: - replyPostId = replyPostId.replace('\n', '').replace('\r', '') - if replyPostId not in removals: - f.write(replyPostId + '\n') + try: + with open(postFilename, 'w+') as f: + for replyPostId in lines: + replyPostId = \ + replyPostId.replace('\n', '').replace('\r', '') + if replyPostId not in removals: + f.write(replyPostId + '\n') + except OSError: + print('WARN: unable to remove replies from post ' + postFilename) + pass return replies diff --git a/bookmarks.py b/bookmarks.py index 1016e3a2d..74b3f4fc3 100644 --- a/bookmarks.py +++ b/bookmarks.py @@ -51,12 +51,11 @@ def undoBookmarksCollectionEntry(recentPostsCache: {}, if os.path.isfile(cachedPostFilename): try: os.remove(cachedPostFilename) - except BaseException: + except OSError: if debug: print('EX: undoBookmarksCollectionEntry ' + 'unable to delete cached post file ' + str(cachedPostFilename)) - pass removePostFromCache(postJsonObject, recentPostsCache) # remove from the index @@ -74,9 +73,13 @@ def undoBookmarksCollectionEntry(recentPostsCache: {}, indexStr = '' with open(bookmarksIndexFilename, 'r') as indexFile: indexStr = indexFile.read().replace(bookmarkIndex + '\n', '') - with open(bookmarksIndexFilename, 'w+') as bookmarksIndexFile: - bookmarksIndexFile.write(indexStr) - + try: + with open(bookmarksIndexFilename, 'w+') as bookmarksIndexFile: + bookmarksIndexFile.write(indexStr) + except OSError: + print('WARN: unable to write bookmarks index ' + + bookmarksIndexFilename) + pass if not postJsonObject.get('type'): return if postJsonObject['type'] != 'Create': @@ -163,12 +166,11 @@ def updateBookmarksCollection(recentPostsCache: {}, if os.path.isfile(cachedPostFilename): try: os.remove(cachedPostFilename) - except BaseException: + except OSError: if debug: print('EX: updateBookmarksCollection ' + 'unable to delete cached post ' + str(cachedPostFilename)) - pass removePostFromCache(postJsonObject, recentPostsCache) if not postJsonObject.get('object'): @@ -233,8 +235,13 @@ def updateBookmarksCollection(recentPostsCache: {}, print('WARN: Failed to write entry to bookmarks index ' + bookmarksIndexFilename + ' ' + str(e)) else: - with open(bookmarksIndexFilename, 'w+') as bookmarksIndexFile: - bookmarksIndexFile.write(bookmarkIndex + '\n') + try: + with open(bookmarksIndexFilename, 'w+') as bookmarksIndexFile: + bookmarksIndexFile.write(bookmarkIndex + '\n') + except OSError: + print('WARN: unable to write bookmarks index ' + + bookmarksIndexFilename) + pass def bookmark(recentPostsCache: {}, diff --git a/cache.py b/cache.py index 62ae4132e..bbc2cbb9f 100644 --- a/cache.py +++ b/cache.py @@ -26,9 +26,8 @@ def _removePersonFromCache(baseDir: str, personUrl: str, if os.path.isfile(cacheFilename): try: os.remove(cacheFilename) - except BaseException: + except OSError: print('EX: unable to delete cached actor ' + str(cacheFilename)) - pass if personCache.get(personUrl): del personCache[personUrl] diff --git a/categories.py b/categories.py index 07fbe51d0..868fcfe4f 100644 --- a/categories.py +++ b/categories.py @@ -95,11 +95,10 @@ def updateHashtagCategories(baseDir: str) -> None: if os.path.isfile(categoryListFilename): try: os.remove(categoryListFilename) - except BaseException: + except OSError: print('EX: updateHashtagCategories ' + 'unable to delete cached category list ' + categoryListFilename) - pass return categoryList = [] @@ -112,8 +111,11 @@ def updateHashtagCategories(baseDir: str) -> None: categoryListStr += categoryStr + '\n' # save a list of available categories for quick lookup - with open(categoryListFilename, 'w+') as fp: - fp.write(categoryListStr) + try: + with open(categoryListFilename, 'w+') as fp: + fp.write(categoryListStr) + except OSError: + print('WARN: unable to write category ' + categoryListFilename) def _validHashtagCategory(category: str) -> bool: @@ -159,12 +161,15 @@ def setHashtagCategory(baseDir: str, hashtag: str, category: str, # don't overwrite any existing categories if os.path.isfile(categoryFilename): return False - with open(categoryFilename, 'w+') as fp: - fp.write(category) - if update: - updateHashtagCategories(baseDir) - return True - + try: + with open(categoryFilename, 'w+') as fp: + fp.write(category) + if update: + updateHashtagCategories(baseDir) + return True + except OSError: + print('WARN: unable to write category ' + categoryFilename) + pass return False diff --git a/content.py b/content.py index f409d43e0..0ff9043e3 100644 --- a/content.py +++ b/content.py @@ -1015,21 +1015,19 @@ def saveMediaInFormPOST(mediaBytes, debug: bool, if os.path.isfile(possibleOtherFormat): try: os.remove(possibleOtherFormat) - except BaseException: + except OSError: if debug: print('EX: saveMediaInFormPOST ' + 'unable to delete other ' + str(possibleOtherFormat)) - pass if os.path.isfile(filenameBase): try: os.remove(filenameBase) - except BaseException: + except OSError: if debug: print('EX: saveMediaInFormPOST ' + 'unable to delete ' + str(filenameBase)) - pass if debug: print('DEBUG: No media found within POST') @@ -1097,12 +1095,11 @@ def saveMediaInFormPOST(mediaBytes, debug: bool, if os.path.isfile(possibleOtherFormat): try: os.remove(possibleOtherFormat) - except BaseException: + except OSError: if debug: print('EX: saveMediaInFormPOST ' + 'unable to delete other 2 ' + str(possibleOtherFormat)) - pass # don't allow scripts within svg files if detectedExtension == 'svg': @@ -1111,8 +1108,11 @@ def saveMediaInFormPOST(mediaBytes, debug: bool, if dangerousSVG(svgStr, False): return None, None - with open(filename, 'wb') as fp: - fp.write(mediaBytes[startPos:]) + try: + with open(filename, 'wb') as fp: + fp.write(mediaBytes[startPos:]) + except OSError: + print('WARN: unable to write media') if not os.path.isfile(filename): print('WARN: Media file could not be written to file: ' + filename) diff --git a/conversation.py b/conversation.py index d44d8568b..ad275ffe7 100644 --- a/conversation.py +++ b/conversation.py @@ -45,7 +45,7 @@ def updateConversation(baseDir: str, nickname: str, domain: str, with open(conversationFilename, 'w+') as fp: fp.write(postId + '\n') return True - except BaseException: + except OSError: print('EX: updateConversation ' + 'unable to write to ' + conversationFilename) pass @@ -54,7 +54,7 @@ def updateConversation(baseDir: str, nickname: str, domain: str, with open(conversationFilename, 'a+') as fp: fp.write(postId + '\n') return True - except BaseException: + except OSError: print('EX: updateConversation 2 ' + 'unable to write to ' + conversationFilename) pass @@ -72,8 +72,12 @@ def muteConversation(baseDir: str, nickname: str, domain: str, return if os.path.isfile(conversationFilename + '.muted'): return - with open(conversationFilename + '.muted', 'w+') as fp: - fp.write('\n') + try: + with open(conversationFilename + '.muted', 'w+') as fp: + fp.write('\n') + except OSError: + print('WARN: unable to write mute ' + conversationFilename) + pass def unmuteConversation(baseDir: str, nickname: str, domain: str, @@ -89,7 +93,6 @@ def unmuteConversation(baseDir: str, nickname: str, domain: str, return try: os.remove(conversationFilename + '.muted') - except BaseException: + except OSError: print('EX: unmuteConversation unable to delete ' + conversationFilename + '.muted') - pass diff --git a/daemon.py b/daemon.py index ff6562e19..9eecf5fc7 100644 --- a/daemon.py +++ b/daemon.py @@ -532,8 +532,12 @@ class PubServer(BaseHTTPRequestHandler): self.server.maxReplies, self.server.debug) # record the vote - with open(votesFilename, 'a+') as votesFile: - votesFile.write(messageId + '\n') + try: + with open(votesFilename, 'a+') as votesFile: + votesFile.write(messageId + '\n') + except OSError: + print('WARN: unable to write vote ' + + votesFilename) # ensure that the cached post is removed if it exists, # so that it then will be recreated @@ -546,11 +550,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(cachedPostFilename): try: os.remove(cachedPostFilename) - except BaseException: + except OSError: print('EX: _sendReplyToQuestion ' + 'unable to delete ' + cachedPostFilename) - pass # remove from memory cache removePostFromCache(postJsonObject, self.server.recentPostsCache) @@ -847,7 +850,7 @@ class PubServer(BaseHTTPRequestHandler): try: with open(mediaFilename + '.etag', 'w+') as etagFile: etagFile.write(etag) - except BaseException: + except OSError: print('EX: _set_headers_etag ' + 'unable to write ' + mediaFilename + '.etag') pass @@ -1758,14 +1761,14 @@ class PubServer(BaseHTTPRequestHandler): try: with open(saltFilename, 'r') as fp: salt = fp.read() - except Exception as e: + except OSError as e: print('WARN: Unable to read salt for ' + loginNickname + ' ' + str(e)) else: try: with open(saltFilename, 'w+') as fp: fp.write(salt) - except Exception as e: + except OSError as e: print('WARN: Unable to save salt for ' + loginNickname + ' ' + str(e)) @@ -1779,7 +1782,7 @@ class PubServer(BaseHTTPRequestHandler): try: with open(tokenFilename, 'w+') as fp: fp.write(token) - except Exception as e: + except OSError as e: print('WARN: Unable to save token for ' + loginNickname + ' ' + str(e)) @@ -2348,17 +2351,19 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(newswireBlockedFilename): try: os.remove(newswireBlockedFilename) - except BaseException: + except OSError: print('EX: _personOptions unable to delete ' + newswireBlockedFilename) - pass refreshNewswire(self.server.baseDir) else: if os.path.isdir(accountDir): nwFilename = newswireBlockedFilename - with open(nwFilename, 'w+') as noNewswireFile: - noNewswireFile.write('\n') - refreshNewswire(self.server.baseDir) + try: + with open(nwFilename, 'w+') as noNewswireFile: + noNewswireFile.write('\n') + refreshNewswire(self.server.baseDir) + except OSError: + print('WARN: unable to write ' + nwFilename) usersPathStr = \ usersPath + '/' + self.server.defaultTimeline + \ '?page=' + str(pageNumber) @@ -2388,17 +2393,19 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(featuresBlockedFilename): try: os.remove(featuresBlockedFilename) - except BaseException: + except OSError: print('EX: _personOptions unable to delete ' + featuresBlockedFilename) - pass refreshNewswire(self.server.baseDir) else: if os.path.isdir(accountDir): featFilename = featuresBlockedFilename - with open(featFilename, 'w+') as noFeaturesFile: - noFeaturesFile.write('\n') - refreshNewswire(self.server.baseDir) + try: + with open(featFilename, 'w+') as noFeaturesFile: + noFeaturesFile.write('\n') + refreshNewswire(self.server.baseDir) + except OSError: + print('WARN: unable to write ' + featFilename) usersPathStr = \ usersPath + '/' + self.server.defaultTimeline + \ '?page=' + str(pageNumber) @@ -2428,15 +2435,17 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(newswireModFilename): try: os.remove(newswireModFilename) - except BaseException: + except OSError: print('EX: _personOptions unable to delete ' + newswireModFilename) - pass else: if os.path.isdir(accountDir): nwFilename = newswireModFilename - with open(nwFilename, 'w+') as modNewswireFile: - modNewswireFile.write('\n') + try: + with open(nwFilename, 'w+') as modNewswireFile: + modNewswireFile.write('\n') + except OSError: + print('WARN: unable to write ' + nwFilename) usersPathStr = \ usersPath + '/' + self.server.defaultTimeline + \ '?page=' + str(pageNumber) @@ -3582,8 +3591,11 @@ class PubServer(BaseHTTPRequestHandler): mediaFilename = \ mediaFilenameBase + '.' + \ getImageExtensionFromMimeType(self.headers['Content-type']) - with open(mediaFilename, 'wb') as avFile: - avFile.write(mediaBytes) + try: + with open(mediaFilename, 'wb') as avFile: + avFile.write(mediaBytes) + except OSError: + print('WARN: unable to write ' + mediaFilename) if debug: print('DEBUG: image saved to ' + mediaFilename) self.send_response(201) @@ -3901,10 +3913,9 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(linksFilename): try: os.remove(linksFilename) - except BaseException: + except OSError: print('EX: _linksUpdate unable to delete ' + linksFilename) - pass adminNickname = \ getConfigParam(baseDir, 'admin') @@ -3919,10 +3930,9 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(aboutFilename): try: os.remove(aboutFilename) - except BaseException: + except OSError: print('EX: _linksUpdate unable to delete ' + aboutFilename) - pass if fields.get('editedTOS'): TOSStr = fields['editedTOS'] @@ -3934,10 +3944,9 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(TOSFilename): try: os.remove(TOSFilename) - except BaseException: + except OSError: print('EX: _linksUpdate unable to delete ' + TOSFilename) - pass # redirect back to the default timeline self._redirect_headers(actorStr + '/' + defaultTimeline, @@ -4037,10 +4046,9 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(categoryFilename): try: os.remove(categoryFilename) - except BaseException: + except OSError: print('EX: _setHashtagCategory unable to delete ' + categoryFilename) - pass # redirect back to the default timeline self._redirect_headers(tagScreenStr, @@ -4114,63 +4122,71 @@ class PubServer(BaseHTTPRequestHandler): extractTextFieldsInPOST(postBytes, boundary, debug) if fields.get('editedNewswire'): newswireStr = fields['editedNewswire'] - with open(newswireFilename, 'w+') as newswireFile: - newswireFile.write(newswireStr) + try: + with open(newswireFilename, 'w+') as newswireFile: + newswireFile.write(newswireStr) + except OSError: + print('WARN: unable to write ' + newswireFilename) else: if os.path.isfile(newswireFilename): try: os.remove(newswireFilename) - except BaseException: + except OSError: print('EX: _newswireUpdate unable to delete ' + newswireFilename) - pass # save filtered words list for the newswire filterNewswireFilename = \ baseDir + '/accounts/' + \ 'news@' + domain + '/filters.txt' if fields.get('filteredWordsNewswire'): - with open(filterNewswireFilename, 'w+') as filterfile: - filterfile.write(fields['filteredWordsNewswire']) + try: + with open(filterNewswireFilename, 'w+') as filterfile: + filterfile.write(fields['filteredWordsNewswire']) + except OSError: + print('WARN: unable to write ' + filterNewswireFilename) else: if os.path.isfile(filterNewswireFilename): try: os.remove(filterNewswireFilename) - except BaseException: + except OSError: print('EX: _newswireUpdate unable to delete ' + filterNewswireFilename) - pass # save news tagging rules hashtagRulesFilename = \ baseDir + '/accounts/hashtagrules.txt' if fields.get('hashtagRulesList'): - with open(hashtagRulesFilename, 'w+') as rulesfile: - rulesfile.write(fields['hashtagRulesList']) + try: + with open(hashtagRulesFilename, 'w+') as rulesfile: + rulesfile.write(fields['hashtagRulesList']) + except OSError: + print('WARN: unable to write ' + hashtagRulesFilename) else: if os.path.isfile(hashtagRulesFilename): try: os.remove(hashtagRulesFilename) - except BaseException: + except OSError: print('EX: _newswireUpdate unable to delete ' + hashtagRulesFilename) - pass newswireTrustedFilename = baseDir + '/accounts/newswiretrusted.txt' if fields.get('trustedNewswire'): newswireTrusted = fields['trustedNewswire'] if not newswireTrusted.endswith('\n'): newswireTrusted += '\n' - with open(newswireTrustedFilename, 'w+') as trustFile: - trustFile.write(newswireTrusted) + try: + with open(newswireTrustedFilename, 'w+') as trustFile: + trustFile.write(newswireTrusted) + except OSError: + print('WARN: unable to write ' + newswireTrustedFilename) else: if os.path.isfile(newswireTrustedFilename): try: os.remove(newswireTrustedFilename) - except BaseException: + except OSError: print('EX: _newswireUpdate unable to delete ' + newswireTrustedFilename) - pass # redirect back to the default timeline self._redirect_headers(actorStr + '/' + defaultTimeline, @@ -4197,10 +4213,9 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(citationsFilename): try: os.remove(citationsFilename) - except BaseException: + except OSError: print('EX: _citationsUpdate unable to delete ' + citationsFilename) - pass if newswire and \ ' boundary=' in self.headers['Content-type']: @@ -4257,8 +4272,11 @@ class PubServer(BaseHTTPRequestHandler): citationsStr += citationDate + '\n' # save citations dates, so that they can be added when # reloading the newblog screen - with open(citationsFilename, 'w+') as citationsFile: - citationsFile.write(citationsStr) + try: + with open(citationsFilename, 'w+') as citationsFile: + citationsFile.write(citationsStr) + except OSError: + print('WARN: unable to write ' + citationsFilename) # redirect back to the default timeline self._redirect_headers(actorStr + '/newblog', @@ -4504,10 +4522,9 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(filenameBase): try: os.remove(filenameBase) - except BaseException: + except OSError: print('EX: _profileUpdate unable to delete ' + filenameBase) - pass else: filenameBase = \ acctDir(baseDir, nickname, domain) + \ @@ -4541,10 +4558,9 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(postImageFilename + '.etag'): try: os.remove(postImageFilename + '.etag') - except BaseException: + except OSError: print('EX: _profileUpdate unable to delete ' + postImageFilename + '.etag') - pass city = getSpoofedCity(self.server.city, baseDir, nickname, domain) @@ -4712,8 +4728,11 @@ class PubServer(BaseHTTPRequestHandler): if fields.get('cityDropdown'): cityFilename = \ acctDir(baseDir, nickname, domain) + '/city.txt' - with open(cityFilename, 'w+') as fp: - fp.write(fields['cityDropdown']) + try: + with open(cityFilename, 'w+') as fp: + fp.write(fields['cityDropdown']) + except OSError: + print('WARN: unable to write ' + cityFilename) # change displayed name if fields.get('displayNickname'): @@ -5597,11 +5616,10 @@ class PubServer(BaseHTTPRequestHandler): try: os.remove(baseDir + '/fonts/custom.' + ext) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + baseDir + '/fonts/custom.' + ext) - pass if os.path.isfile(baseDir + '/fonts/custom.' + ext + '.etag'): @@ -5609,12 +5627,11 @@ class PubServer(BaseHTTPRequestHandler): os.remove(baseDir + '/fonts/custom.' + ext + '.etag') - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + baseDir + '/fonts/custom.' + ext + '.etag') - pass currTheme = getTheme(baseDir) if currTheme: self.server.themeName = currTheme @@ -5664,11 +5681,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(followDMsFilename): try: os.remove(followDMsFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + followDMsFilename) - pass # remove Twitter retweets removeTwitterFilename = \ @@ -5685,11 +5701,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(removeTwitterFilename): try: os.remove(removeTwitterFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + removeTwitterFilename) - pass # hide Like button hideLikeButtonFile = \ @@ -5708,20 +5723,18 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(notifyLikesFilename): try: os.remove(notifyLikesFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + notifyLikesFilename) - pass if not hideLikeButtonActive: if os.path.isfile(hideLikeButtonFile): try: os.remove(hideLikeButtonFile) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + hideLikeButtonFile) - pass # hide Reaction button hideReactionButtonFile = \ @@ -5740,20 +5753,18 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(notifyReactionsFilename): try: os.remove(notifyReactionsFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + notifyReactionsFilename) - pass if not hideReactionButtonActive: if os.path.isfile(hideReactionButtonFile): try: os.remove(hideReactionButtonFile) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + hideReactionButtonFile) - pass # notify about new Likes if onFinalWelcomeScreen: @@ -5773,11 +5784,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(notifyLikesFilename): try: os.remove(notifyLikesFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + notifyLikesFilename) - pass notifyReactionsFilename = \ acctDir(baseDir, nickname, domain) + \ @@ -5800,11 +5810,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(notifyReactionsFilename): try: os.remove(notifyReactionsFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + notifyReactionsFilename) - pass # this account is a bot if fields.get('isBot'): @@ -5865,11 +5874,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(filterFilename): try: os.remove(filterFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + filterFilename) - pass # word replacements switchFilename = \ @@ -5882,11 +5890,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(switchFilename): try: os.remove(switchFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + switchFilename) - pass # autogenerated tags autoTagsFilename = \ @@ -5899,11 +5906,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(autoTagsFilename): try: os.remove(autoTagsFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + autoTagsFilename) - pass # autogenerated content warnings autoCWFilename = \ @@ -5916,11 +5922,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(autoCWFilename): try: os.remove(autoCWFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + autoCWFilename) - pass # save blocked accounts list blockedFilename = \ @@ -5937,7 +5942,6 @@ class PubServer(BaseHTTPRequestHandler): print('EX: _profileUpdate ' + 'unable to delete ' + blockedFilename) - pass # Save DM allowed instances list. # The allow list for incoming DMs, @@ -5952,11 +5956,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(dmAllowedInstancesFilename): try: os.remove(dmAllowedInstancesFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + dmAllowedInstancesFilename) - pass # save allowed instances list # This is the account level allow list @@ -5970,11 +5973,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(allowedInstancesFilename): try: os.remove(allowedInstancesFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + allowedInstancesFilename) - pass if isModerator(self.server.baseDir, nickname): # set selected content warning lists @@ -6036,11 +6038,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(peertubeInstancesFile): try: os.remove(peertubeInstancesFile) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + peertubeInstancesFile) - pass self.server.peertubeInstances.clear() # save git project names list @@ -6054,11 +6055,10 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(gitProjectsFilename): try: os.remove(gitProjectsFilename) - except BaseException: + except OSError: print('EX: _profileUpdate ' + 'unable to delete ' + gitProjectsFilename) - pass # save actor json file within accounts if actorChanged: @@ -16296,10 +16296,9 @@ class PubServer(BaseHTTPRequestHandler): print('Edited blog post, removing cached html') try: os.remove(cachedFilename) - except BaseException: + except OSError: print('EX: _receiveNewPostProcess ' + 'unable to delete ' + cachedFilename) - pass # remove from memory cache removePostFromCache(postJsonObject, self.server.recentPostsCache) @@ -16732,10 +16731,9 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(filename): try: os.remove(filename) - except BaseException: + except OSError: print('EX: _receiveNewPostProcess ' + 'unable to delete ' + filename) - pass self.postToNickname = nickname return 1 return -1 diff --git a/delete.py b/delete.py index bd67f5dd6..74c084a60 100644 --- a/delete.py +++ b/delete.py @@ -201,6 +201,5 @@ def removeOldHashtags(baseDir: str, maxMonths: int) -> str: for removeFilename in removeHashtags: try: os.remove(removeFilename) - except BaseException: + except OSError: print('EX: removeOldHashtags unable to delete ' + removeFilename) - pass diff --git a/devices.py b/devices.py index e306b3dd8..19997fa09 100644 --- a/devices.py +++ b/devices.py @@ -46,9 +46,8 @@ def E2EEremoveDevice(baseDir: str, nickname: str, domain: str, if os.path.isfile(deviceFilename): try: os.remove(deviceFilename) - except BaseException: + except OSError: print('EX: E2EEremoveDevice unable to delete ' + deviceFilename) - pass return True return False diff --git a/follow.py b/follow.py index b8953131f..704dd90dd 100644 --- a/follow.py +++ b/follow.py @@ -341,9 +341,8 @@ def clearFollows(baseDir: str, nickname: str, domain: str, if os.path.isfile(filename): try: os.remove(filename) - except BaseException: + except OSError: print('EX: clearFollows unable to delete ' + filename) - pass def clearFollowers(baseDir: str, nickname: str, domain: str) -> None: @@ -908,10 +907,9 @@ def followedAccountAccepts(session, baseDir: str, httpPrefix: str, if os.path.isfile(followActivityfilename): try: os.remove(followActivityfilename) - except BaseException: + except OSError: print('EX: followedAccountAccepts unable to delete ' + followActivityfilename) - pass groupAccount = False if followJson: @@ -983,10 +981,9 @@ def followedAccountRejects(session, baseDir: str, httpPrefix: str, # remove the follow request json try: os.remove(followActivityfilename) - except BaseException: + except OSError: print('EX: followedAccountRejects unable to delete ' + followActivityfilename) - pass # send the reject activity return sendSignedJson(rejectJson, session, baseDir, nicknameToFollow, domainToFollow, port, diff --git a/inbox.py b/inbox.py index db63e88b2..84c1e0f11 100644 --- a/inbox.py +++ b/inbox.py @@ -920,7 +920,7 @@ def _receiveUpdateToQuestion(recentPostsCache: {}, messageJson: {}, if os.path.isfile(cachedPostFilename): try: os.remove(cachedPostFilename) - except BaseException: + except OSError: print('EX: _receiveUpdateToQuestion unable to delete ' + cachedPostFilename) # remove from memory cache @@ -1944,7 +1944,7 @@ def _receiveAnnounce(recentPostsCache: {}, # if the announce can't be downloaded then remove it try: os.remove(postFilename) - except BaseException: + except OSError: print('EX: _receiveAnnounce unable to delete ' + str(postFilename)) pass @@ -2059,10 +2059,9 @@ def _receiveUndoAnnounce(recentPostsCache: {}, if os.path.isfile(postFilename): try: os.remove(postFilename) - except BaseException: + except OSError: print('EX: _receiveUndoAnnounce unable to delete ' + str(postFilename)) - pass return True @@ -2973,7 +2972,7 @@ def _receiveQuestionVote(baseDir: str, nickname: str, domain: str, if os.path.isfile(cachedPostFilename): try: os.remove(cachedPostFilename) - except BaseException: + except OSError: print('EX: replytoQuestion unable to delete ' + cachedPostFilename) @@ -3592,9 +3591,8 @@ def clearQueueItems(baseDir: str, queue: []) -> None: try: os.remove(os.path.join(queueDir, qfile)) ctr += 1 - except BaseException: + except OSError: print('EX: clearQueueItems unable to delete ' + qfile) - pass break break if ctr > 0: @@ -3659,10 +3657,9 @@ def _inboxQuotaExceeded(queue: {}, queueFilename: str, if len(queue) > 0: try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: _inboxQuotaExceeded unable to delete ' + str(queueFilename)) - pass queue.pop(0) return True quotasDaily['domains'][postDomain] += 1 @@ -3682,10 +3679,9 @@ def _inboxQuotaExceeded(queue: {}, queueFilename: str, if len(queue) > 0: try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: _inboxQuotaExceeded unable to delete ' + str(queueFilename)) - pass queue.pop(0) return True quotasPerMin['domains'][postDomain] += 1 @@ -3704,10 +3700,9 @@ def _inboxQuotaExceeded(queue: {}, queueFilename: str, if len(queue) > 0: try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: _inboxQuotaExceeded unable to delete ' + str(queueFilename)) - pass queue.pop(0) return True quotasDaily['accounts'][postHandle] += 1 @@ -3728,10 +3723,9 @@ def _inboxQuotaExceeded(queue: {}, queueFilename: str, if len(queue) > 0: try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: _inboxQuotaExceeded unable to delete ' + str(queueFilename)) - pass queue.pop(0) return True quotasPerMin['accounts'][postHandle] += 1 @@ -3913,10 +3907,9 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if os.path.isfile(queueFilename): try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: runInboxQueue 1 unable to delete ' + str(queueFilename)) - pass continue # clear the daily quotas for maximum numbers of received posts @@ -3988,10 +3981,9 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if os.path.isfile(queueFilename): try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: runInboxQueue 2 unable to delete ' + str(queueFilename)) - pass if len(queue) > 0: queue.pop(0) continue @@ -4041,10 +4033,9 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if os.path.isfile(queueFilename): try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: runInboxQueue 3 unable to delete ' + str(queueFilename)) - pass if len(queue) > 0: queue.pop(0) continue @@ -4063,10 +4054,9 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if os.path.isfile(queueFilename): try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: runInboxQueue 4 unable to delete ' + str(queueFilename)) - pass if len(queue) > 0: queue.pop(0) continue @@ -4094,10 +4084,9 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if os.path.isfile(queueFilename): try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: runInboxQueue 5 unable to delete ' + str(queueFilename)) - pass if len(queue) > 0: queue.pop(0) continue @@ -4117,10 +4106,9 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if os.path.isfile(queueFilename): try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: runInboxQueue 6 unable to delete ' + str(queueFilename)) - pass if len(queue) > 0: queue.pop(0) print('Queue: Follow activity for ' + keyId + @@ -4140,10 +4128,9 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if os.path.isfile(queueFilename): try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: runInboxQueue 7 unable to delete ' + str(queueFilename)) - pass if len(queue) > 0: queue.pop(0) continue @@ -4163,10 +4150,9 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if os.path.isfile(queueFilename): try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: runInboxQueue 8 unable to delete ' + str(queueFilename)) - pass if len(queue) > 0: queue.pop(0) continue @@ -4183,10 +4169,9 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if os.path.isfile(queueFilename): try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: runInboxQueue 9 unable to delete ' + str(queueFilename)) - pass if len(queue) > 0: queue.pop(0) continue @@ -4265,9 +4250,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if os.path.isfile(queueFilename): try: os.remove(queueFilename) - except BaseException: + except OSError: print('EX: runInboxQueue 10 unable to delete ' + str(queueFilename)) - pass if len(queue) > 0: queue.pop(0) diff --git a/like.py b/like.py index ef1c57a5d..390e3e622 100644 --- a/like.py +++ b/like.py @@ -430,10 +430,9 @@ def updateLikesCollection(recentPostsCache: {}, if os.path.isfile(cachedPostFilename): try: os.remove(cachedPostFilename) - except BaseException: + except OSError: print('EX: updateLikesCollection unable to delete ' + cachedPostFilename) - pass obj = postJsonObject if hasObjectDict(postJsonObject): diff --git a/manualapprove.py b/manualapprove.py index 4af4146a9..1a8edd2f9 100644 --- a/manualapprove.py +++ b/manualapprove.py @@ -254,17 +254,15 @@ def manualApproveFollowRequest(session, baseDir: str, if os.path.isfile(followActivityfilename): try: os.remove(followActivityfilename) - except BaseException: + except OSError: print('EX: manualApproveFollowRequest unable to delete ' + followActivityfilename) - pass else: try: os.remove(approveFollowsFilename + '.new') - except BaseException: + except OSError: print('EX: manualApproveFollowRequest unable to delete ' + approveFollowsFilename + '.new') - pass def manualApproveFollowRequestThread(session, baseDir: str, diff --git a/media.py b/media.py index 5b742a5e1..8448ce101 100644 --- a/media.py +++ b/media.py @@ -168,10 +168,9 @@ def convertImageToLowBandwidth(imageFilename: str) -> None: if os.path.isfile(lowBandwidthFilename): try: os.remove(lowBandwidthFilename) - except BaseException: + except OSError: print('EX: convertImageToLowBandwidth unable to delete ' + lowBandwidthFilename) - pass cmd = \ '/usr/bin/convert +noise Multiplicative ' + \ @@ -191,10 +190,9 @@ def convertImageToLowBandwidth(imageFilename: str) -> None: if os.path.isfile(lowBandwidthFilename): try: os.remove(imageFilename) - except BaseException: + except OSError: print('EX: convertImageToLowBandwidth unable to delete ' + imageFilename) - pass os.rename(lowBandwidthFilename, imageFilename) if os.path.isfile(imageFilename): print('Image converted to low bandwidth ' + imageFilename) diff --git a/newsdaemon.py b/newsdaemon.py index 80c69bbb8..87ab01938 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -727,10 +727,9 @@ def _convertRSStoActivityPub(baseDir: str, httpPrefix: str, if os.path.isfile(filename + '.arrived'): try: os.remove(filename + '.arrived') - except BaseException: + except OSError: print('EX: _convertRSStoActivityPub ' + 'unable to delete ' + filename + '.arrived') - pass # setting the url here links to the activitypub object # stored locally @@ -843,10 +842,9 @@ def runNewswireDaemon(baseDir: str, httpd, if os.path.isfile(refreshFilename): try: os.remove(refreshFilename) - except BaseException: + except OSError: print('EX: runNewswireDaemon unable to delete ' + str(refreshFilename)) - pass break diff --git a/newswire.py b/newswire.py index 0925fad7f..803c15b48 100644 --- a/newswire.py +++ b/newswire.py @@ -1040,10 +1040,9 @@ def _addBlogsToNewswire(baseDir: str, domain: str, newswire: {}, if os.path.isfile(newswireModerationFilename): try: os.remove(newswireModerationFilename) - except BaseException: + except OSError: print('EX: _addBlogsToNewswire unable to delete ' + str(newswireModerationFilename)) - pass def getDictFromNewswire(session, baseDir: str, domain: str, diff --git a/outbox.py b/outbox.py index f9f42de9f..eab5d2542 100644 --- a/outbox.py +++ b/outbox.py @@ -400,10 +400,9 @@ def postMessageToOutbox(session, translate: {}, if os.path.isfile(citationsFilename): try: os.remove(citationsFilename) - except BaseException: + except OSError: print('EX: postMessageToOutbox unable to delete ' + citationsFilename) - pass # The following activity types get added to the index files indexedActivities = ( diff --git a/person.py b/person.py index ada52381e..64d66a847 100644 --- a/person.py +++ b/person.py @@ -1045,16 +1045,14 @@ def suspendAccount(baseDir: str, nickname: str, domain: str) -> None: if os.path.isfile(saltFilename): try: os.remove(saltFilename) - except BaseException: + except OSError: print('EX: suspendAccount unable to delete ' + saltFilename) - pass tokenFilename = acctDir(baseDir, nickname, domain) + '/.token' if os.path.isfile(tokenFilename): try: os.remove(tokenFilename) - except BaseException: + except OSError: print('EX: suspendAccount unable to delete ' + tokenFilename) - pass suspendedFilename = baseDir + '/accounts/suspended.txt' if os.path.isfile(suspendedFilename): @@ -1163,41 +1161,36 @@ def removeAccount(baseDir: str, nickname: str, if os.path.isfile(baseDir + '/accounts/' + handle + '.json'): try: os.remove(baseDir + '/accounts/' + handle + '.json') - except BaseException: + except OSError: print('EX: removeAccount unable to delete ' + baseDir + '/accounts/' + handle + '.json') - pass if os.path.isfile(baseDir + '/wfendpoints/' + handle + '.json'): try: os.remove(baseDir + '/wfendpoints/' + handle + '.json') - except BaseException: + except OSError: print('EX: removeAccount unable to delete ' + baseDir + '/wfendpoints/' + handle + '.json') - pass if os.path.isfile(baseDir + '/keys/private/' + handle + '.key'): try: os.remove(baseDir + '/keys/private/' + handle + '.key') - except BaseException: + except OSError: print('EX: removeAccount unable to delete ' + baseDir + '/keys/private/' + handle + '.key') - pass if os.path.isfile(baseDir + '/keys/public/' + handle + '.pem'): try: os.remove(baseDir + '/keys/public/' + handle + '.pem') - except BaseException: + except OSError: print('EX: removeAccount unable to delete ' + baseDir + '/keys/public/' + handle + '.pem') - pass if os.path.isdir(baseDir + '/sharefiles/' + nickname): shutil.rmtree(baseDir + '/sharefiles/' + nickname, ignore_errors=False, onerror=None) if os.path.isfile(baseDir + '/wfdeactivated/' + handle + '.json'): try: os.remove(baseDir + '/wfdeactivated/' + handle + '.json') - except BaseException: + except OSError: print('EX: removeAccount unable to delete ' + baseDir + '/wfdeactivated/' + handle + '.json') - pass if os.path.isdir(baseDir + '/sharefilesdeactivated/' + nickname): shutil.rmtree(baseDir + '/sharefilesdeactivated/' + nickname, ignore_errors=False, onerror=None) diff --git a/posts.py b/posts.py index 2837a224f..da4ba8d32 100644 --- a/posts.py +++ b/posts.py @@ -1585,7 +1585,7 @@ def undoPinnedPost(baseDir: str, nickname: str, domain: str) -> None: if os.path.isfile(pinnedFilename): try: os.remove(pinnedFilename) - except BaseException: + except OSError: print('EX: undoPinnedPost unable to delete ' + pinnedFilename) @@ -3966,10 +3966,9 @@ def archivePostsForPerson(httpPrefix: str, nickname: str, domain: str, if os.path.isfile(postCacheFilename): try: os.remove(postCacheFilename) - except BaseException: + except OSError: print('EX: archivePostsForPerson unable to delete ' + postCacheFilename) - pass noOfPosts -= 1 removeCtr += 1 diff --git a/reaction.py b/reaction.py index 92485804d..834c55a01 100644 --- a/reaction.py +++ b/reaction.py @@ -460,10 +460,9 @@ def updateReactionCollection(recentPostsCache: {}, if os.path.isfile(cachedPostFilename): try: os.remove(cachedPostFilename) - except BaseException: + except OSError: print('EX: updateReactionCollection unable to delete ' + cachedPostFilename) - pass obj = postJsonObject if hasObjectDict(postJsonObject): diff --git a/schedule.py b/schedule.py index 804bc16b2..edef6d7df 100644 --- a/schedule.py +++ b/schedule.py @@ -48,10 +48,9 @@ def _updatePostSchedule(baseDir: str, handle: str, httpd, if os.path.isfile(postFilename): try: os.remove(postFilename) - except BaseException: + except OSError: print('EX: _updatePostSchedule unable to delete ' + str(postFilename)) - pass continue # create the new index file indexLines.append(line) @@ -133,10 +132,9 @@ def _updatePostSchedule(baseDir: str, handle: str, httpd, indexLines.remove(line) try: os.remove(postFilename) - except BaseException: + except OSError: print('EX: _updatePostSchedule unable to delete ' + str(postFilename)) - pass continue # move to the outbox @@ -206,10 +204,9 @@ def removeScheduledPosts(baseDir: str, nickname: str, domain: str) -> None: if os.path.isfile(scheduleIndexFilename): try: os.remove(scheduleIndexFilename) - except BaseException: + except OSError: print('EX: removeScheduledPosts unable to delete ' + scheduleIndexFilename) - pass # remove the scheduled posts scheduledDir = acctDir(baseDir, nickname, domain) + '/scheduled' if not os.path.isdir(scheduledDir): @@ -219,7 +216,6 @@ def removeScheduledPosts(baseDir: str, nickname: str, domain: str) -> None: if os.path.isfile(filePath): try: os.remove(filePath) - except BaseException: + except OSError: print('EX: removeScheduledPosts unable to delete ' + filePath) - pass diff --git a/session.py b/session.py index a1f51f017..4eedae57e 100644 --- a/session.py +++ b/session.py @@ -439,10 +439,9 @@ def downloadImage(session, baseDir: str, url: str, if os.path.isfile(imageFilename): try: os.remove(imageFilename) - except BaseException: + except OSError: print('EX: downloadImage unable to delete ' + imageFilename) - pass else: with open(imageFilename, 'wb') as f: f.write(result.content) diff --git a/shares.py b/shares.py index 9df356597..aa521e526 100644 --- a/shares.py +++ b/shares.py @@ -148,10 +148,9 @@ def removeSharedItem(baseDir: str, nickname: str, domain: str, if os.path.isfile(itemIDfile + '.' + ext): try: os.remove(itemIDfile + '.' + ext) - except BaseException: + except OSError: print('EX: removeSharedItem unable to delete ' + itemIDfile + '.' + ext) - pass # remove the item itself del sharesJson[itemID] saveJson(sharesJson, sharesFilename) @@ -368,10 +367,9 @@ def addShare(baseDir: str, if moveImage: try: os.remove(imageFilename) - except BaseException: + except OSError: print('EX: addShare unable to delete ' + str(imageFilename)) - pass imageUrl = \ httpPrefix + '://' + domainFull + \ '/sharefiles/' + nickname + '/' + itemID + '.' + ext @@ -442,10 +440,9 @@ def _expireSharesForAccount(baseDir: str, nickname: str, domain: str, if os.path.isfile(itemIDfile + '.' + ext): try: os.remove(itemIDfile + '.' + ext) - except BaseException: + except OSError: print('EX: _expireSharesForAccount unable to delete ' + itemIDfile + '.' + ext) - pass saveJson(sharesJson, sharesFilename) diff --git a/tests.py b/tests.py index 9ed6a6506..07f6524a6 100644 --- a/tests.py +++ b/tests.py @@ -3478,7 +3478,7 @@ def _testJsonString() -> None: assert messageStr in encodedStr try: os.remove(filename) - except BaseException: + except OSError: pass @@ -3492,7 +3492,7 @@ def _testSaveLoadJson(): if os.path.isfile(testFilename): try: os.remove(testFilename) - except BaseException: + except OSError: pass assert saveJson(testJson, testFilename) assert os.path.isfile(testFilename) @@ -3504,7 +3504,7 @@ def _testSaveLoadJson(): assert testLoadJson['param2'] == '"Crème brûlée यह एक परीक्षण ह"' try: os.remove(testFilename) - except BaseException: + except OSError: pass diff --git a/theme.py b/theme.py index 481b478d0..587bf1799 100644 --- a/theme.py +++ b/theme.py @@ -90,9 +90,8 @@ def exportTheme(baseDir: str, theme: str) -> bool: if os.path.isfile(exportFilename): try: os.remove(exportFilename) - except BaseException: + except OSError: print('EX: exportTheme unable to delete ' + str(exportFilename)) - pass try: make_archive(baseDir + '/exports/' + theme, 'zip', themeDir) except BaseException: @@ -264,10 +263,9 @@ def _removeTheme(baseDir: str): continue try: os.remove(baseDir + '/' + filename) - except BaseException: + except OSError: print('EX: _removeTheme unable to delete ' + baseDir + '/' + filename) - pass def setCSSparam(css: str, param: str, value: str) -> str: @@ -451,10 +449,9 @@ def disableGrayscale(baseDir: str) -> None: if os.path.isfile(grayscaleFilename): try: os.remove(grayscaleFilename) - except BaseException: + except OSError: print('EX: disableGrayscale unable to delete ' + grayscaleFilename) - pass def _setCustomFont(baseDir: str): @@ -617,19 +614,17 @@ def _setTextModeTheme(baseDir: str, name: str) -> None: if os.path.isfile(baseDir + '/accounts/banner.txt'): try: os.remove(baseDir + '/accounts/banner.txt') - except BaseException: + except OSError: print('EX: _setTextModeTheme unable to delete ' + baseDir + '/accounts/banner.txt') - pass if os.path.isfile(textModeBannerFilename): try: copyfile(textModeBannerFilename, baseDir + '/accounts/banner.txt') - except BaseException: + except OSError: print('EX: _setTextModeTheme unable to copy ' + textModeBannerFilename + ' ' + baseDir + '/accounts/banner.txt') - pass def _setThemeImages(baseDir: str, name: str) -> None: @@ -679,10 +674,9 @@ def _setThemeImages(baseDir: str, name: str) -> None: baseDir + '/accounts/' + backgroundType + '-background.' + ext) continue - except BaseException: + except OSError: print('EX: _setThemeImages unable to copy ' + backgroundImageFilename) - pass # background image was not found # so remove any existing file if os.path.isfile(baseDir + '/accounts/' + @@ -690,21 +684,19 @@ def _setThemeImages(baseDir: str, name: str) -> None: try: os.remove(baseDir + '/accounts/' + backgroundType + '-background.' + ext) - except BaseException: + except OSError: print('EX: _setThemeImages unable to delete ' + baseDir + '/accounts/' + backgroundType + '-background.' + ext) - pass if os.path.isfile(profileImageFilename) and \ os.path.isfile(bannerFilename): try: copyfile(profileImageFilename, accountDir + '/image.png') - except BaseException: + except OSError: print('EX: _setThemeImages unable to copy ' + profileImageFilename) - pass try: copyfile(bannerFilename, @@ -718,10 +710,9 @@ def _setThemeImages(baseDir: str, name: str) -> None: if os.path.isfile(searchBannerFilename): copyfile(searchBannerFilename, accountDir + '/search_banner.png') - except BaseException: + except OSError: print('EX: _setThemeImages unable to copy ' + searchBannerFilename) - pass try: if os.path.isfile(leftColImageFilename): @@ -731,10 +722,9 @@ def _setThemeImages(baseDir: str, name: str) -> None: '/left_col_image.png'): try: os.remove(accountDir + '/left_col_image.png') - except BaseException: + except OSError: print('EX: _setThemeImages unable to delete ' + accountDir + '/left_col_image.png') - pass except BaseException: print('EX: _setThemeImages unable to copy ' + leftColImageFilename) @@ -749,14 +739,12 @@ def _setThemeImages(baseDir: str, name: str) -> None: '/right_col_image.png'): try: os.remove(accountDir + '/right_col_image.png') - except BaseException: + except OSError: print('EX: _setThemeImages unable to delete ' + accountDir + '/right_col_image.png') - pass except BaseException: print('EX: _setThemeImages unable to copy ' + rightColImageFilename) - pass break diff --git a/utils.py b/utils.py index 7592bd1c1..cfc68baca 100644 --- a/utils.py +++ b/utils.py @@ -625,10 +625,9 @@ def removeAvatarFromCache(baseDir: str, actorStr: str) -> None: if os.path.isfile(avatarFilename): try: os.remove(avatarFilename) - except BaseException: + except OSError: print('EX: removeAvatarFromCache ' + 'unable to delete cached avatar ' + str(avatarFilename)) - pass def saveJson(jsonObject: {}, filename: str) -> bool: @@ -1287,10 +1286,9 @@ def clearFromPostCaches(baseDir: str, recentPostsCache: {}, if os.path.isfile(postFilename): try: os.remove(postFilename) - except BaseException: + except OSError: print('EX: clearFromPostCaches file not removed ' + str(postFilename)) - pass # if the post is in the recent posts cache then remove it if recentPostsCache.get('index'): if postId in recentPostsCache['index']: @@ -1450,18 +1448,16 @@ def _removeAttachment(baseDir: str, httpPrefix: str, domain: str, if os.path.isfile(mediaFilename): try: os.remove(mediaFilename) - except BaseException: + except OSError: print('EX: _removeAttachment unable to delete media file ' + str(mediaFilename)) - pass etagFilename = mediaFilename + '.etag' if os.path.isfile(etagFilename): try: os.remove(etagFilename) - except BaseException: + except OSError: print('EX: _removeAttachment unable to delete etag file ' + str(etagFilename)) - pass postJson['attachment'] = [] @@ -1528,10 +1524,9 @@ def _deletePostRemoveReplies(baseDir: str, nickname: str, domain: str, # remove the replies file try: os.remove(repliesFilename) - except BaseException: + except OSError: print('EX: _deletePostRemoveReplies unable to delete replies file ' + str(repliesFilename)) - pass def _isBookmarked(baseDir: str, nickname: str, domain: str, @@ -1589,11 +1584,10 @@ def _deleteCachedHtml(baseDir: str, nickname: str, domain: str, if os.path.isfile(cachedPostFilename): try: os.remove(cachedPostFilename) - except BaseException: + except OSError: print('EX: _deleteCachedHtml ' + 'unable to delete cached post file ' + str(cachedPostFilename)) - pass def _deleteHashtagsOnPost(baseDir: str, postJsonObject: {}) -> None: @@ -1641,10 +1635,9 @@ def _deleteHashtagsOnPost(baseDir: str, postJsonObject: {}) -> None: # if there are no lines then remove the hashtag file try: os.remove(tagIndexFilename) - except BaseException: + except OSError: print('EX: _deleteHashtagsOnPost unable to delete tag index ' + str(tagIndexFilename)) - pass else: # write the new hashtag index without the given post in it with open(tagIndexFilename, 'w+') as f: @@ -1681,18 +1674,16 @@ def _deleteConversationPost(baseDir: str, nickname: str, domain: str, if os.path.isfile(conversationFilename + '.muted'): try: os.remove(conversationFilename + '.muted') - except BaseException: + except OSError: print('EX: _deleteConversationPost ' + 'unable to remove conversation ' + str(conversationFilename) + '.muted') - pass try: os.remove(conversationFilename) - except BaseException: + except OSError: print('EX: _deleteConversationPost ' + 'unable to remove conversation ' + str(conversationFilename)) - pass def deletePost(baseDir: str, httpPrefix: str, @@ -1709,11 +1700,10 @@ def deletePost(baseDir: str, httpPrefix: str, # finally, remove the post itself try: os.remove(postFilename) - except BaseException: + except OSError: if debug: print('EX: deletePost unable to delete post ' + str(postFilename)) - pass return # don't allow deletion of bookmarked posts @@ -1740,10 +1730,9 @@ def deletePost(baseDir: str, httpPrefix: str, if os.path.isfile(extFilename): try: os.remove(extFilename) - except BaseException: + except OSError: print('EX: deletePost unable to remove ext ' + str(extFilename)) - pass # remove cached html version of the post _deleteCachedHtml(baseDir, nickname, domain, postJsonObject) @@ -1771,10 +1760,9 @@ def deletePost(baseDir: str, httpPrefix: str, # finally, remove the post itself try: os.remove(postFilename) - except BaseException: + except OSError: if debug: print('EX: deletePost unable to delete post ' + str(postFilename)) - pass def isValidLanguage(text: str) -> bool: @@ -2213,11 +2201,10 @@ def undoLikesCollectionEntry(recentPostsCache: {}, if os.path.isfile(cachedPostFilename): try: os.remove(cachedPostFilename) - except BaseException: + except OSError: print('EX: undoLikesCollectionEntry ' + 'unable to delete cached post ' + str(cachedPostFilename)) - pass removePostFromCache(postJsonObject, recentPostsCache) if not postJsonObject.get('type'): @@ -2278,11 +2265,10 @@ def undoReactionCollectionEntry(recentPostsCache: {}, if os.path.isfile(cachedPostFilename): try: os.remove(cachedPostFilename) - except BaseException: + except OSError: print('EX: undoReactionCollectionEntry ' + 'unable to delete cached post ' + str(cachedPostFilename)) - pass removePostFromCache(postJsonObject, recentPostsCache) if not postJsonObject.get('type'): @@ -2344,12 +2330,11 @@ def undoAnnounceCollectionEntry(recentPostsCache: {}, if os.path.isfile(cachedPostFilename): try: os.remove(cachedPostFilename) - except BaseException: + except OSError: if debug: print('EX: undoAnnounceCollectionEntry ' + 'unable to delete cached post ' + str(cachedPostFilename)) - pass removePostFromCache(postJsonObject, recentPostsCache) if not postJsonObject.get('type'): @@ -2412,12 +2397,11 @@ def updateAnnounceCollection(recentPostsCache: {}, if os.path.isfile(cachedPostFilename): try: os.remove(cachedPostFilename) - except BaseException: + except OSError: if debug: print('EX: updateAnnounceCollection ' + 'unable to delete cached post ' + str(cachedPostFilename)) - pass removePostFromCache(postJsonObject, recentPostsCache) if not hasObjectDict(postJsonObject): diff --git a/webapp_calendar.py b/webapp_calendar.py index c20a5f35b..e4fba3cb6 100644 --- a/webapp_calendar.py +++ b/webapp_calendar.py @@ -108,9 +108,8 @@ def _htmlCalendarDay(personCache: {}, cssCache: {}, translate: {}, if os.path.isfile(calendarFile): try: os.remove(calendarFile) - except BaseException: + except OSError: print('EX: _htmlCalendarDay unable to delete ' + calendarFile) - pass cssFilename = baseDir + '/epicyon-calendar.css' if os.path.isfile(baseDir + '/calendar.css'): diff --git a/webapp_minimalbutton.py b/webapp_minimalbutton.py index db31ad964..1cc893794 100644 --- a/webapp_minimalbutton.py +++ b/webapp_minimalbutton.py @@ -36,9 +36,11 @@ def setMinimal(baseDir: str, domain: str, nickname: str, if minimal and minimalFileExists: try: os.remove(minimalFilename) - except BaseException: + except OSError: print('EX: setMinimal unable to delete ' + minimalFilename) - pass elif not minimal and not minimalFileExists: - with open(minimalFilename, 'w+') as fp: - fp.write('\n') + try: + with open(minimalFilename, 'w+') as fp: + fp.write('\n') + except OSError: + print('WARN: unable to write minimal ' + minimalFilename) diff --git a/webapp_timeline.py b/webapp_timeline.py index 842fffca4..29ee85fa0 100644 --- a/webapp_timeline.py +++ b/webapp_timeline.py @@ -476,9 +476,8 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str, if boxName == 'dm': try: os.remove(dmFile) - except BaseException: + except OSError: print('EX: htmlTimeline unable to delete ' + dmFile) - pass # should the Replies button be highlighted? newReply = False @@ -488,9 +487,8 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str, if boxName == 'tlreplies': try: os.remove(replyFile) - except BaseException: + except OSError: print('EX: htmlTimeline unable to delete ' + replyFile) - pass # should the Shares button be highlighted? newShare = False @@ -500,9 +498,8 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str, if boxName == 'tlshares': try: os.remove(newShareFile) - except BaseException: + except OSError: print('EX: htmlTimeline unable to delete ' + newShareFile) - pass # should the Wanted button be highlighted? newWanted = False @@ -512,9 +509,8 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str, if boxName == 'tlwanted': try: os.remove(newWantedFile) - except BaseException: + except OSError: print('EX: htmlTimeline unable to delete ' + newWantedFile) - pass # should the Moderation/reports button be highlighted? newReport = False @@ -524,9 +520,8 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str, if boxName == 'moderation': try: os.remove(newReportFile) - except BaseException: + except OSError: print('EX: htmlTimeline unable to delete ' + newReportFile) - pass separatorStr = '' if boxName != 'tlmedia': diff --git a/webapp_utils.py b/webapp_utils.py index 0647d899b..327cb3d8b 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -283,10 +283,9 @@ def updateAvatarImageCache(signingPrivateKeyPem: str, if os.path.isfile(avatarImageFilename): try: os.remove(avatarImageFilename) - except BaseException: + except OSError: print('EX: updateAvatarImageCache unable to delete ' + avatarImageFilename) - pass else: with open(avatarImageFilename, 'wb') as f: f.write(result.content)