Less verbose when not in debug

merge-requests/21/head
Bob Mottram 2021-03-14 19:22:58 +00:00
parent df0179768f
commit faadca51b6
18 changed files with 71 additions and 54 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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:

View File

@ -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)

View File

@ -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()

View File

@ -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)

View File

@ -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:

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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):

View File

@ -1223,7 +1223,7 @@ def individualPostAsHtml(allowDownloads: bool,
postActorWf = \
webfingerHandle(session, postActorHandle, httpPrefix,
cachedWebfingers,
domain, __version__)
domain, __version__, False)
avatarUrl2 = None
displayName = None

View File

@ -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,

View File

@ -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