From faadca51b69426f94581a59dae9a54926f9d19bb Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 14 Mar 2021 19:22:58 +0000 Subject: [PATCH] Less verbose when not in debug --- announce.py | 2 +- availability.py | 2 +- daemon.py | 16 ++++++++++++---- delete.py | 2 +- epicyon.py | 2 +- follow.py | 4 ++-- inbox.py | 13 +++++++------ like.py | 4 ++-- migrate.py | 2 +- person.py | 5 +++-- posts.py | 27 ++++++++++++++------------- roles.py | 2 +- shares.py | 4 ++-- skills.py | 2 +- socnet.py | 2 +- webapp_post.py | 2 +- webapp_profile.py | 14 ++++++++------ webfinger.py | 20 ++++++++++++-------- 18 files changed, 71 insertions(+), 54 deletions(-) diff --git a/announce.py b/announce.py index e8a3f2133..60679e4de 100644 --- a/announce.py +++ b/announce.py @@ -219,7 +219,7 @@ def sendAnnounceViaServer(baseDir: str, session, # lookup the inbox for the To handle wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - fromDomain, projectVersion) + fromDomain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) diff --git a/availability.py b/availability.py index 0b0f48847..5b88c4103 100644 --- a/availability.py +++ b/availability.py @@ -105,7 +105,7 @@ def sendAvailabilityViaServer(baseDir: str, session, # lookup the inbox for the To handle wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - domain, projectVersion) + domain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) diff --git a/daemon.py b/daemon.py index c483efc69..d4f4f893a 100644 --- a/daemon.py +++ b/daemon.py @@ -1379,7 +1379,7 @@ class PubServer(BaseHTTPRequestHandler): if GETtimings.get(prevGetId): timeDiff = int(timeDiff - int(GETtimings[prevGetId])) GETtimings[currGetId] = str(timeDiff) - if logEvent: + if logEvent and self.server.debug: print('GET TIMING ' + currGetId + ' = ' + str(timeDiff)) def _benchmarkPOSTtimings(self, POSTstartTime, POSTtimings: [], @@ -1397,7 +1397,8 @@ class PubServer(BaseHTTPRequestHandler): if logEvent: ctr = 1 for timeDiff in POSTtimings: - print('POST TIMING|' + str(ctr) + '|' + timeDiff) + if self.server.debug: + print('POST TIMING|' + str(ctr) + '|' + timeDiff) ctr += 1 def _pathContainsBlogLink(self, baseDir: str, @@ -7351,6 +7352,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.peertubeInstances, self.server.allowLocalNetworkAccess, self.server.textModeBanner, + self.server.debug, actorJson['roles'], None, None) msg = msg.encode('utf-8') @@ -7439,6 +7441,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.peertubeInstances, allowLocalNetworkAccess, self.server.textModeBanner, + self.server.debug, actorJson['skills'], None, None) msg = msg.encode('utf-8') @@ -9243,6 +9246,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.peertubeInstances, self.server.allowLocalNetworkAccess, self.server.textModeBanner, + self.server.debug, shares, pageNumber, sharesPerPage) msg = msg.encode('utf-8') @@ -9341,6 +9345,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.peertubeInstances, self.server.allowLocalNetworkAccess, self.server.textModeBanner, + self.server.debug, following, pageNumber, followsPerPage).encode('utf-8') @@ -9439,6 +9444,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.peertubeInstances, self.server.allowLocalNetworkAccess, self.server.textModeBanner, + self.server.debug, followers, pageNumber, followsPerPage).encode('utf-8') @@ -9560,6 +9566,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.peertubeInstances, self.server.allowLocalNetworkAccess, self.server.textModeBanner, + self.server.debug, None, None).encode('utf-8') msglen = len(msg) self._set_headers('text/html', msglen, @@ -13637,7 +13644,7 @@ class PubServer(BaseHTTPRequestHandler): # check authorization authorized = self._isAuthorized() - if not authorized: + if not authorized and self.server.debug: print('POST Not authorized') print(str(self.headers)) @@ -14236,7 +14243,8 @@ class PubServer(BaseHTTPRequestHandler): return else: if self.path == '/sharedInbox' or self.path == '/inbox': - print('DEBUG: POST to shared inbox') + if self.server.debug: + print('DEBUG: POST to shared inbox') queueStatus = \ self._updateInboxQueue('inbox', messageJson, messageBytes) if queueStatus >= 0 and queueStatus <= 3: diff --git a/delete.py b/delete.py index 027221abb..737f574e8 100644 --- a/delete.py +++ b/delete.py @@ -55,7 +55,7 @@ def sendDeleteViaServer(baseDir: str, session, # lookup the inbox for the To handle wfRequest = \ webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - fromDomain, projectVersion) + fromDomain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) diff --git a/epicyon.py b/epicyon.py index 707ed1163..f31ef781a 100644 --- a/epicyon.py +++ b/epicyon.py @@ -1477,7 +1477,7 @@ if args.followers: handle = nickname + '@' + domain wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - None, __version__) + None, __version__, debug) if not wfRequest: print('Unable to webfinger ' + handle) sys.exit() diff --git a/follow.py b/follow.py index e4d20d815..6404eda2a 100644 --- a/follow.py +++ b/follow.py @@ -989,7 +989,7 @@ def sendFollowRequestViaServer(baseDir: str, session, # lookup the inbox for the To handle wfRequest = \ webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - fromDomain, projectVersion) + fromDomain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) @@ -1078,7 +1078,7 @@ def sendUnfollowRequestViaServer(baseDir: str, session, # lookup the inbox for the To handle wfRequest = \ webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - fromDomain, projectVersion) + fromDomain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) diff --git a/inbox.py b/inbox.py index 1e92ed930..de3587042 100644 --- a/inbox.py +++ b/inbox.py @@ -2702,7 +2702,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, queue.pop(0) continue - print('Loading queue item ' + queueFilename) + if debug: + print('Loading queue item ' + queueFilename) # Load the queue json queueJson = loadJson(queueFilename, 1) @@ -2829,7 +2830,7 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if accountMaxPostsPerDay > 0 or domainMaxPostsPerDay > 0: pprint(quotasDaily) - if queueJson.get('actor'): + if debug and queueJson.get('actor'): print('Obtaining public key for actor ' + queueJson['actor']) # Try a few times to obtain the public key @@ -3053,8 +3054,9 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, httpPrefix, domain, port, debug) if len(recipientsDict.items()) == 0 and \ len(recipientsDictFollowers.items()) == 0: - print('Queue: no recipients were resolved ' + - 'for post arriving in inbox') + if debug: + print('Queue: no recipients were resolved ' + + 'for post arriving in inbox') if os.path.isfile(queueFilename): os.remove(queueFilename) if len(queue) > 0: @@ -3122,8 +3124,7 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, themeName) if debug: pprint(queueJson['post']) - - print('Queue: Queue post accepted') + print('Queue: Queue post accepted') if os.path.isfile(queueFilename): os.remove(queueFilename) if len(queue) > 0: diff --git a/like.py b/like.py index 4dcc86ceb..acf243f52 100644 --- a/like.py +++ b/like.py @@ -167,7 +167,7 @@ def sendLikeViaServer(baseDir: str, session, # lookup the inbox for the To handle wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - fromDomain, projectVersion) + fromDomain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) @@ -248,7 +248,7 @@ def sendUndoLikeViaServer(baseDir: str, session, # lookup the inbox for the To handle wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - fromDomain, projectVersion) + fromDomain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) diff --git a/migrate.py b/migrate.py index 9d050f114..9c24dce82 100644 --- a/migrate.py +++ b/migrate.py @@ -56,7 +56,7 @@ def _updateMovedHandle(baseDir: str, nickname: str, domain: str, handle = handle[1:] wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - None, __version__) + None, __version__, debug) if not wfRequest: print('updateMovedHandle unable to webfinger ' + handle) return ctr diff --git a/person.py b/person.py index d08963e22..e4d3c3f01 100644 --- a/person.py +++ b/person.py @@ -1102,7 +1102,8 @@ def setPersonNotes(baseDir: str, nickname: str, domain: str, return True -def getActorJson(handle: str, http: bool, gnunet: bool, quiet=False) -> {}: +def getActorJson(handle: str, http: bool, gnunet: bool, + debug: bool, quiet=False) -> {}: """Returns the actor json """ originalActor = handle @@ -1175,7 +1176,7 @@ def getActorJson(handle: str, http: bool, gnunet: bool, quiet=False) -> {}: handle = nickname + '@' + domain wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - None, __version__) + None, __version__, debug) if not wfRequest: if not quiet: print('Unable to webfinger ' + handle) diff --git a/posts.py b/posts.py index 6636a9c17..676ea3e67 100644 --- a/posts.py +++ b/posts.py @@ -1935,7 +1935,7 @@ def sendPost(projectVersion: str, # lookup the inbox for the To handle wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - domain, projectVersion) + domain, projectVersion, debug) if not wfRequest: return 1 if not isinstance(wfRequest, dict): @@ -2052,7 +2052,7 @@ def sendPostViaServer(projectVersion: str, # lookup the inbox for the To handle wfRequest = \ webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - fromDomain, projectVersion) + fromDomain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: webfinger failed for ' + handle) @@ -2249,7 +2249,7 @@ def sendSignedJson(postJsonObject: {}, session, baseDir: str, # lookup the inbox for the To handle wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - domain, projectVersion) + domain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: webfinger for ' + handle + ' failed') @@ -2538,7 +2538,8 @@ def sendToNamedAddresses(session, baseDir: str, personCache, debug, projectVersion) -def _hasSharedInbox(session, httpPrefix: str, domain: str) -> bool: +def _hasSharedInbox(session, httpPrefix: str, domain: str, + debug: bool) -> bool: """Returns true if the given domain has a shared inbox This tries the new and the old way of webfingering the shared inbox """ @@ -2547,9 +2548,8 @@ def _hasSharedInbox(session, httpPrefix: str, domain: str) -> bool: 'inbox@' + domain ] for handle in tryHandles: - wfRequest = webfingerHandle(session, handle, - httpPrefix, {}, - None, __version__) + wfRequest = webfingerHandle(session, handle, httpPrefix, {}, + None, __version__, debug) if wfRequest: if isinstance(wfRequest, dict): if not wfRequest.get('errors'): @@ -2634,7 +2634,8 @@ def sendToFollowers(session, baseDir: str, print('Sending post to followers domain is active: ' + followerDomainUrl) - withSharedInbox = _hasSharedInbox(session, httpPrefix, followerDomain) + withSharedInbox = _hasSharedInbox(session, httpPrefix, + followerDomain, debug) if debug: if withSharedInbox: print(followerDomain + ' has shared inbox') @@ -3463,7 +3464,7 @@ def getPublicPostsOfPerson(baseDir: str, nickname: str, domain: str, handle = httpPrefix + "://" + domainFull + "/@" + nickname wfRequest = \ webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - domain, projectVersion) + domain, projectVersion, debug) if not wfRequest: sys.exit() if not isinstance(wfRequest, dict): @@ -3505,7 +3506,7 @@ def getPublicPostDomains(session, baseDir: str, nickname: str, domain: str, handle = httpPrefix + "://" + domainFull + "/@" + nickname wfRequest = \ webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - domain, projectVersion) + domain, projectVersion, debug) if not wfRequest: return domainList if not isinstance(wfRequest, dict): @@ -3585,7 +3586,7 @@ def getPublicPostInfo(session, baseDir: str, nickname: str, domain: str, handle = httpPrefix + "://" + domainFull + "/@" + nickname wfRequest = \ webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - domain, projectVersion) + domain, projectVersion, debug) if not wfRequest: return {} if not isinstance(wfRequest, dict): @@ -4148,7 +4149,7 @@ def sendBlockViaServer(baseDir: str, session, # lookup the inbox for the To handle wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - fromDomain, projectVersion) + fromDomain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) @@ -4232,7 +4233,7 @@ def sendUndoBlockViaServer(baseDir: str, session, # lookup the inbox for the To handle wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - fromDomain, projectVersion) + fromDomain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) diff --git a/roles.py b/roles.py index 7af860db5..218ff7d3a 100644 --- a/roles.py +++ b/roles.py @@ -310,7 +310,7 @@ def sendRoleViaServer(baseDir: str, session, # lookup the inbox for the To handle wfRequest = webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - delegatorDomain, projectVersion) + delegatorDomain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) diff --git a/shares.py b/shares.py index cf726d1a6..239f79a70 100644 --- a/shares.py +++ b/shares.py @@ -358,7 +358,7 @@ def sendShareViaServer(baseDir, session, wfRequest = \ webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - fromDomain, projectVersion) + fromDomain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) @@ -457,7 +457,7 @@ def sendUndoShareViaServer(baseDir: str, session, # lookup the inbox for the To handle wfRequest = \ webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - fromDomain, projectVersion) + fromDomain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) diff --git a/skills.py b/skills.py index dd8ac8eac..267c43f37 100644 --- a/skills.py +++ b/skills.py @@ -123,7 +123,7 @@ def sendSkillViaServer(baseDir: str, session, nickname: str, password: str, wfRequest = \ webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - domain, projectVersion) + domain, projectVersion, debug) if not wfRequest: if debug: print('DEBUG: announce webfinger failed for ' + handle) diff --git a/socnet.py b/socnet.py index 42fbfd072..30450c1ff 100644 --- a/socnet.py +++ b/socnet.py @@ -52,7 +52,7 @@ def instancesGraph(baseDir: str, handles: str, wfRequest = \ webfingerHandle(session, handle, httpPrefix, cachedWebfingers, - domain, projectVersion) + domain, projectVersion, debug) if not wfRequest: return dotGraphStr + '}\n' if not isinstance(wfRequest, dict): diff --git a/webapp_post.py b/webapp_post.py index 1cd2099b6..895908213 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -1223,7 +1223,7 @@ def individualPostAsHtml(allowDownloads: bool, postActorWf = \ webfingerHandle(session, postActorHandle, httpPrefix, cachedWebfingers, - domain, __version__) + domain, __version__, False) avatarUrl2 = None displayName = None diff --git a/webapp_profile.py b/webapp_profile.py index 1a987244b..0a4902822 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -115,7 +115,7 @@ def htmlProfileAfterSearch(cssCache: {}, webfingerHandle(session, searchNickname + '@' + searchDomainFull, httpPrefix, cachedWebfingers, - domain, projectVersion) + domain, projectVersion, debug) if not wf: print('DEBUG: Unable to webfinger ' + searchNickname + '@' + searchDomainFull) @@ -481,6 +481,7 @@ def htmlProfile(rssIconAtTop: bool, peertubeInstances: [], allowLocalNetworkAccess: bool, textModeBanner: str, + debug: bool, extraJson=None, pageNumber=None, maxItemsPerPage=None) -> str: """Show the profile page as html @@ -816,7 +817,7 @@ def htmlProfile(rssIconAtTop: bool, cachedWebfingers, personCache, extraJson, projectVersion, ["unfollow"], selected, usersPath, pageNumber, maxItemsPerPage, - dormantMonths) + dormantMonths, debug) elif selected == 'followers': profileStr += \ _htmlProfileFollowing(translate, baseDir, httpPrefix, @@ -825,7 +826,7 @@ def htmlProfile(rssIconAtTop: bool, cachedWebfingers, personCache, extraJson, projectVersion, ["block"], selected, usersPath, pageNumber, - maxItemsPerPage, dormantMonths) + maxItemsPerPage, dormantMonths, debug) elif selected == 'roles': profileStr += \ _htmlProfileRoles(translate, nickname, domainFull, @@ -920,7 +921,7 @@ def _htmlProfileFollowing(translate: {}, baseDir: str, httpPrefix: str, feedName: str, actor: str, pageNumber: int, maxItemsPerPage: int, - dormantMonths: int) -> str: + dormantMonths: int, debug: bool) -> str: """Shows following on the profile screen """ profileStr = '' @@ -952,7 +953,7 @@ def _htmlProfileFollowing(translate: {}, baseDir: str, httpPrefix: str, domain, followingActor, authorized, nickname, httpPrefix, projectVersion, dormant, - buttons) + debug, buttons) if authorized and maxItemsPerPage and pageNumber: if len(followingJson['orderedItems']) >= maxItemsPerPage: @@ -1801,6 +1802,7 @@ def _individualFollowAsHtml(translate: {}, httpPrefix: str, projectVersion: str, dormant: bool, + debug: bool, buttons=[]) -> str: """An individual follow entry on the profile screen """ @@ -1817,7 +1819,7 @@ def _individualFollowAsHtml(translate: {}, followUrlWf = \ webfingerHandle(session, followUrlHandle, httpPrefix, cachedWebfingers, - domain, __version__) + domain, __version__, debug) (inboxUrl, pubKeyId, pubKey, fromPersonId, sharedInbox, diff --git a/webfinger.py b/webfinger.py index 29c63bad7..920f97af7 100644 --- a/webfinger.py +++ b/webfinger.py @@ -40,11 +40,13 @@ def _parseHandle(handle: str) -> (str, str): def webfingerHandle(session, handle: str, httpPrefix: str, cachedWebfingers: {}, - fromDomain: str, projectVersion: str) -> {}: + fromDomain: str, projectVersion: str, + debug: bool) -> {}: """Gets webfinger result for the given ActivityPub handle """ if not session: - print('WARN: No session specified for webfingerHandle') + if debug: + print('WARN: No session specified for webfingerHandle') return None nickname, domain = _parseHandle(handle) @@ -60,7 +62,8 @@ def webfingerHandle(session, handle: str, httpPrefix: str, wf = getWebfingerFromCache(nickname + '@' + wfDomain, cachedWebfingers) if wf: - print('Webfinger from cache: ' + str(wf)) + if debug: + print('Webfinger from cache: ' + str(wf)) return wf url = '{}://{}/.well-known/webfinger'.format(httpPrefix, domain) par = { @@ -81,11 +84,12 @@ def webfingerHandle(session, handle: str, httpPrefix: str, storeWebfingerInCache(nickname + '@' + wfDomain, result, cachedWebfingers) else: - print("WARN: Unable to webfinger " + url + ' ' + - 'nickname: ' + str(nickname) + ' ' + - 'domain: ' + str(wfDomain) + ' ' + - 'headers: ' + str(hdr) + ' ' + - 'params: ' + str(par)) + if debug: + print("WARN: Unable to webfinger " + url + ' ' + + 'nickname: ' + str(nickname) + ' ' + + 'domain: ' + str(wfDomain) + ' ' + + 'headers: ' + str(hdr) + ' ' + + 'params: ' + str(par)) return result