mirror of https://gitlab.com/bashrc2/epicyon
Merge branch 'main' of gitlab.com:bashrc2/epicyon
commit
453761f56e
3
auth.py
3
auth.py
|
|
@ -203,7 +203,7 @@ def authorize(baseDir: str, path: str, authHeader: str, debug: bool) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def createPassword(length: int = 10):
|
||||
def createPassword(length: int):
|
||||
validChars = 'abcdefghijklmnopqrstuvwxyz' + \
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
||||
return ''.join((secrets.choice(validChars) for i in range(length)))
|
||||
|
|
@ -255,4 +255,5 @@ def recordLoginFailure(baseDir: str, ipAddress: str,
|
|||
ipAddress + ' port 443: ' +
|
||||
'Too many authentication failures [preauth]\n')
|
||||
except BaseException:
|
||||
print('EX: recordLoginFailure failed ' + str(failureLog))
|
||||
pass
|
||||
|
|
|
|||
22
blocking.py
22
blocking.py
|
|
@ -517,6 +517,8 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
|
|||
os.remove(cachedPostFilename)
|
||||
print('MUTE: cached post removed ' + cachedPostFilename)
|
||||
except BaseException:
|
||||
print('EX: MUTE cached post not removed ' +
|
||||
cachedPostFilename)
|
||||
pass
|
||||
else:
|
||||
print('MUTE: cached post not found ' + cachedPostFilename)
|
||||
|
|
@ -554,6 +556,9 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
|
|||
print('MUTE: cached referenced post removed ' +
|
||||
cachedPostFilename)
|
||||
except BaseException:
|
||||
print('EX: ' +
|
||||
'MUTE cached referenced post not removed ' +
|
||||
cachedPostFilename)
|
||||
pass
|
||||
|
||||
if recentPostsCache.get('json'):
|
||||
|
|
@ -583,6 +588,9 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int,
|
|||
try:
|
||||
os.remove(muteFilename)
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: unmutePost mute filename not deleted ' +
|
||||
str(muteFilename))
|
||||
pass
|
||||
print('UNMUTE: ' + muteFilename + ' file removed')
|
||||
|
||||
|
|
@ -631,6 +639,9 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int,
|
|||
try:
|
||||
os.remove(cachedPostFilename)
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: unmutePost cached post not deleted ' +
|
||||
str(cachedPostFilename))
|
||||
pass
|
||||
|
||||
# if the post is in the recent posts cache then mark it as unmuted
|
||||
|
|
@ -661,6 +672,10 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int,
|
|||
print('MUTE: cached referenced post removed ' +
|
||||
cachedPostFilename)
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: ' +
|
||||
'unmutePost cached ref post not removed ' +
|
||||
str(cachedPostFilename))
|
||||
pass
|
||||
|
||||
if recentPostsCache.get('json'):
|
||||
|
|
@ -804,6 +819,8 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
|
|||
try:
|
||||
os.remove(allowFilename)
|
||||
except BaseException:
|
||||
print('EX: setBrochMode allow file not deleted ' +
|
||||
str(allowFilename))
|
||||
pass
|
||||
print('Broch mode turned off')
|
||||
else:
|
||||
|
|
@ -844,7 +861,7 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
|
|||
setConfigParam(baseDir, "brochMode", enabled)
|
||||
|
||||
|
||||
def brochModeLapses(baseDir: str, lapseDays: int = 7) -> bool:
|
||||
def brochModeLapses(baseDir: str, lapseDays: int) -> bool:
|
||||
"""After broch mode is enabled it automatically
|
||||
elapses after a period of time
|
||||
"""
|
||||
|
|
@ -857,6 +874,7 @@ def brochModeLapses(baseDir: str, lapseDays: int = 7) -> bool:
|
|||
modifiedDate = \
|
||||
datetime.strptime(lastModified, "%Y-%m-%dT%H:%M:%SZ")
|
||||
except BaseException:
|
||||
print('EX: brochModeLapses date not parsed ' + str(lastModified))
|
||||
return False
|
||||
if not modifiedDate:
|
||||
return False
|
||||
|
|
@ -868,6 +886,8 @@ def brochModeLapses(baseDir: str, lapseDays: int = 7) -> bool:
|
|||
os.remove(allowFilename)
|
||||
removed = True
|
||||
except BaseException:
|
||||
print('EX: brochModeLapses allow file not deleted ' +
|
||||
str(allowFilename))
|
||||
pass
|
||||
if removed:
|
||||
setConfigParam(baseDir, "brochMode", False)
|
||||
|
|
|
|||
|
|
@ -52,6 +52,10 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
|
|||
try:
|
||||
os.remove(cachedPostFilename)
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: undoBookmarksCollectionEntry ' +
|
||||
'unable to delete cached post file ' +
|
||||
str(cachedPostFilename))
|
||||
pass
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
|
||||
|
|
@ -160,6 +164,10 @@ def updateBookmarksCollection(recentPostsCache: {},
|
|||
try:
|
||||
os.remove(cachedPostFilename)
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: updateBookmarksCollection ' +
|
||||
'unable to delete cached post ' +
|
||||
str(cachedPostFilename))
|
||||
pass
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
|
||||
|
|
|
|||
1
cache.py
1
cache.py
|
|
@ -27,6 +27,7 @@ def _removePersonFromCache(baseDir: str, personUrl: str,
|
|||
try:
|
||||
os.remove(cacheFilename)
|
||||
except BaseException:
|
||||
print('EX: unable to delete cached actor ' + str(cacheFilename))
|
||||
pass
|
||||
if personCache.get(personUrl):
|
||||
del personCache[personUrl]
|
||||
|
|
|
|||
|
|
@ -96,6 +96,9 @@ def updateHashtagCategories(baseDir: str) -> None:
|
|||
try:
|
||||
os.remove(categoryListFilename)
|
||||
except BaseException:
|
||||
print('EX: updateHashtagCategories ' +
|
||||
'unable to delete cached category list ' +
|
||||
categoryListFilename)
|
||||
pass
|
||||
return
|
||||
|
||||
|
|
|
|||
16
content.py
16
content.py
|
|
@ -272,6 +272,8 @@ def replaceEmojiFromTags(content: str, tag: [], messageType: str) -> str:
|
|||
content = content.replace(tagItem['name'],
|
||||
replaceChar)
|
||||
except BaseException:
|
||||
print('EX: replaceEmojiFromTags name ' +
|
||||
str(iconName))
|
||||
pass
|
||||
else:
|
||||
# sequence of codes
|
||||
|
|
@ -283,6 +285,8 @@ def replaceEmojiFromTags(content: str, tag: [], messageType: str) -> str:
|
|||
icode, 16))
|
||||
except BaseException:
|
||||
iconCodeSequence = ''
|
||||
print('EX: replaceEmojiFromTags code ' +
|
||||
str(icode))
|
||||
break
|
||||
if iconCodeSequence:
|
||||
content = content.replace(tagItem['name'],
|
||||
|
|
@ -943,11 +947,19 @@ def saveMediaInFormPOST(mediaBytes, debug: bool,
|
|||
try:
|
||||
os.remove(possibleOtherFormat)
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: saveMediaInFormPOST ' +
|
||||
'unable to delete other ' +
|
||||
str(possibleOtherFormat))
|
||||
pass
|
||||
if os.path.isfile(filenameBase):
|
||||
try:
|
||||
os.remove(filenameBase)
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: saveMediaInFormPOST ' +
|
||||
'unable to delete ' +
|
||||
str(filenameBase))
|
||||
pass
|
||||
|
||||
if debug:
|
||||
|
|
@ -1017,6 +1029,10 @@ def saveMediaInFormPOST(mediaBytes, debug: bool,
|
|||
try:
|
||||
os.remove(possibleOtherFormat)
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: saveMediaInFormPOST ' +
|
||||
'unable to delete other 2 ' +
|
||||
str(possibleOtherFormat))
|
||||
pass
|
||||
|
||||
# don't allow scripts within svg files
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ def updateConversation(baseDir: str, nickname: str, domain: str,
|
|||
fp.write(postId + '\n')
|
||||
return True
|
||||
except BaseException:
|
||||
print('EX: updateConversation ' +
|
||||
'unable to write to ' + conversationFilename)
|
||||
pass
|
||||
elif postId + '\n' not in open(conversationFilename).read():
|
||||
try:
|
||||
|
|
@ -53,6 +55,8 @@ def updateConversation(baseDir: str, nickname: str, domain: str,
|
|||
fp.write(postId + '\n')
|
||||
return True
|
||||
except BaseException:
|
||||
print('EX: updateConversation 2 ' +
|
||||
'unable to write to ' + conversationFilename)
|
||||
pass
|
||||
return False
|
||||
|
||||
|
|
@ -86,4 +90,6 @@ def unmuteConversation(baseDir: str, nickname: str, domain: str,
|
|||
try:
|
||||
os.remove(conversationFilename + '.muted')
|
||||
except BaseException:
|
||||
print('EX: unmuteConversation unable to delete ' +
|
||||
conversationFilename + '.muted')
|
||||
pass
|
||||
|
|
|
|||
124
daemon.py
124
daemon.py
|
|
@ -53,6 +53,7 @@ from donate import getDonationUrl
|
|||
from donate import setDonationUrl
|
||||
from donate import getWebsite
|
||||
from donate import setWebsite
|
||||
from person import addActorUpdateTimestamp
|
||||
from person import setPersonNotes
|
||||
from person import getDefaultPersonContext
|
||||
from person import getActorUpdateJson
|
||||
|
|
@ -540,6 +541,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(cachedPostFilename)
|
||||
except BaseException:
|
||||
print('EX: _sendReplyToQuestion ' +
|
||||
'unable to delete ' +
|
||||
cachedPostFilename)
|
||||
pass
|
||||
# remove from memory cache
|
||||
removePostFromCache(postJsonObject,
|
||||
|
|
@ -822,6 +826,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
with open(mediaFilename + '.etag', 'r') as etagFile:
|
||||
etag = etagFile.read()
|
||||
except BaseException:
|
||||
print('EX: _set_headers_etag ' +
|
||||
'unable to read ' + mediaFilename + '.etag')
|
||||
pass
|
||||
if not etag:
|
||||
etag = md5(data).hexdigest() # nosec
|
||||
|
|
@ -829,6 +835,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
with open(mediaFilename + '.etag', 'w+') as etagFile:
|
||||
etagFile.write(etag)
|
||||
except BaseException:
|
||||
print('EX: _set_headers_etag ' +
|
||||
'unable to write ' + mediaFilename + '.etag')
|
||||
pass
|
||||
# if etag:
|
||||
# self.send_header('ETag', '"' + etag + '"')
|
||||
|
|
@ -854,6 +862,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
with open(mediaFilename, 'r') as etagFile:
|
||||
currEtag = etagFile.read()
|
||||
except BaseException:
|
||||
print('EX: _etag_exists unable to read ' +
|
||||
str(mediaFilename))
|
||||
pass
|
||||
if currEtag and oldEtag == currEtag:
|
||||
# The file has not changed
|
||||
|
|
@ -984,17 +994,6 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
tries += 1
|
||||
return False
|
||||
|
||||
def _robotsTxt(self) -> bool:
|
||||
if not self.path.lower().startswith('/robot'):
|
||||
return False
|
||||
msg = 'User-agent: *\nDisallow: /'
|
||||
msg = msg.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
self._set_headers('text/plain; charset=utf-8', msglen,
|
||||
None, self.server.domainFull, True)
|
||||
self._write(msg)
|
||||
return True
|
||||
|
||||
def _hasAccept(self, callingDomain: str) -> bool:
|
||||
"""Do the http headers have an Accept field?
|
||||
"""
|
||||
|
|
@ -2339,6 +2338,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(newswireBlockedFilename)
|
||||
except BaseException:
|
||||
print('EX: _personOptions unable to delete ' +
|
||||
newswireBlockedFilename)
|
||||
pass
|
||||
refreshNewswire(self.server.baseDir)
|
||||
else:
|
||||
|
|
@ -2377,6 +2378,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(featuresBlockedFilename)
|
||||
except BaseException:
|
||||
print('EX: _personOptions unable to delete ' +
|
||||
featuresBlockedFilename)
|
||||
pass
|
||||
refreshNewswire(self.server.baseDir)
|
||||
else:
|
||||
|
|
@ -2415,6 +2418,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(newswireModFilename)
|
||||
except BaseException:
|
||||
print('EX: _personOptions unable to delete ' +
|
||||
newswireModFilename)
|
||||
pass
|
||||
else:
|
||||
if os.path.isdir(accountDir):
|
||||
|
|
@ -3848,6 +3853,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(linksFilename)
|
||||
except BaseException:
|
||||
print('EX: _linksUpdate unable to delete ' +
|
||||
linksFilename)
|
||||
pass
|
||||
|
||||
adminNickname = \
|
||||
|
|
@ -3864,6 +3871,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(aboutFilename)
|
||||
except BaseException:
|
||||
print('EX: _linksUpdate unable to delete ' +
|
||||
aboutFilename)
|
||||
pass
|
||||
|
||||
if fields.get('editedTOS'):
|
||||
|
|
@ -3877,6 +3886,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(TOSFilename)
|
||||
except BaseException:
|
||||
print('EX: _linksUpdate unable to delete ' +
|
||||
TOSFilename)
|
||||
pass
|
||||
|
||||
# redirect back to the default timeline
|
||||
|
|
@ -3978,6 +3989,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(categoryFilename)
|
||||
except BaseException:
|
||||
print('EX: _setHashtagCategory unable to delete ' +
|
||||
categoryFilename)
|
||||
pass
|
||||
|
||||
# redirect back to the default timeline
|
||||
|
|
@ -4059,6 +4072,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(newswireFilename)
|
||||
except BaseException:
|
||||
print('EX: _newswireUpdate unable to delete ' +
|
||||
newswireFilename)
|
||||
pass
|
||||
|
||||
# save filtered words list for the newswire
|
||||
|
|
@ -4073,6 +4088,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(filterNewswireFilename)
|
||||
except BaseException:
|
||||
print('EX: _newswireUpdate unable to delete ' +
|
||||
filterNewswireFilename)
|
||||
pass
|
||||
|
||||
# save news tagging rules
|
||||
|
|
@ -4086,6 +4103,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(hashtagRulesFilename)
|
||||
except BaseException:
|
||||
print('EX: _newswireUpdate unable to delete ' +
|
||||
hashtagRulesFilename)
|
||||
pass
|
||||
|
||||
newswireTrustedFilename = baseDir + '/accounts/newswiretrusted.txt'
|
||||
|
|
@ -4100,6 +4119,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(newswireTrustedFilename)
|
||||
except BaseException:
|
||||
print('EX: _newswireUpdate unable to delete ' +
|
||||
newswireTrustedFilename)
|
||||
pass
|
||||
|
||||
# redirect back to the default timeline
|
||||
|
|
@ -4128,6 +4149,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(citationsFilename)
|
||||
except BaseException:
|
||||
print('EX: _citationsUpdate unable to delete ' +
|
||||
citationsFilename)
|
||||
pass
|
||||
|
||||
if newswire and \
|
||||
|
|
@ -4433,6 +4456,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(filenameBase)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate unable to delete ' +
|
||||
filenameBase)
|
||||
pass
|
||||
else:
|
||||
filenameBase = \
|
||||
|
|
@ -4468,6 +4493,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(postImageFilename + '.etag')
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate unable to delete ' +
|
||||
postImageFilename + '.etag')
|
||||
pass
|
||||
|
||||
city = getSpoofedCity(self.server.city,
|
||||
|
|
@ -5503,6 +5530,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
os.remove(baseDir +
|
||||
'/fonts/custom.' + ext)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
baseDir + '/fonts/custom.' + ext)
|
||||
pass
|
||||
if os.path.isfile(baseDir +
|
||||
'/fonts/custom.' + ext +
|
||||
|
|
@ -5512,6 +5542,10 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
'/fonts/custom.' + ext +
|
||||
'.etag')
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
baseDir + '/fonts/custom.' +
|
||||
ext + '.etag')
|
||||
pass
|
||||
currTheme = getTheme(baseDir)
|
||||
if currTheme:
|
||||
|
|
@ -5563,6 +5597,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(followDMsFilename)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
followDMsFilename)
|
||||
pass
|
||||
|
||||
# remove Twitter retweets
|
||||
|
|
@ -5581,6 +5618,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(removeTwitterFilename)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
removeTwitterFilename)
|
||||
pass
|
||||
|
||||
# hide Like button
|
||||
|
|
@ -5601,12 +5641,18 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(notifyLikesFilename)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
notifyLikesFilename)
|
||||
pass
|
||||
if not hideLikeButtonActive:
|
||||
if os.path.isfile(hideLikeButtonFile):
|
||||
try:
|
||||
os.remove(hideLikeButtonFile)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
hideLikeButtonFile)
|
||||
pass
|
||||
|
||||
# notify about new Likes
|
||||
|
|
@ -5628,6 +5674,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(notifyLikesFilename)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
notifyLikesFilename)
|
||||
pass
|
||||
|
||||
# this account is a bot
|
||||
|
|
@ -5690,6 +5739,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(filterFilename)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
filterFilename)
|
||||
pass
|
||||
|
||||
# word replacements
|
||||
|
|
@ -5704,6 +5756,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(switchFilename)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
switchFilename)
|
||||
pass
|
||||
|
||||
# autogenerated tags
|
||||
|
|
@ -5718,6 +5773,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(autoTagsFilename)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
autoTagsFilename)
|
||||
pass
|
||||
|
||||
# autogenerated content warnings
|
||||
|
|
@ -5732,6 +5790,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(autoCWFilename)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
autoCWFilename)
|
||||
pass
|
||||
|
||||
# save blocked accounts list
|
||||
|
|
@ -5746,6 +5807,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(blockedFilename)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
blockedFilename)
|
||||
pass
|
||||
|
||||
# Save DM allowed instances list.
|
||||
|
|
@ -5762,6 +5826,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(dmAllowedInstancesFilename)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
dmAllowedInstancesFilename)
|
||||
pass
|
||||
|
||||
# save allowed instances list
|
||||
|
|
@ -5777,6 +5844,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(allowedInstancesFilename)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
allowedInstancesFilename)
|
||||
pass
|
||||
|
||||
if isModerator(self.server.baseDir, nickname):
|
||||
|
|
@ -5840,6 +5910,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(peertubeInstancesFile)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
peertubeInstancesFile)
|
||||
pass
|
||||
self.server.peertubeInstances.clear()
|
||||
|
||||
|
|
@ -5855,6 +5928,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(gitProjectsFilename)
|
||||
except BaseException:
|
||||
print('EX: _profileUpdate ' +
|
||||
'unable to delete ' +
|
||||
gitProjectsFilename)
|
||||
pass
|
||||
|
||||
# save actor json file within accounts
|
||||
|
|
@ -5874,13 +5950,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
actorJson['featuredTags'] = \
|
||||
actorJson['id'] + '/collections/tags'
|
||||
randomizeActorImages(actorJson)
|
||||
# add an updated timestamp to the actor
|
||||
updatedTime = datetime.datetime.utcnow()
|
||||
actorJson['updated'] = \
|
||||
updatedTime.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
# add updated timestamp to avatar and banner
|
||||
actorJson['icon']['updated'] = actorJson['updated']
|
||||
actorJson['image']['updated'] = actorJson['updated']
|
||||
addActorUpdateTimestamp(actorJson)
|
||||
# save the actor
|
||||
saveJson(actorJson, actorFilename)
|
||||
webfingerUpdate(baseDir,
|
||||
|
|
@ -13300,14 +13370,6 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
'_GET', 'show about screen done',
|
||||
self.server.debug)
|
||||
|
||||
# send robots.txt if asked
|
||||
if self._robotsTxt():
|
||||
return
|
||||
|
||||
fitnessPerformance(GETstartTime, self.server.fitness,
|
||||
'_GET', 'robots txt',
|
||||
self.server.debug)
|
||||
|
||||
# the initial welcome screen after first logging in
|
||||
if htmlGET and authorized and \
|
||||
'/users/' in self.path and self.path.endswith('/welcome'):
|
||||
|
|
@ -15106,6 +15168,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
with open(mediaTagFilename, 'r') as etagFile:
|
||||
etag = etagFile.read()
|
||||
except BaseException:
|
||||
print('EX: do_HEAD unable to read ' +
|
||||
mediaTagFilename)
|
||||
pass
|
||||
else:
|
||||
with open(mediaFilename, 'rb') as avFile:
|
||||
|
|
@ -15115,6 +15179,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
with open(mediaTagFilename, 'w+') as etagFile:
|
||||
etagFile.write(etag)
|
||||
except BaseException:
|
||||
print('EX: do_HEAD unable to write ' +
|
||||
mediaTagFilename)
|
||||
pass
|
||||
|
||||
mediaFileType = mediaFileMimeType(checkPath)
|
||||
|
|
@ -15281,6 +15347,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
with open(lastUsedFilename, 'w+') as lastUsedFile:
|
||||
lastUsedFile.write(str(int(time.time())))
|
||||
except BaseException:
|
||||
print('EX: _receiveNewPostProcess unable to write ' +
|
||||
lastUsedFilename)
|
||||
pass
|
||||
|
||||
mentionsStr = ''
|
||||
|
|
@ -15444,6 +15512,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(cachedFilename)
|
||||
except BaseException:
|
||||
print('EX: _receiveNewPostProcess ' +
|
||||
'unable to delete ' + cachedFilename)
|
||||
pass
|
||||
# remove from memory cache
|
||||
removePostFromCache(postJsonObject,
|
||||
|
|
@ -15867,6 +15937,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
try:
|
||||
os.remove(filename)
|
||||
except BaseException:
|
||||
print('EX: _receiveNewPostProcess ' +
|
||||
'unable to delete ' + filename)
|
||||
pass
|
||||
self.postToNickname = nickname
|
||||
return 1
|
||||
|
|
|
|||
|
|
@ -202,4 +202,5 @@ def removeOldHashtags(baseDir: str, maxMonths: int) -> str:
|
|||
try:
|
||||
os.remove(removeFilename)
|
||||
except BaseException:
|
||||
print('EX: removeOldHashtags unable to delete ' + removeFilename)
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -954,9 +954,9 @@ def _desktopShowBox(indent: str,
|
|||
yourActor: str, boxName: str, boxJson: {},
|
||||
translate: {},
|
||||
screenreader: str, systemLanguage: str, espeak,
|
||||
pageNumber: int = 1,
|
||||
newReplies: bool = False,
|
||||
newDMs: bool = False) -> bool:
|
||||
pageNumber: int,
|
||||
newReplies: bool,
|
||||
newDMs: bool) -> bool:
|
||||
"""Shows online timeline
|
||||
"""
|
||||
numberWidth = 2
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ def E2EEremoveDevice(baseDir: str, nickname: str, domain: str,
|
|||
try:
|
||||
os.remove(deviceFilename)
|
||||
except BaseException:
|
||||
print('EX: E2EEremoveDevice unable to delete ' + deviceFilename)
|
||||
pass
|
||||
return True
|
||||
return False
|
||||
|
|
|
|||
19
epicyon.py
19
epicyon.py
|
|
@ -883,6 +883,7 @@ if args.socnet:
|
|||
fp.write(dotGraph)
|
||||
print('Saved to socnet.dot')
|
||||
except BaseException:
|
||||
print('EX: commandline unable to write socnet.dot')
|
||||
pass
|
||||
sys.exit()
|
||||
|
||||
|
|
@ -2100,7 +2101,7 @@ if args.followers:
|
|||
'Accept': 'application/activity+json; profile="' + profileStr + '"'
|
||||
}
|
||||
if not personUrl:
|
||||
personUrl = getUserUrl(wfRequest)
|
||||
personUrl = getUserUrl(wfRequest, 0, args.debug)
|
||||
if nickname == domain:
|
||||
personUrl = personUrl.replace('/users/', '/actor/')
|
||||
personUrl = personUrl.replace('/accounts/', '/actor/')
|
||||
|
|
@ -2126,7 +2127,7 @@ if args.followers:
|
|||
followersList = \
|
||||
downloadFollowCollection(signingPrivateKeyPem,
|
||||
'followers', session,
|
||||
httpPrefix, personUrl, 1, 3)
|
||||
httpPrefix, personUrl, 1, 3, args.debug)
|
||||
if followersList:
|
||||
for actor in followersList:
|
||||
print(actor)
|
||||
|
|
@ -2673,17 +2674,19 @@ if args.testdata:
|
|||
print('Generating some test data for user: ' + nickname)
|
||||
|
||||
if os.path.isdir(baseDir + '/tags'):
|
||||
shutil.rmtree(baseDir + '/tags')
|
||||
shutil.rmtree(baseDir + '/tags', ignore_errors=False, onerror=None)
|
||||
if os.path.isdir(baseDir + '/accounts'):
|
||||
shutil.rmtree(baseDir + '/accounts')
|
||||
shutil.rmtree(baseDir + '/accounts', ignore_errors=False, onerror=None)
|
||||
if os.path.isdir(baseDir + '/keys'):
|
||||
shutil.rmtree(baseDir + '/keys')
|
||||
shutil.rmtree(baseDir + '/keys', ignore_errors=False, onerror=None)
|
||||
if os.path.isdir(baseDir + '/media'):
|
||||
shutil.rmtree(baseDir + '/media')
|
||||
shutil.rmtree(baseDir + '/media', ignore_errors=False, onerror=None)
|
||||
if os.path.isdir(baseDir + '/sharefiles'):
|
||||
shutil.rmtree(baseDir + '/sharefiles')
|
||||
shutil.rmtree(baseDir + '/sharefiles',
|
||||
ignore_errors=False, onerror=None)
|
||||
if os.path.isdir(baseDir + '/wfendpoints'):
|
||||
shutil.rmtree(baseDir + '/wfendpoints')
|
||||
shutil.rmtree(baseDir + '/wfendpoints',
|
||||
ignore_errors=False, onerror=None)
|
||||
|
||||
setConfigParam(baseDir, 'registrationsRemaining',
|
||||
str(maxRegistrations))
|
||||
|
|
|
|||
|
|
@ -319,6 +319,7 @@ def clearFollows(baseDir: str, nickname: str, domain: str,
|
|||
try:
|
||||
os.remove(filename)
|
||||
except BaseException:
|
||||
print('EX: clearFollows unable to delete ' + filename)
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -390,6 +391,8 @@ def getFollowingFeed(baseDir: str, domain: str, port: int, path: str,
|
|||
try:
|
||||
pageNumber = int(pageNumber)
|
||||
except BaseException:
|
||||
print('EX: getFollowingFeed unable to convert to int ' +
|
||||
str(pageNumber))
|
||||
pass
|
||||
path = path.split('?page=')[0]
|
||||
headerOnly = False
|
||||
|
|
@ -883,6 +886,8 @@ def followedAccountAccepts(session, baseDir: str, httpPrefix: str,
|
|||
try:
|
||||
os.remove(followActivityfilename)
|
||||
except BaseException:
|
||||
print('EX: followedAccountAccepts unable to delete ' +
|
||||
followActivityfilename)
|
||||
pass
|
||||
|
||||
groupAccount = False
|
||||
|
|
@ -956,6 +961,8 @@ def followedAccountRejects(session, baseDir: str, httpPrefix: str,
|
|||
try:
|
||||
os.remove(followActivityfilename)
|
||||
except BaseException:
|
||||
print('EX: followedAccountRejects unable to delete ' +
|
||||
followActivityfilename)
|
||||
pass
|
||||
# send the reject activity
|
||||
return sendSignedJson(rejectJson, session, baseDir,
|
||||
|
|
|
|||
10
happening.py
10
happening.py
|
|
@ -20,7 +20,7 @@ from utils import hasObjectDict
|
|||
from utils import acctDir
|
||||
|
||||
|
||||
def _validUuid(testUuid: str, version: int = 4):
|
||||
def _validUuid(testUuid: str, version: int):
|
||||
"""Check if uuid_to_test is a valid UUID
|
||||
"""
|
||||
try:
|
||||
|
|
@ -42,7 +42,7 @@ def _removeEventFromTimeline(eventId: str, tlEventsFilename: str) -> None:
|
|||
with open(tlEventsFilename, 'w+') as fp2:
|
||||
fp2.write(eventsTimeline)
|
||||
except BaseException:
|
||||
print('ERROR: unable to save events timeline')
|
||||
print('EX: ERROR: unable to save events timeline')
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ def saveEventPost(baseDir: str, handle: str, postId: str,
|
|||
|
||||
if eventJson.get('name') and eventJson.get('actor') and \
|
||||
eventJson.get('uuid') and eventJson.get('content'):
|
||||
if not _validUuid(eventJson['uuid']):
|
||||
if not _validUuid(eventJson['uuid'], 4):
|
||||
return False
|
||||
print('Mobilizon type event')
|
||||
# if this is a full description of an event then save it
|
||||
|
|
@ -166,8 +166,8 @@ def _isHappeningPost(postJsonObject: {}) -> bool:
|
|||
|
||||
|
||||
def getTodaysEvents(baseDir: str, nickname: str, domain: str,
|
||||
currYear: int = None, currMonthNumber: int = None,
|
||||
currDayOfMonth: int = None) -> {}:
|
||||
currYear: int, currMonthNumber: int,
|
||||
currDayOfMonth: int) -> {}:
|
||||
"""Retrieves calendar events for today
|
||||
Returns a dictionary of lists containing Event and Place activities
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -467,5 +467,5 @@ def verifyPostHeaders(httpPrefix: str, publicKeyPem: str, headers: dict,
|
|||
return True
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('DEBUG: verifyPostHeaders pkcs1_15 verify failure')
|
||||
print('EX: verifyPostHeaders pkcs1_15 verify failure')
|
||||
return False
|
||||
|
|
|
|||
49
inbox.py
49
inbox.py
|
|
@ -136,7 +136,7 @@ def _storeLastPostId(baseDir: str, nickname: str, domain: str,
|
|||
with open(actorFilename, 'w+') as fp:
|
||||
fp.write(postId)
|
||||
except BaseException:
|
||||
print('Unable to write last post id to ' + actorFilename)
|
||||
print('EX: Unable to write last post id to ' + actorFilename)
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -155,7 +155,7 @@ def _updateCachedHashtagSwarm(baseDir: str, nickname: str, domain: str,
|
|||
modifiedDate = \
|
||||
datetime.datetime.strptime(lastModified, "%Y-%m-%dT%H:%M:%SZ")
|
||||
except BaseException:
|
||||
print('WARN: unable to parse last modified cache date ' +
|
||||
print('EX: unable to parse last modified cache date ' +
|
||||
str(lastModified))
|
||||
pass
|
||||
if modifiedDate:
|
||||
|
|
@ -180,7 +180,7 @@ def _updateCachedHashtagSwarm(baseDir: str, nickname: str, domain: str,
|
|||
fp.write(newSwarmStr)
|
||||
return True
|
||||
except BaseException:
|
||||
print('WARN: unable to write cached hashtag swarm ' +
|
||||
print('EX: unable to write cached hashtag swarm ' +
|
||||
cachedHashtagSwarmFilename)
|
||||
pass
|
||||
return False
|
||||
|
|
@ -911,6 +911,8 @@ def _receiveUpdateToQuestion(recentPostsCache: {}, messageJson: {},
|
|||
try:
|
||||
os.remove(cachedPostFilename)
|
||||
except BaseException:
|
||||
print('EX: _receiveUpdateToQuestion unable to delete ' +
|
||||
cachedPostFilename)
|
||||
pass
|
||||
# remove from memory cache
|
||||
removePostFromCache(messageJson, recentPostsCache)
|
||||
|
|
@ -1659,6 +1661,8 @@ def _receiveAnnounce(recentPostsCache: {},
|
|||
try:
|
||||
os.remove(postFilename)
|
||||
except BaseException:
|
||||
print('EX: _receiveAnnounce unable to delete ' +
|
||||
str(postFilename))
|
||||
pass
|
||||
else:
|
||||
if debug:
|
||||
|
|
@ -1684,7 +1688,7 @@ def _receiveAnnounce(recentPostsCache: {},
|
|||
if '/statuses/' in lookupActor:
|
||||
lookupActor = lookupActor.split('/statuses/')[0]
|
||||
|
||||
if isRecentPost(postJsonObject):
|
||||
if isRecentPost(postJsonObject, 3):
|
||||
if not os.path.isfile(postFilename + '.tts'):
|
||||
domainFull = getFullDomain(domain, port)
|
||||
updateSpeaker(baseDir, httpPrefix,
|
||||
|
|
@ -1772,6 +1776,8 @@ def _receiveUndoAnnounce(recentPostsCache: {},
|
|||
try:
|
||||
os.remove(postFilename)
|
||||
except BaseException:
|
||||
print('EX: _receiveUndoAnnounce unable to delete ' +
|
||||
str(postFilename))
|
||||
pass
|
||||
return True
|
||||
|
||||
|
|
@ -2113,14 +2119,14 @@ def _likeNotify(baseDir: str, domain: str, onionDomain: str,
|
|||
with open(prevLikeFile, 'w+') as fp:
|
||||
fp.write(likeStr)
|
||||
except BaseException:
|
||||
print('ERROR: unable to save previous like notification ' +
|
||||
print('EX: ERROR: unable to save previous like notification ' +
|
||||
prevLikeFile)
|
||||
pass
|
||||
try:
|
||||
with open(likeFile, 'w+') as fp:
|
||||
fp.write(likeStr)
|
||||
except BaseException:
|
||||
print('ERROR: unable to write like notification file ' +
|
||||
print('EX: ERROR: unable to write like notification file ' +
|
||||
likeFile)
|
||||
pass
|
||||
|
||||
|
|
@ -2939,7 +2945,7 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
|
|||
print('ERROR: unable to update ' + boxname + ' index')
|
||||
else:
|
||||
if boxname == 'inbox':
|
||||
if isRecentPost(postJsonObject):
|
||||
if isRecentPost(postJsonObject, 3):
|
||||
domainFull = getFullDomain(domain, port)
|
||||
updateSpeaker(baseDir, httpPrefix,
|
||||
nickname, domain, domainFull,
|
||||
|
|
@ -3036,6 +3042,7 @@ def clearQueueItems(baseDir: str, queue: []) -> None:
|
|||
os.remove(os.path.join(queueDir, qfile))
|
||||
ctr += 1
|
||||
except BaseException:
|
||||
print('EX: clearQueueItems unable to delete ' + qfile)
|
||||
pass
|
||||
break
|
||||
break
|
||||
|
|
@ -3102,6 +3109,8 @@ def _inboxQuotaExceeded(queue: {}, queueFilename: str,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: _inboxQuotaExceeded unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
queue.pop(0)
|
||||
return True
|
||||
|
|
@ -3123,6 +3132,8 @@ def _inboxQuotaExceeded(queue: {}, queueFilename: str,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: _inboxQuotaExceeded unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
queue.pop(0)
|
||||
return True
|
||||
|
|
@ -3143,6 +3154,8 @@ def _inboxQuotaExceeded(queue: {}, queueFilename: str,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: _inboxQuotaExceeded unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
queue.pop(0)
|
||||
return True
|
||||
|
|
@ -3165,6 +3178,8 @@ def _inboxQuotaExceeded(queue: {}, queueFilename: str,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: _inboxQuotaExceeded unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
queue.pop(0)
|
||||
return True
|
||||
|
|
@ -3348,6 +3363,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: runInboxQueue 1 unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
continue
|
||||
|
||||
|
|
@ -3421,6 +3438,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: runInboxQueue 2 unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
if len(queue) > 0:
|
||||
queue.pop(0)
|
||||
|
|
@ -3472,6 +3491,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: runInboxQueue 3 unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
if len(queue) > 0:
|
||||
queue.pop(0)
|
||||
|
|
@ -3492,6 +3513,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: runInboxQueue 4 unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
if len(queue) > 0:
|
||||
queue.pop(0)
|
||||
|
|
@ -3521,6 +3544,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: runInboxQueue 5 unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
if len(queue) > 0:
|
||||
queue.pop(0)
|
||||
|
|
@ -3542,6 +3567,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: runInboxQueue 6 unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
if len(queue) > 0:
|
||||
queue.pop(0)
|
||||
|
|
@ -3563,6 +3590,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: runInboxQueue 7 unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
if len(queue) > 0:
|
||||
queue.pop(0)
|
||||
|
|
@ -3584,6 +3613,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: runInboxQueue 8 unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
if len(queue) > 0:
|
||||
queue.pop(0)
|
||||
|
|
@ -3602,6 +3633,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: runInboxQueue 9 unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
if len(queue) > 0:
|
||||
queue.pop(0)
|
||||
|
|
@ -3680,6 +3713,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
|
|||
try:
|
||||
os.remove(queueFilename)
|
||||
except BaseException:
|
||||
print('EX: runInboxQueue 10 unable to delete ' +
|
||||
str(queueFilename))
|
||||
pass
|
||||
if len(queue) > 0:
|
||||
queue.pop(0)
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ def libretranslate(url: str, text: str,
|
|||
try:
|
||||
response = request.urlopen(req)
|
||||
except BaseException:
|
||||
print('Unable to translate: ' + text)
|
||||
print('EX: Unable to translate: ' + text)
|
||||
return originalText
|
||||
|
||||
response_str = response.read().decode()
|
||||
|
|
|
|||
2
like.py
2
like.py
|
|
@ -431,6 +431,8 @@ def updateLikesCollection(recentPostsCache: {},
|
|||
try:
|
||||
os.remove(cachedPostFilename)
|
||||
except BaseException:
|
||||
print('EX: updateLikesCollection unable to delete ' +
|
||||
cachedPostFilename)
|
||||
pass
|
||||
|
||||
obj = postJsonObject
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ def verifyJsonSignature(doc: {}, publicKeyPem: str) -> bool:
|
|||
hazutils.Prehashed(hashes.SHA256()))
|
||||
return True
|
||||
except BaseException:
|
||||
print('EX: verifyJsonSignature unable to verify')
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -255,11 +255,15 @@ def manualApproveFollowRequest(session, baseDir: str,
|
|||
try:
|
||||
os.remove(followActivityfilename)
|
||||
except BaseException:
|
||||
print('EX: manualApproveFollowRequest unable to delete ' +
|
||||
followActivityfilename)
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
os.remove(approveFollowsFilename + '.new')
|
||||
except BaseException:
|
||||
print('EX: manualApproveFollowRequest unable to delete ' +
|
||||
approveFollowsFilename + '.new')
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
|||
15
media.py
15
media.py
|
|
@ -126,6 +126,7 @@ def _spoofMetaData(baseDir: str, nickname: str, domain: str,
|
|||
with open(decoySeedFilename, 'w+') as fp:
|
||||
fp.write(str(decoySeed))
|
||||
except BaseException:
|
||||
print('EX: unable to write ' + decoySeedFilename)
|
||||
pass
|
||||
|
||||
if os.path.isfile('/usr/bin/exiftool'):
|
||||
|
|
@ -166,6 +167,8 @@ def convertImageToLowBandwidth(imageFilename: str) -> None:
|
|||
try:
|
||||
os.remove(lowBandwidthFilename)
|
||||
except BaseException:
|
||||
print('EX: convertImageToLowBandwidth unable to delete ' +
|
||||
lowBandwidthFilename)
|
||||
pass
|
||||
|
||||
cmd = \
|
||||
|
|
@ -187,6 +190,8 @@ def convertImageToLowBandwidth(imageFilename: str) -> None:
|
|||
try:
|
||||
os.remove(imageFilename)
|
||||
except BaseException:
|
||||
print('EX: convertImageToLowBandwidth unable to delete ' +
|
||||
imageFilename)
|
||||
pass
|
||||
os.rename(lowBandwidthFilename, imageFilename)
|
||||
if os.path.isfile(imageFilename):
|
||||
|
|
@ -273,6 +278,7 @@ def _updateEtag(mediaFilename: str) -> None:
|
|||
with open(mediaFilename, 'rb') as mediaFile:
|
||||
data = mediaFile.read()
|
||||
except BaseException:
|
||||
print('EX: _updateEtag unable to read ' + str(mediaFilename))
|
||||
pass
|
||||
|
||||
if not data:
|
||||
|
|
@ -284,6 +290,8 @@ def _updateEtag(mediaFilename: str) -> None:
|
|||
with open(mediaFilename + '.etag', 'w+') as etagFile:
|
||||
etagFile.write(etag)
|
||||
except BaseException:
|
||||
print('EX: _updateEtag unable to write ' +
|
||||
str(mediaFilename) + '.etag')
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -357,8 +365,7 @@ def attachMedia(baseDir: str, httpPrefix: str,
|
|||
return postJson
|
||||
|
||||
|
||||
def archiveMedia(baseDir: str, archiveDirectory: str,
|
||||
maxWeeks: int = 4) -> None:
|
||||
def archiveMedia(baseDir: str, archiveDirectory: str, maxWeeks: int) -> None:
|
||||
"""Any media older than the given number of weeks gets archived
|
||||
"""
|
||||
if maxWeeks == 0:
|
||||
|
|
@ -382,7 +389,8 @@ def archiveMedia(baseDir: str, archiveDirectory: str,
|
|||
archiveDirectory + '/media')
|
||||
else:
|
||||
# archive to /dev/null
|
||||
rmtree(os.path.join(baseDir + '/media', weekDir))
|
||||
rmtree(os.path.join(baseDir + '/media', weekDir),
|
||||
ignore_errors=False, onerror=None)
|
||||
break
|
||||
|
||||
|
||||
|
|
@ -407,6 +415,7 @@ def getImageDimensions(imageFilename: str) -> (int, int):
|
|||
result = subprocess.run(['identify', '-format', '"%wx%h"',
|
||||
imageFilename], stdout=subprocess.PIPE)
|
||||
except BaseException:
|
||||
print('EX: getImageDimensions unable to run identify command')
|
||||
return None, None
|
||||
if not result:
|
||||
return None, None
|
||||
|
|
|
|||
|
|
@ -471,7 +471,7 @@ def _createNewsMirror(baseDir: str, domain: str,
|
|||
postId = postId.strip()
|
||||
mirrorArticleDir = mirrorDir + '/' + postId
|
||||
if os.path.isdir(mirrorArticleDir):
|
||||
rmtree(mirrorArticleDir)
|
||||
rmtree(mirrorArticleDir, ignore_errors=False, onerror=None)
|
||||
removals.append(postId)
|
||||
noOfDirs -= 1
|
||||
|
||||
|
|
@ -555,12 +555,12 @@ def _convertRSStoActivityPub(baseDir: str, httpPrefix: str,
|
|||
dateStrWithOffset = \
|
||||
datetime.datetime.strptime(dateStr, "%Y-%m-%d %H:%M:%S%z")
|
||||
except BaseException:
|
||||
print('Newswire strptime failed ' + str(dateStr))
|
||||
print('EX: Newswire strptime failed ' + str(dateStr))
|
||||
continue
|
||||
try:
|
||||
dateStr = dateStrWithOffset.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
except BaseException:
|
||||
print('Newswire dateStrWithOffset failed ' +
|
||||
print('EX: Newswire dateStrWithOffset failed ' +
|
||||
str(dateStrWithOffset))
|
||||
continue
|
||||
|
||||
|
|
@ -726,6 +726,8 @@ def _convertRSStoActivityPub(baseDir: str, httpPrefix: str,
|
|||
try:
|
||||
os.remove(filename + '.arrived')
|
||||
except BaseException:
|
||||
print('EX: _convertRSStoActivityPub ' +
|
||||
'unable to delete ' + filename + '.arrived')
|
||||
pass
|
||||
|
||||
# setting the url here links to the activitypub object
|
||||
|
|
@ -839,6 +841,8 @@ def runNewswireDaemon(baseDir: str, httpd,
|
|||
try:
|
||||
os.remove(refreshFilename)
|
||||
except BaseException:
|
||||
print('EX: runNewswireDaemon unable to delete ' +
|
||||
str(refreshFilename))
|
||||
pass
|
||||
break
|
||||
|
||||
|
|
|
|||
21
newswire.py
21
newswire.py
|
|
@ -132,8 +132,8 @@ def _addNewswireDictEntry(baseDir: str, domain: str,
|
|||
votesStatus: str, postFilename: str,
|
||||
description: str, moderated: bool,
|
||||
mirrored: bool,
|
||||
tags: [] = [],
|
||||
maxTags: int = 32) -> None:
|
||||
tags: [],
|
||||
maxTags: int) -> None:
|
||||
"""Update the newswire dictionary
|
||||
"""
|
||||
# remove any markup
|
||||
|
|
@ -229,8 +229,7 @@ def parseFeedDate(pubDate: str) -> str:
|
|||
continue
|
||||
|
||||
try:
|
||||
publishedDate = \
|
||||
datetime.strptime(pubDate, dateFormat)
|
||||
publishedDate = datetime.strptime(pubDate, dateFormat)
|
||||
except BaseException:
|
||||
continue
|
||||
|
||||
|
|
@ -384,7 +383,7 @@ def _xml2StrToDict(baseDir: str, domain: str, xmlStr: str,
|
|||
title, link,
|
||||
votesStatus, postFilename,
|
||||
description, moderated,
|
||||
mirrored)
|
||||
mirrored, [], 32)
|
||||
postCtr += 1
|
||||
if postCtr >= maxPostsPerSource:
|
||||
break
|
||||
|
|
@ -471,7 +470,7 @@ def _xml1StrToDict(baseDir: str, domain: str, xmlStr: str,
|
|||
title, link,
|
||||
votesStatus, postFilename,
|
||||
description, moderated,
|
||||
mirrored)
|
||||
mirrored, [], 32)
|
||||
postCtr += 1
|
||||
if postCtr >= maxPostsPerSource:
|
||||
break
|
||||
|
|
@ -546,7 +545,7 @@ def _atomFeedToDict(baseDir: str, domain: str, xmlStr: str,
|
|||
title, link,
|
||||
votesStatus, postFilename,
|
||||
description, moderated,
|
||||
mirrored)
|
||||
mirrored, [], 32)
|
||||
postCtr += 1
|
||||
if postCtr >= maxPostsPerSource:
|
||||
break
|
||||
|
|
@ -568,6 +567,7 @@ def _jsonFeedV1ToDict(baseDir: str, domain: str, xmlStr: str,
|
|||
try:
|
||||
feedJson = json.loads(xmlStr)
|
||||
except BaseException:
|
||||
print('EX: _jsonFeedV1ToDict unable to load json ' + str(xmlStr))
|
||||
return {}
|
||||
maxBytes = maxFeedItemSizeKb * 1024
|
||||
if not feedJson.get('version'):
|
||||
|
|
@ -656,7 +656,7 @@ def _jsonFeedV1ToDict(baseDir: str, domain: str, xmlStr: str,
|
|||
title, link,
|
||||
votesStatus, postFilename,
|
||||
description, moderated,
|
||||
mirrored)
|
||||
mirrored, [], 32)
|
||||
postCtr += 1
|
||||
if postCtr >= maxPostsPerSource:
|
||||
break
|
||||
|
|
@ -727,7 +727,8 @@ def _atomFeedYTToDict(baseDir: str, domain: str, xmlStr: str,
|
|||
result, pubDateStr,
|
||||
title, link,
|
||||
votesStatus, postFilename,
|
||||
description, moderated, mirrored)
|
||||
description, moderated, mirrored,
|
||||
[], 32)
|
||||
postCtr += 1
|
||||
if postCtr >= maxPostsPerSource:
|
||||
break
|
||||
|
|
@ -1045,6 +1046,8 @@ def _addBlogsToNewswire(baseDir: str, domain: str, newswire: {},
|
|||
try:
|
||||
os.remove(newswireModerationFilename)
|
||||
except BaseException:
|
||||
print('EX: _addBlogsToNewswire unable to delete ' +
|
||||
str(newswireModerationFilename))
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -397,6 +397,8 @@ def postMessageToOutbox(session, translate: {},
|
|||
try:
|
||||
os.remove(citationsFilename)
|
||||
except BaseException:
|
||||
print('EX: postMessageToOutbox unable to delete ' +
|
||||
citationsFilename)
|
||||
pass
|
||||
|
||||
# The following activity types get added to the index files
|
||||
|
|
|
|||
40
person.py
40
person.py
|
|
@ -11,6 +11,7 @@ import time
|
|||
import os
|
||||
import subprocess
|
||||
import shutil
|
||||
import datetime
|
||||
import pyqrcode
|
||||
from random import randint
|
||||
from pathlib import Path
|
||||
|
|
@ -894,6 +895,8 @@ def personBoxJson(recentPostsCache: {},
|
|||
try:
|
||||
pageNumber = int(pageNumber)
|
||||
except BaseException:
|
||||
print('EX: personBoxJson unable to convert to int ' +
|
||||
str(pageNumber))
|
||||
pass
|
||||
path = path.split('?page=')[0]
|
||||
headerOnly = False
|
||||
|
|
@ -1034,12 +1037,14 @@ def suspendAccount(baseDir: str, nickname: str, domain: str) -> None:
|
|||
try:
|
||||
os.remove(saltFilename)
|
||||
except BaseException:
|
||||
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:
|
||||
print('EX: suspendAccount unable to delete ' + tokenFilename)
|
||||
pass
|
||||
|
||||
suspendedFilename = baseDir + '/accounts/suspended.txt'
|
||||
|
|
@ -1100,6 +1105,8 @@ def _removeTagsForNickname(baseDir: str, nickname: str,
|
|||
try:
|
||||
tagFilename = os.path.join(directory, filename)
|
||||
except BaseException:
|
||||
print('EX: _removeTagsForNickname unable to join ' +
|
||||
str(directory) + ' ' + str(filename))
|
||||
continue
|
||||
if not os.path.isfile(tagFilename):
|
||||
continue
|
||||
|
|
@ -1139,38 +1146,52 @@ def removeAccount(baseDir: str, nickname: str,
|
|||
removePassword(baseDir, nickname)
|
||||
_removeTagsForNickname(baseDir, nickname, domain, port)
|
||||
if os.path.isdir(baseDir + '/deactivated/' + handle):
|
||||
shutil.rmtree(baseDir + '/deactivated/' + handle)
|
||||
shutil.rmtree(baseDir + '/deactivated/' + handle,
|
||||
ignore_errors=False, onerror=None)
|
||||
if os.path.isdir(baseDir + '/accounts/' + handle):
|
||||
shutil.rmtree(baseDir + '/accounts/' + handle)
|
||||
shutil.rmtree(baseDir + '/accounts/' + handle,
|
||||
ignore_errors=False, onerror=None)
|
||||
if os.path.isfile(baseDir + '/accounts/' + handle + '.json'):
|
||||
try:
|
||||
os.remove(baseDir + '/accounts/' + handle + '.json')
|
||||
except BaseException:
|
||||
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:
|
||||
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:
|
||||
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:
|
||||
print('EX: removeAccount unable to delete ' +
|
||||
baseDir + '/keys/public/' + handle + '.pem')
|
||||
pass
|
||||
if os.path.isdir(baseDir + '/sharefiles/' + nickname):
|
||||
shutil.rmtree(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:
|
||||
print('EX: removeAccount unable to delete ' +
|
||||
baseDir + '/wfdeactivated/' + handle + '.json')
|
||||
pass
|
||||
if os.path.isdir(baseDir + '/sharefilesdeactivated/' + nickname):
|
||||
shutil.rmtree(baseDir + '/sharefilesdeactivated/' + nickname)
|
||||
shutil.rmtree(baseDir + '/sharefilesdeactivated/' + nickname,
|
||||
ignore_errors=False, onerror=None)
|
||||
|
||||
refreshNewswire(baseDir)
|
||||
|
||||
|
|
@ -1559,3 +1580,14 @@ def getPersonAvatarUrl(baseDir: str, personUrl: str, personCache: {},
|
|||
if '.svg' not in personJson['icon']['url'].lower():
|
||||
return personJson['icon']['url']
|
||||
return None
|
||||
|
||||
|
||||
def addActorUpdateTimestamp(actorJson: {}) -> None:
|
||||
"""Adds 'updated' fields with a timestamp
|
||||
"""
|
||||
updatedTime = datetime.datetime.utcnow()
|
||||
currDateStr = updatedTime.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
actorJson['updated'] = currDateStr
|
||||
# add updated timestamp to avatar and banner
|
||||
actorJson['icon']['updated'] = currDateStr
|
||||
actorJson['image']['updated'] = currDateStr
|
||||
|
|
|
|||
46
posts.py
46
posts.py
|
|
@ -196,7 +196,7 @@ def _cleanHtml(rawHtml: str) -> str:
|
|||
return html.unescape(text)
|
||||
|
||||
|
||||
def getUserUrl(wfRequest: {}, sourceId: int = 0, debug: bool = False) -> str:
|
||||
def getUserUrl(wfRequest: {}, sourceId: int, debug: bool) -> str:
|
||||
"""Gets the actor url from a webfinger request
|
||||
"""
|
||||
if not wfRequest.get('links'):
|
||||
|
|
@ -893,7 +893,7 @@ def deleteAllPosts(baseDir: str,
|
|||
if os.path.isfile(filePath):
|
||||
os.unlink(filePath)
|
||||
elif os.path.isdir(filePath):
|
||||
shutil.rmtree(filePath)
|
||||
shutil.rmtree(filePath, ignore_errors=False, onerror=None)
|
||||
except Exception as e:
|
||||
print('ERROR: deleteAllPosts ' + str(e))
|
||||
|
||||
|
|
@ -1569,6 +1569,7 @@ def undoPinnedPost(baseDir: str, nickname: str, domain: str) -> None:
|
|||
try:
|
||||
os.remove(pinnedFilename)
|
||||
except BaseException:
|
||||
print('EX: undoPinnedPost unable to delete ' + pinnedFilename)
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -2094,6 +2095,7 @@ def createReportPost(baseDir: str,
|
|||
with open(newReportFile, 'w+') as fp:
|
||||
fp.write(toUrl + '/moderation')
|
||||
except BaseException:
|
||||
print('EX: createReportPost unable to write ' + newReportFile)
|
||||
pass
|
||||
|
||||
return postJsonObject
|
||||
|
|
@ -2534,7 +2536,7 @@ def sendSignedJson(postJsonObject: {}, session, baseDir: str,
|
|||
toDomain = getFullDomain(toDomain, toPort)
|
||||
|
||||
toDomainUrl = httpPrefix + '://' + toDomain
|
||||
if not siteIsActive(toDomainUrl):
|
||||
if not siteIsActive(toDomainUrl, 10):
|
||||
print('Domain is inactive: ' + toDomainUrl)
|
||||
return 9
|
||||
print('Domain is active: ' + toDomainUrl)
|
||||
|
|
@ -3041,7 +3043,7 @@ def sendToFollowers(session, baseDir: str,
|
|||
|
||||
# check that the follower's domain is active
|
||||
followerDomainUrl = httpPrefix + '://' + followerDomain
|
||||
if not siteIsActive(followerDomainUrl):
|
||||
if not siteIsActive(followerDomainUrl, 10):
|
||||
print('Sending post to followers domain is inactive: ' +
|
||||
followerDomainUrl)
|
||||
continue
|
||||
|
|
@ -3195,7 +3197,7 @@ def sendToFollowersThread(session, baseDir: str,
|
|||
def createInbox(recentPostsCache: {},
|
||||
session, baseDir: str, nickname: str, domain: str, port: int,
|
||||
httpPrefix: str, itemsPerPage: int, headerOnly: bool,
|
||||
pageNumber: int = None) -> {}:
|
||||
pageNumber: int) -> {}:
|
||||
return _createBoxIndexed(recentPostsCache,
|
||||
session, baseDir, 'inbox',
|
||||
nickname, domain, port, httpPrefix,
|
||||
|
|
@ -3205,7 +3207,7 @@ def createInbox(recentPostsCache: {},
|
|||
|
||||
def createBookmarksTimeline(session, baseDir: str, nickname: str, domain: str,
|
||||
port: int, httpPrefix: str, itemsPerPage: int,
|
||||
headerOnly: bool, pageNumber: int = None) -> {}:
|
||||
headerOnly: bool, pageNumber: int) -> {}:
|
||||
return _createBoxIndexed({}, session, baseDir, 'tlbookmarks',
|
||||
nickname, domain,
|
||||
port, httpPrefix, itemsPerPage, headerOnly,
|
||||
|
|
@ -3215,7 +3217,7 @@ def createBookmarksTimeline(session, baseDir: str, nickname: str, domain: str,
|
|||
def createDMTimeline(recentPostsCache: {},
|
||||
session, baseDir: str, nickname: str, domain: str,
|
||||
port: int, httpPrefix: str, itemsPerPage: int,
|
||||
headerOnly: bool, pageNumber: int = None) -> {}:
|
||||
headerOnly: bool, pageNumber: int) -> {}:
|
||||
return _createBoxIndexed(recentPostsCache,
|
||||
session, baseDir, 'dm', nickname,
|
||||
domain, port, httpPrefix, itemsPerPage,
|
||||
|
|
@ -3225,7 +3227,7 @@ def createDMTimeline(recentPostsCache: {},
|
|||
def createRepliesTimeline(recentPostsCache: {},
|
||||
session, baseDir: str, nickname: str, domain: str,
|
||||
port: int, httpPrefix: str, itemsPerPage: int,
|
||||
headerOnly: bool, pageNumber: int = None) -> {}:
|
||||
headerOnly: bool, pageNumber: int) -> {}:
|
||||
return _createBoxIndexed(recentPostsCache, session, baseDir, 'tlreplies',
|
||||
nickname, domain, port, httpPrefix,
|
||||
itemsPerPage, headerOnly, True,
|
||||
|
|
@ -3234,7 +3236,7 @@ def createRepliesTimeline(recentPostsCache: {},
|
|||
|
||||
def createBlogsTimeline(session, baseDir: str, nickname: str, domain: str,
|
||||
port: int, httpPrefix: str, itemsPerPage: int,
|
||||
headerOnly: bool, pageNumber: int = None) -> {}:
|
||||
headerOnly: bool, pageNumber: int) -> {}:
|
||||
return _createBoxIndexed({}, session, baseDir, 'tlblogs', nickname,
|
||||
domain, port, httpPrefix,
|
||||
itemsPerPage, headerOnly, True,
|
||||
|
|
@ -3243,7 +3245,7 @@ def createBlogsTimeline(session, baseDir: str, nickname: str, domain: str,
|
|||
|
||||
def createFeaturesTimeline(session, baseDir: str, nickname: str, domain: str,
|
||||
port: int, httpPrefix: str, itemsPerPage: int,
|
||||
headerOnly: bool, pageNumber: int = None) -> {}:
|
||||
headerOnly: bool, pageNumber: int) -> {}:
|
||||
return _createBoxIndexed({}, session, baseDir, 'tlfeatures', nickname,
|
||||
domain, port, httpPrefix,
|
||||
itemsPerPage, headerOnly, True,
|
||||
|
|
@ -3252,7 +3254,7 @@ def createFeaturesTimeline(session, baseDir: str, nickname: str, domain: str,
|
|||
|
||||
def createMediaTimeline(session, baseDir: str, nickname: str, domain: str,
|
||||
port: int, httpPrefix: str, itemsPerPage: int,
|
||||
headerOnly: bool, pageNumber: int = None) -> {}:
|
||||
headerOnly: bool, pageNumber: int) -> {}:
|
||||
return _createBoxIndexed({}, session, baseDir, 'tlmedia', nickname,
|
||||
domain, port, httpPrefix,
|
||||
itemsPerPage, headerOnly, True,
|
||||
|
|
@ -3263,7 +3265,7 @@ def createNewsTimeline(session, baseDir: str, nickname: str, domain: str,
|
|||
port: int, httpPrefix: str, itemsPerPage: int,
|
||||
headerOnly: bool, newswireVotesThreshold: int,
|
||||
positiveVoting: bool, votingTimeMins: int,
|
||||
pageNumber: int = None) -> {}:
|
||||
pageNumber: int) -> {}:
|
||||
return _createBoxIndexed({}, session, baseDir, 'outbox', 'news',
|
||||
domain, port, httpPrefix,
|
||||
itemsPerPage, headerOnly, True,
|
||||
|
|
@ -3274,7 +3276,7 @@ def createNewsTimeline(session, baseDir: str, nickname: str, domain: str,
|
|||
def createOutbox(session, baseDir: str, nickname: str, domain: str,
|
||||
port: int, httpPrefix: str,
|
||||
itemsPerPage: int, headerOnly: bool, authorized: bool,
|
||||
pageNumber: int = None) -> {}:
|
||||
pageNumber: int) -> {}:
|
||||
return _createBoxIndexed({}, session, baseDir, 'outbox',
|
||||
nickname, domain, port, httpPrefix,
|
||||
itemsPerPage, headerOnly, authorized,
|
||||
|
|
@ -3283,7 +3285,7 @@ def createOutbox(session, baseDir: str, nickname: str, domain: str,
|
|||
|
||||
def createModeration(baseDir: str, nickname: str, domain: str, port: int,
|
||||
httpPrefix: str, itemsPerPage: int, headerOnly: bool,
|
||||
pageNumber: int = None) -> {}:
|
||||
pageNumber: int) -> {}:
|
||||
boxDir = createPersonDir(nickname, domain, baseDir, 'inbox')
|
||||
boxname = 'moderation'
|
||||
|
||||
|
|
@ -3545,7 +3547,7 @@ def _createBoxIndexed(recentPostsCache: {},
|
|||
nickname: str, domain: str, port: int, httpPrefix: str,
|
||||
itemsPerPage: int, headerOnly: bool, authorized: bool,
|
||||
newswireVotesThreshold: int, positiveVoting: bool,
|
||||
votingTimeMins: int, pageNumber: int = None) -> {}:
|
||||
votingTimeMins: int, pageNumber: int) -> {}:
|
||||
"""Constructs the box feed for a person with the given nickname
|
||||
"""
|
||||
if not authorized or not pageNumber:
|
||||
|
|
@ -3584,6 +3586,8 @@ def _createBoxIndexed(recentPostsCache: {},
|
|||
try:
|
||||
pageStr = '?page=' + str(pageNumber)
|
||||
except BaseException:
|
||||
print('EX: _createBoxIndexed ' +
|
||||
'unable to convert page number to string')
|
||||
pass
|
||||
boxUrl = localActorUrl(httpPrefix, nickname, domain) + '/' + boxname
|
||||
boxHeader = {
|
||||
|
|
@ -3743,6 +3747,7 @@ def _createBoxIndexed(recentPostsCache: {},
|
|||
try:
|
||||
p = json.loads(postStr)
|
||||
except BaseException:
|
||||
print('EX: _createBoxIndexed unable to load json ' + postStr)
|
||||
continue
|
||||
|
||||
# Does this post have replies?
|
||||
|
|
@ -3925,6 +3930,8 @@ def archivePostsForPerson(httpPrefix: str, nickname: str, domain: str,
|
|||
try:
|
||||
os.remove(postCacheFilename)
|
||||
except BaseException:
|
||||
print('EX: archivePostsForPerson unable to delete ' +
|
||||
postCacheFilename)
|
||||
pass
|
||||
|
||||
noOfPosts -= 1
|
||||
|
|
@ -4065,8 +4072,8 @@ def getPublicPostDomains(session, baseDir: str, nickname: str, domain: str,
|
|||
def downloadFollowCollection(signingPrivateKeyPem: str,
|
||||
followType: str,
|
||||
session, httpPrefix: str,
|
||||
actor: str, pageNumber: int = 1,
|
||||
noOfPages: int = 1, debug: bool = False) -> []:
|
||||
actor: str, pageNumber: int,
|
||||
noOfPages: int, debug: bool) -> []:
|
||||
"""Returns a list of following/followers for the given actor
|
||||
by downloading the json for their following/followers collection
|
||||
"""
|
||||
|
|
@ -5037,11 +5044,15 @@ def secondsBetweenPublished(published1: str, published2: str) -> int:
|
|||
published1Time = \
|
||||
datetime.datetime.strptime(published1, '%Y-%m-%dT%H:%M:%SZ')
|
||||
except BaseException:
|
||||
print('EX: secondsBetweenPublished unable to parse date 1 ' +
|
||||
str(published1))
|
||||
return -1
|
||||
try:
|
||||
published2Time = \
|
||||
datetime.datetime.strptime(published2, '%Y-%m-%dT%H:%M:%SZ')
|
||||
except BaseException:
|
||||
print('EX: secondsBetweenPublished unable to parse date 2 ' +
|
||||
str(published2))
|
||||
return -1
|
||||
return (published2Time - published1Time).seconds
|
||||
|
||||
|
|
@ -5079,6 +5090,7 @@ def editedPostFilename(baseDir: str, nickname: str, domain: str,
|
|||
with open(actorFilename, 'r') as fp:
|
||||
lastpostId = fp.read()
|
||||
except BaseException:
|
||||
print('EX: editedPostFilename unable to read ' + actorFilename)
|
||||
return ''
|
||||
if not lastpostId:
|
||||
return ''
|
||||
|
|
|
|||
21
schedule.py
21
schedule.py
|
|
@ -49,6 +49,8 @@ def _updatePostSchedule(baseDir: str, handle: str, httpd,
|
|||
try:
|
||||
os.remove(postFilename)
|
||||
except BaseException:
|
||||
print('EX: _updatePostSchedule unable to delete ' +
|
||||
str(postFilename))
|
||||
pass
|
||||
continue
|
||||
# create the new index file
|
||||
|
|
@ -131,6 +133,8 @@ def _updatePostSchedule(baseDir: str, handle: str, httpd,
|
|||
try:
|
||||
os.remove(postFilename)
|
||||
except BaseException:
|
||||
print('EX: _updatePostSchedule unable to delete ' +
|
||||
str(postFilename))
|
||||
pass
|
||||
continue
|
||||
|
||||
|
|
@ -202,6 +206,8 @@ def removeScheduledPosts(baseDir: str, nickname: str, domain: str) -> None:
|
|||
try:
|
||||
os.remove(scheduleIndexFilename)
|
||||
except BaseException:
|
||||
print('EX: removeScheduledPosts unable to delete ' +
|
||||
scheduleIndexFilename)
|
||||
pass
|
||||
# remove the scheduled posts
|
||||
scheduledDir = acctDir(baseDir, nickname, domain) + '/scheduled'
|
||||
|
|
@ -209,11 +215,10 @@ def removeScheduledPosts(baseDir: str, nickname: str, domain: str) -> None:
|
|||
return
|
||||
for scheduledPostFilename in os.listdir(scheduledDir):
|
||||
filePath = os.path.join(scheduledDir, scheduledPostFilename)
|
||||
try:
|
||||
if os.path.isfile(filePath):
|
||||
try:
|
||||
os.remove(filePath)
|
||||
except BaseException:
|
||||
pass
|
||||
except BaseException:
|
||||
pass
|
||||
if os.path.isfile(filePath):
|
||||
try:
|
||||
os.remove(filePath)
|
||||
except BaseException:
|
||||
print('EX: removeScheduledPosts unable to delete ' +
|
||||
filePath)
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ def urlExists(session, url: str, timeoutSec: int = 3,
|
|||
print('urlExists for ' + url + ' returned ' +
|
||||
str(result.status_code))
|
||||
except BaseException:
|
||||
print('EX: urlExists GET failed ' + str(url))
|
||||
pass
|
||||
return False
|
||||
|
||||
|
|
|
|||
14
shares.py
14
shares.py
|
|
@ -149,6 +149,8 @@ def removeSharedItem(baseDir: str, nickname: str, domain: str,
|
|||
try:
|
||||
os.remove(itemIDfile + '.' + ext)
|
||||
except BaseException:
|
||||
print('EX: removeSharedItem unable to delete ' +
|
||||
itemIDfile + '.' + ext)
|
||||
pass
|
||||
# remove the item itself
|
||||
del sharesJson[itemID]
|
||||
|
|
@ -293,6 +295,8 @@ def _indicateNewShareAvailable(baseDir: str, httpPrefix: str,
|
|||
else:
|
||||
fp.write(localActor + '/tlwanted')
|
||||
except BaseException:
|
||||
print('EX: _indicateNewShareAvailable unable to write ' +
|
||||
str(newShareFile))
|
||||
pass
|
||||
break
|
||||
|
||||
|
|
@ -364,6 +368,8 @@ def addShare(baseDir: str,
|
|||
try:
|
||||
os.remove(imageFilename)
|
||||
except BaseException:
|
||||
print('EX: addShare unable to delete ' +
|
||||
str(imageFilename))
|
||||
pass
|
||||
imageUrl = \
|
||||
httpPrefix + '://' + domainFull + \
|
||||
|
|
@ -436,6 +442,8 @@ def _expireSharesForAccount(baseDir: str, nickname: str, domain: str,
|
|||
try:
|
||||
os.remove(itemIDfile + '.' + ext)
|
||||
except BaseException:
|
||||
print('EX: _expireSharesForAccount unable to delete ' +
|
||||
itemIDfile + '.' + ext)
|
||||
pass
|
||||
saveJson(sharesJson, sharesFilename)
|
||||
|
||||
|
|
@ -444,7 +452,7 @@ def getSharesFeedForPerson(baseDir: str,
|
|||
domain: str, port: int,
|
||||
path: str, httpPrefix: str,
|
||||
sharesFileType: str,
|
||||
sharesPerPage: int = 12) -> {}:
|
||||
sharesPerPage: int) -> {}:
|
||||
"""Returns the shares for an account from GET requests
|
||||
"""
|
||||
if '/' + sharesFileType not in path:
|
||||
|
|
@ -460,6 +468,8 @@ def getSharesFeedForPerson(baseDir: str,
|
|||
try:
|
||||
pageNumber = int(pageNumber)
|
||||
except BaseException:
|
||||
print('EX: getSharesFeedForPerson unable to convert to int ' +
|
||||
str(pageNumber))
|
||||
pass
|
||||
path = path.split('?page=')[0]
|
||||
headerOnly = False
|
||||
|
|
@ -1564,7 +1574,7 @@ def _updateFederatedSharesCache(session, sharedItemsFederatedDomains: [],
|
|||
if not tokensJson.get(federatedDomainFull):
|
||||
# token has been obtained for the other domain
|
||||
continue
|
||||
if not siteIsActive(httpPrefix + '://' + federatedDomainFull):
|
||||
if not siteIsActive(httpPrefix + '://' + federatedDomainFull, 10):
|
||||
continue
|
||||
if sharesFileType == 'shares':
|
||||
url = httpPrefix + '://' + federatedDomainFull + '/catalog'
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ def _siteActiveHttpRequest(loc, timeout: int):
|
|||
return result
|
||||
|
||||
|
||||
def siteIsActive(url: str, timeout: int = 10) -> bool:
|
||||
def siteIsActive(url: str, timeout: int) -> bool:
|
||||
"""Returns true if the current url is resolvable.
|
||||
This can be used to check that an instance is online before
|
||||
trying to send posts to it.
|
||||
|
|
@ -118,5 +118,6 @@ def siteIsActive(url: str, timeout: int = 10) -> bool:
|
|||
return True
|
||||
|
||||
except BaseException:
|
||||
print('EX: siteIsActive ' + str(loc))
|
||||
pass
|
||||
return False
|
||||
|
|
|
|||
85
tests.py
85
tests.py
|
|
@ -245,7 +245,7 @@ def _testHttpSignedGET(baseDir: str):
|
|||
|
||||
path = baseDir + '/.testHttpsigGET'
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
shutil.rmtree(path, ignore_errors=False, onerror=None)
|
||||
os.mkdir(path)
|
||||
os.chdir(path)
|
||||
|
||||
|
|
@ -290,7 +290,7 @@ def _testHttpSignedGET(baseDir: str):
|
|||
boxpath, GETmethod, None,
|
||||
messageBodyJsonStr, debug, noRecencyCheck)
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
shutil.rmtree(path, ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def _testSignAndVerify() -> None:
|
||||
|
|
@ -561,7 +561,7 @@ def _testHttpsigBase(withDigest: bool, baseDir: str):
|
|||
|
||||
path = baseDir + '/.testHttpsigBase'
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
shutil.rmtree(path, ignore_errors=False, onerror=None)
|
||||
os.mkdir(path)
|
||||
os.chdir(path)
|
||||
|
||||
|
|
@ -662,7 +662,7 @@ def _testHttpsigBase(withDigest: bool, baseDir: str):
|
|||
messageBodyJsonStr, False) is False
|
||||
|
||||
os.chdir(baseDir)
|
||||
shutil.rmtree(path)
|
||||
shutil.rmtree(path, ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def _testHttpsig(baseDir: str):
|
||||
|
|
@ -709,7 +709,7 @@ def createServerAlice(path: str, domain: str, port: int,
|
|||
sendThreads: []):
|
||||
print('Creating test server: Alice on port ' + str(port))
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
shutil.rmtree(path, ignore_errors=False, onerror=None)
|
||||
os.mkdir(path)
|
||||
os.chdir(path)
|
||||
sharedItemsFederatedDomains = []
|
||||
|
|
@ -850,7 +850,7 @@ def createServerBob(path: str, domain: str, port: int,
|
|||
sendThreads: []):
|
||||
print('Creating test server: Bob on port ' + str(port))
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
shutil.rmtree(path, ignore_errors=False, onerror=None)
|
||||
os.mkdir(path)
|
||||
os.chdir(path)
|
||||
sharedItemsFederatedDomains = []
|
||||
|
|
@ -988,7 +988,7 @@ def createServerEve(path: str, domain: str, port: int, federationList: [],
|
|||
sendThreads: []):
|
||||
print('Creating test server: Eve on port ' + str(port))
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
shutil.rmtree(path, ignore_errors=False, onerror=None)
|
||||
os.mkdir(path)
|
||||
os.chdir(path)
|
||||
sharedItemsFederatedDomains = []
|
||||
|
|
@ -1055,7 +1055,7 @@ def createServerGroup(path: str, domain: str, port: int,
|
|||
sendThreads: []):
|
||||
print('Creating test server: Group on port ' + str(port))
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
shutil.rmtree(path, ignore_errors=False, onerror=None)
|
||||
os.mkdir(path)
|
||||
os.chdir(path)
|
||||
sharedItemsFederatedDomains = []
|
||||
|
|
@ -1134,7 +1134,7 @@ def testPostMessageBetweenServers(baseDir: str) -> None:
|
|||
proxyType = None
|
||||
|
||||
if os.path.isdir(baseDir + '/.tests'):
|
||||
shutil.rmtree(baseDir + '/.tests')
|
||||
shutil.rmtree(baseDir + '/.tests', ignore_errors=False, onerror=None)
|
||||
os.mkdir(baseDir + '/.tests')
|
||||
|
||||
# create the servers
|
||||
|
|
@ -1417,8 +1417,8 @@ def testPostMessageBetweenServers(baseDir: str) -> None:
|
|||
assert thrBob.is_alive() is False
|
||||
|
||||
os.chdir(baseDir)
|
||||
shutil.rmtree(aliceDir)
|
||||
shutil.rmtree(bobDir)
|
||||
shutil.rmtree(aliceDir, ignore_errors=False, onerror=None)
|
||||
shutil.rmtree(bobDir, ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def testFollowBetweenServers(baseDir: str) -> None:
|
||||
|
|
@ -1435,7 +1435,7 @@ def testFollowBetweenServers(baseDir: str) -> None:
|
|||
federationList = []
|
||||
|
||||
if os.path.isdir(baseDir + '/.tests'):
|
||||
shutil.rmtree(baseDir + '/.tests')
|
||||
shutil.rmtree(baseDir + '/.tests', ignore_errors=False, onerror=None)
|
||||
os.mkdir(baseDir + '/.tests')
|
||||
|
||||
# create the servers
|
||||
|
|
@ -1605,7 +1605,7 @@ def testFollowBetweenServers(baseDir: str) -> None:
|
|||
if os.path.isfile(os.path.join(queuePath, name))]) == 0
|
||||
|
||||
os.chdir(baseDir)
|
||||
shutil.rmtree(baseDir + '/.tests')
|
||||
shutil.rmtree(baseDir + '/.tests', ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def testSharedItemsFederation(baseDir: str) -> None:
|
||||
|
|
@ -1622,7 +1622,7 @@ def testSharedItemsFederation(baseDir: str) -> None:
|
|||
federationList = []
|
||||
|
||||
if os.path.isdir(baseDir + '/.tests'):
|
||||
shutil.rmtree(baseDir + '/.tests')
|
||||
shutil.rmtree(baseDir + '/.tests', ignore_errors=False, onerror=None)
|
||||
os.mkdir(baseDir + '/.tests')
|
||||
|
||||
# create the servers
|
||||
|
|
@ -1767,7 +1767,7 @@ def testSharedItemsFederation(baseDir: str) -> None:
|
|||
print('\n\n*********************************************************')
|
||||
print('Bob publishes some shared items')
|
||||
if os.path.isdir(bobDir + '/ontology'):
|
||||
shutil.rmtree(bobDir + '/ontology')
|
||||
shutil.rmtree(bobDir + '/ontology', ignore_errors=False, onerror=None)
|
||||
os.mkdir(bobDir + '/ontology')
|
||||
copyfile(baseDir + '/img/logo.png', bobDir + '/logo.png')
|
||||
copyfile(baseDir + '/ontology/foodTypes.json',
|
||||
|
|
@ -2004,7 +2004,7 @@ def testSharedItemsFederation(baseDir: str) -> None:
|
|||
assert thrBob.is_alive() is False
|
||||
|
||||
os.chdir(baseDir)
|
||||
shutil.rmtree(baseDir + '/.tests')
|
||||
shutil.rmtree(baseDir + '/.tests', ignore_errors=False, onerror=None)
|
||||
print('Testing federation of shared items between ' +
|
||||
'Alice and Bob is complete')
|
||||
|
||||
|
|
@ -2026,7 +2026,7 @@ def testGroupFollow(baseDir: str) -> None:
|
|||
federationList = []
|
||||
|
||||
if os.path.isdir(baseDir + '/.tests'):
|
||||
shutil.rmtree(baseDir + '/.tests')
|
||||
shutil.rmtree(baseDir + '/.tests', ignore_errors=False, onerror=None)
|
||||
os.mkdir(baseDir + '/.tests')
|
||||
|
||||
# create the servers
|
||||
|
|
@ -2412,7 +2412,7 @@ def testGroupFollow(baseDir: str) -> None:
|
|||
if os.path.isfile(os.path.join(queuePath, name))]) == 0
|
||||
|
||||
os.chdir(baseDir)
|
||||
shutil.rmtree(baseDir + '/.tests')
|
||||
shutil.rmtree(baseDir + '/.tests', ignore_errors=False, onerror=None)
|
||||
print('Testing following of a group is complete')
|
||||
|
||||
|
||||
|
|
@ -2427,7 +2427,7 @@ def _testFollowersOfPerson(baseDir: str) -> None:
|
|||
federationList = []
|
||||
baseDir = currDir + '/.tests_followersofperson'
|
||||
if os.path.isdir(baseDir):
|
||||
shutil.rmtree(baseDir)
|
||||
shutil.rmtree(baseDir, ignore_errors=False, onerror=None)
|
||||
os.mkdir(baseDir)
|
||||
os.chdir(baseDir)
|
||||
createPerson(baseDir, nickname, domain, port,
|
||||
|
|
@ -2462,7 +2462,7 @@ def _testFollowersOfPerson(baseDir: str) -> None:
|
|||
assert 'drokk@' + domain in followList
|
||||
assert 'sausagedog@' + domain in followList
|
||||
os.chdir(currDir)
|
||||
shutil.rmtree(baseDir)
|
||||
shutil.rmtree(baseDir, ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def _testNoOfFollowersOnDomain(baseDir: str) -> None:
|
||||
|
|
@ -2477,7 +2477,7 @@ def _testNoOfFollowersOnDomain(baseDir: str) -> None:
|
|||
federationList = []
|
||||
baseDir = currDir + '/.tests_nooffollowersOndomain'
|
||||
if os.path.isdir(baseDir):
|
||||
shutil.rmtree(baseDir)
|
||||
shutil.rmtree(baseDir, ignore_errors=False, onerror=None)
|
||||
os.mkdir(baseDir)
|
||||
os.chdir(baseDir)
|
||||
createPerson(baseDir, nickname, domain, port, httpPrefix, True,
|
||||
|
|
@ -2524,7 +2524,7 @@ def _testNoOfFollowersOnDomain(baseDir: str) -> None:
|
|||
assert followersOnOtherDomain == 2
|
||||
|
||||
os.chdir(currDir)
|
||||
shutil.rmtree(baseDir)
|
||||
shutil.rmtree(baseDir, ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def _testGroupFollowers(baseDir: str) -> None:
|
||||
|
|
@ -2539,7 +2539,7 @@ def _testGroupFollowers(baseDir: str) -> None:
|
|||
federationList = []
|
||||
baseDir = currDir + '/.tests_testgroupfollowers'
|
||||
if os.path.isdir(baseDir):
|
||||
shutil.rmtree(baseDir)
|
||||
shutil.rmtree(baseDir, ignore_errors=False, onerror=None)
|
||||
os.mkdir(baseDir)
|
||||
os.chdir(baseDir)
|
||||
createPerson(baseDir, nickname, domain, port, httpPrefix, True,
|
||||
|
|
@ -2569,7 +2569,7 @@ def _testGroupFollowers(baseDir: str) -> None:
|
|||
assert len(grouped['clutterly.domain']) == 1
|
||||
|
||||
os.chdir(currDir)
|
||||
shutil.rmtree(baseDir)
|
||||
shutil.rmtree(baseDir, ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def _testFollows(baseDir: str) -> None:
|
||||
|
|
@ -2583,7 +2583,7 @@ def _testFollows(baseDir: str) -> None:
|
|||
federationList = ['wild.com', 'mesh.com']
|
||||
baseDir = currDir + '/.tests_testfollows'
|
||||
if os.path.isdir(baseDir):
|
||||
shutil.rmtree(baseDir)
|
||||
shutil.rmtree(baseDir, ignore_errors=False, onerror=None)
|
||||
os.mkdir(baseDir)
|
||||
os.chdir(baseDir)
|
||||
createPerson(baseDir, nickname, domain, port, httpPrefix, True,
|
||||
|
|
@ -2647,7 +2647,7 @@ def _testFollows(baseDir: str) -> None:
|
|||
assert(False)
|
||||
|
||||
os.chdir(currDir)
|
||||
shutil.rmtree(baseDir)
|
||||
shutil.rmtree(baseDir, ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def _testCreatePerson(baseDir: str):
|
||||
|
|
@ -2662,7 +2662,7 @@ def _testCreatePerson(baseDir: str):
|
|||
clientToServer = False
|
||||
baseDir = currDir + '/.tests_createperson'
|
||||
if os.path.isdir(baseDir):
|
||||
shutil.rmtree(baseDir)
|
||||
shutil.rmtree(baseDir, ignore_errors=False, onerror=None)
|
||||
os.mkdir(baseDir)
|
||||
os.chdir(baseDir)
|
||||
|
||||
|
|
@ -2703,7 +2703,7 @@ def _testCreatePerson(baseDir: str):
|
|||
lowBandwidth)
|
||||
|
||||
os.chdir(currDir)
|
||||
shutil.rmtree(baseDir)
|
||||
shutil.rmtree(baseDir, ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def showTestBoxes(name: str, inboxPath: str, outboxPath: str) -> None:
|
||||
|
|
@ -2726,7 +2726,7 @@ def _testAuthentication(baseDir: str) -> None:
|
|||
|
||||
baseDir = currDir + '/.tests_authentication'
|
||||
if os.path.isdir(baseDir):
|
||||
shutil.rmtree(baseDir)
|
||||
shutil.rmtree(baseDir, ignore_errors=False, onerror=None)
|
||||
os.mkdir(baseDir)
|
||||
os.chdir(baseDir)
|
||||
|
||||
|
|
@ -2755,7 +2755,7 @@ def _testAuthentication(baseDir: str) -> None:
|
|||
authHeader, False)
|
||||
|
||||
os.chdir(currDir)
|
||||
shutil.rmtree(baseDir)
|
||||
shutil.rmtree(baseDir, ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def testClientToServer(baseDir: str):
|
||||
|
|
@ -2773,7 +2773,7 @@ def testClientToServer(baseDir: str):
|
|||
lowBandwidth = False
|
||||
|
||||
if os.path.isdir(baseDir + '/.tests'):
|
||||
shutil.rmtree(baseDir + '/.tests')
|
||||
shutil.rmtree(baseDir + '/.tests', ignore_errors=False, onerror=None)
|
||||
os.mkdir(baseDir + '/.tests')
|
||||
|
||||
# create the servers
|
||||
|
|
@ -3163,8 +3163,8 @@ def testClientToServer(baseDir: str):
|
|||
assert thrBob.is_alive() is False
|
||||
|
||||
os.chdir(baseDir)
|
||||
# shutil.rmtree(aliceDir)
|
||||
# shutil.rmtree(bobDir)
|
||||
# shutil.rmtree(aliceDir, ignore_errors=False, onerror=None)
|
||||
# shutil.rmtree(bobDir, ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def _testActorParsing():
|
||||
|
|
@ -3356,12 +3356,12 @@ def _testAddEmoji(baseDir: str):
|
|||
os.mkdir(path)
|
||||
path = baseDir + '/.tests/emoji'
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
shutil.rmtree(path, ignore_errors=False, onerror=None)
|
||||
os.mkdir(path)
|
||||
baseDir = path
|
||||
path = baseDir + '/emoji'
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
shutil.rmtree(path, ignore_errors=False, onerror=None)
|
||||
os.mkdir(path)
|
||||
copytree(baseDirOriginal + '/emoji', baseDir + '/emoji')
|
||||
os.chdir(baseDir)
|
||||
|
|
@ -3384,7 +3384,8 @@ def _testAddEmoji(baseDir: str):
|
|||
assert contentModified == '<p>Emoji 🍋 🍓 🍌</p>'
|
||||
|
||||
os.chdir(baseDirOriginal)
|
||||
shutil.rmtree(baseDirOriginal + '/.tests')
|
||||
shutil.rmtree(baseDirOriginal + '/.tests',
|
||||
ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def _testGetStatusNumber():
|
||||
|
|
@ -3578,9 +3579,10 @@ def _testJsonld():
|
|||
|
||||
def _testSiteIsActive():
|
||||
print('testSiteIsActive')
|
||||
assert(siteIsActive('https://archive.org'))
|
||||
assert(siteIsActive('https://mastodon.social'))
|
||||
assert(not siteIsActive('https://notarealwebsite.a.b.c'))
|
||||
timeout = 10
|
||||
assert(siteIsActive('https://archive.org', timeout))
|
||||
assert(siteIsActive('https://mastodon.social', timeout))
|
||||
assert(not siteIsActive('https://notarealwebsite.a.b.c', timeout))
|
||||
|
||||
|
||||
def _testRemoveHtml():
|
||||
|
|
@ -4987,7 +4989,8 @@ def testUpdateActor(baseDir: str):
|
|||
federationList = []
|
||||
|
||||
if os.path.isdir(baseDir + '/.tests'):
|
||||
shutil.rmtree(baseDir + '/.tests')
|
||||
shutil.rmtree(baseDir + '/.tests',
|
||||
ignore_errors=False, onerror=None)
|
||||
os.mkdir(baseDir + '/.tests')
|
||||
|
||||
# create the server
|
||||
|
|
@ -5089,7 +5092,7 @@ def testUpdateActor(baseDir: str):
|
|||
|
||||
os.chdir(baseDir)
|
||||
if os.path.isdir(baseDir + '/.tests'):
|
||||
shutil.rmtree(baseDir + '/.tests')
|
||||
shutil.rmtree(baseDir + '/.tests', ignore_errors=False, onerror=None)
|
||||
|
||||
|
||||
def _testRemovePostInteractions() -> None:
|
||||
|
|
|
|||
73
theme.py
73
theme.py
|
|
@ -30,7 +30,7 @@ def importTheme(baseDir: str, filename: str) -> bool:
|
|||
return False
|
||||
tempThemeDir = baseDir + '/imports/files'
|
||||
if os.path.isdir(tempThemeDir):
|
||||
rmtree(tempThemeDir)
|
||||
rmtree(tempThemeDir, ignore_errors=False, onerror=None)
|
||||
os.mkdir(tempThemeDir)
|
||||
unpack_archive(filename, tempThemeDir, 'zip')
|
||||
essentialThemeFiles = ('name.txt', 'theme.json')
|
||||
|
|
@ -71,9 +71,9 @@ def importTheme(baseDir: str, filename: str) -> bool:
|
|||
os.mkdir(themeDir)
|
||||
copytree(tempThemeDir, themeDir)
|
||||
if os.path.isdir(tempThemeDir):
|
||||
rmtree(tempThemeDir)
|
||||
rmtree(tempThemeDir, ignore_errors=False, onerror=None)
|
||||
if scanThemesForScripts(themeDir):
|
||||
rmtree(themeDir)
|
||||
rmtree(themeDir, ignore_errors=False, onerror=None)
|
||||
return False
|
||||
return os.path.isfile(themeDir + '/theme.json')
|
||||
|
||||
|
|
@ -91,10 +91,13 @@ def exportTheme(baseDir: str, theme: str) -> bool:
|
|||
try:
|
||||
os.remove(exportFilename)
|
||||
except BaseException:
|
||||
print('EX: exportTheme unable to delete ' + str(exportFilename))
|
||||
pass
|
||||
try:
|
||||
make_archive(baseDir + '/exports/' + theme, 'zip', themeDir)
|
||||
except BaseException:
|
||||
print('EX: exportTheme unable to archive ' +
|
||||
baseDir + '/exports/' + str(theme))
|
||||
pass
|
||||
return os.path.isfile(exportFilename)
|
||||
|
||||
|
|
@ -257,11 +260,14 @@ def _removeTheme(baseDir: str):
|
|||
"""
|
||||
themeFiles = _getThemeFiles()
|
||||
for filename in themeFiles:
|
||||
if os.path.isfile(baseDir + '/' + filename):
|
||||
try:
|
||||
os.remove(baseDir + '/' + filename)
|
||||
except BaseException:
|
||||
pass
|
||||
if not os.path.isfile(baseDir + '/' + filename):
|
||||
continue
|
||||
try:
|
||||
os.remove(baseDir + '/' + filename)
|
||||
except BaseException:
|
||||
print('EX: _removeTheme unable to delete ' +
|
||||
baseDir + '/' + filename)
|
||||
pass
|
||||
|
||||
|
||||
def setCSSparam(css: str, param: str, value: str) -> str:
|
||||
|
|
@ -446,6 +452,8 @@ def disableGrayscale(baseDir: str) -> None:
|
|||
try:
|
||||
os.remove(grayscaleFilename)
|
||||
except BaseException:
|
||||
print('EX: disableGrayscale unable to delete ' +
|
||||
grayscaleFilename)
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -589,12 +597,18 @@ def _setTextModeTheme(baseDir: str, name: str) -> None:
|
|||
copyfile(textModeLogoFilename,
|
||||
baseDir + '/accounts/logo.txt')
|
||||
except BaseException:
|
||||
print('EX: _setTextModeTheme unable to copy ' +
|
||||
textModeLogoFilename + ' ' +
|
||||
baseDir + '/accounts/logo.txt')
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
copyfile(baseDir + '/img/logo.txt',
|
||||
baseDir + '/accounts/logo.txt')
|
||||
except BaseException:
|
||||
print('EX: _setTextModeTheme unable to copy ' +
|
||||
baseDir + '/img/logo.txt ' +
|
||||
baseDir + '/accounts/logo.txt')
|
||||
pass
|
||||
|
||||
# set the text mode banner which appears in browsers such as Lynx
|
||||
|
|
@ -604,12 +618,17 @@ def _setTextModeTheme(baseDir: str, name: str) -> None:
|
|||
try:
|
||||
os.remove(baseDir + '/accounts/banner.txt')
|
||||
except BaseException:
|
||||
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:
|
||||
print('EX: _setTextModeTheme unable to copy ' +
|
||||
textModeBannerFilename + ' ' +
|
||||
baseDir + '/accounts/banner.txt')
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -641,8 +660,7 @@ def _setThemeImages(baseDir: str, name: str) -> None:
|
|||
for acct in dirs:
|
||||
if not isAccountDir(acct):
|
||||
continue
|
||||
accountDir = \
|
||||
os.path.join(baseDir + '/accounts', acct)
|
||||
accountDir = os.path.join(baseDir + '/accounts', acct)
|
||||
|
||||
for backgroundType in backgroundNames:
|
||||
for ext in extensions:
|
||||
|
|
@ -662,6 +680,8 @@ def _setThemeImages(baseDir: str, name: str) -> None:
|
|||
backgroundType + '-background.' + ext)
|
||||
continue
|
||||
except BaseException:
|
||||
print('EX: _setThemeImages unable to copy ' +
|
||||
backgroundImageFilename)
|
||||
pass
|
||||
# background image was not found
|
||||
# so remove any existing file
|
||||
|
|
@ -671,6 +691,9 @@ def _setThemeImages(baseDir: str, name: str) -> None:
|
|||
os.remove(baseDir + '/accounts/' +
|
||||
backgroundType + '-background.' + ext)
|
||||
except BaseException:
|
||||
print('EX: _setThemeImages unable to delete ' +
|
||||
baseDir + '/accounts/' +
|
||||
backgroundType + '-background.' + ext)
|
||||
pass
|
||||
|
||||
if os.path.isfile(profileImageFilename) and \
|
||||
|
|
@ -679,12 +702,16 @@ def _setThemeImages(baseDir: str, name: str) -> None:
|
|||
copyfile(profileImageFilename,
|
||||
accountDir + '/image.png')
|
||||
except BaseException:
|
||||
print('EX: _setThemeImages unable to copy ' +
|
||||
profileImageFilename)
|
||||
pass
|
||||
|
||||
try:
|
||||
copyfile(bannerFilename,
|
||||
accountDir + '/banner.png')
|
||||
except BaseException:
|
||||
print('EX: _setThemeImages unable to copy ' +
|
||||
bannerFilename)
|
||||
pass
|
||||
|
||||
try:
|
||||
|
|
@ -692,21 +719,25 @@ def _setThemeImages(baseDir: str, name: str) -> None:
|
|||
copyfile(searchBannerFilename,
|
||||
accountDir + '/search_banner.png')
|
||||
except BaseException:
|
||||
print('EX: _setThemeImages unable to copy ' +
|
||||
searchBannerFilename)
|
||||
pass
|
||||
|
||||
try:
|
||||
if os.path.isfile(leftColImageFilename):
|
||||
copyfile(leftColImageFilename,
|
||||
accountDir + '/left_col_image.png')
|
||||
else:
|
||||
if os.path.isfile(accountDir +
|
||||
'/left_col_image.png'):
|
||||
try:
|
||||
os.remove(accountDir + '/left_col_image.png')
|
||||
except BaseException:
|
||||
pass
|
||||
|
||||
elif os.path.isfile(accountDir +
|
||||
'/left_col_image.png'):
|
||||
try:
|
||||
os.remove(accountDir + '/left_col_image.png')
|
||||
except BaseException:
|
||||
print('EX: _setThemeImages unable to delete ' +
|
||||
accountDir + '/left_col_image.png')
|
||||
pass
|
||||
except BaseException:
|
||||
print('EX: _setThemeImages unable to copy ' +
|
||||
leftColImageFilename)
|
||||
pass
|
||||
|
||||
try:
|
||||
|
|
@ -719,8 +750,12 @@ def _setThemeImages(baseDir: str, name: str) -> None:
|
|||
try:
|
||||
os.remove(accountDir + '/right_col_image.png')
|
||||
except BaseException:
|
||||
print('EX: _setThemeImages unable to delete ' +
|
||||
accountDir + '/right_col_image.png')
|
||||
pass
|
||||
except BaseException:
|
||||
print('EX: _setThemeImages unable to copy ' +
|
||||
rightColImageFilename)
|
||||
pass
|
||||
break
|
||||
|
||||
|
|
@ -745,6 +780,7 @@ def setNewsAvatar(baseDir: str, name: str,
|
|||
try:
|
||||
os.remove(filename)
|
||||
except BaseException:
|
||||
print('EX: setNewsAvatar unable to delete ' + filename)
|
||||
pass
|
||||
if os.path.isdir(baseDir + '/cache/avatars'):
|
||||
copyfile(newFilename, filename)
|
||||
|
|
@ -780,6 +816,7 @@ def setTheme(baseDir: str, name: str, domain: str,
|
|||
globals()['setTheme' + themeName](baseDir,
|
||||
allowLocalNetworkAccess)
|
||||
except BaseException:
|
||||
print('EX: setTheme unable to set theme ' + themeName)
|
||||
pass
|
||||
|
||||
if prevThemeName:
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class threadWithTrace(threading.Thread):
|
|||
|
||||
|
||||
def removeDormantThreads(baseDir: str, threadsList: [], debug: bool,
|
||||
timeoutMins: int = 30) -> None:
|
||||
timeoutMins: int) -> None:
|
||||
"""Removes threads whose execution has completed
|
||||
"""
|
||||
if len(threadsList) == 0:
|
||||
|
|
@ -150,4 +150,6 @@ def removeDormantThreads(baseDir: str, threadsList: [], debug: bool,
|
|||
',' + str(noOfActiveThreads) +
|
||||
',' + str(len(threadsList)) + '\n')
|
||||
except BaseException:
|
||||
print('EX: removeDormantThreads unable to write ' +
|
||||
sendLogFilename)
|
||||
pass
|
||||
|
|
|
|||
73
utils.py
73
utils.py
|
|
@ -16,9 +16,9 @@ import json
|
|||
import idna
|
||||
import locale
|
||||
from pprint import pprint
|
||||
from followingCalendar import addPersonToCalendar
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from followingCalendar import addPersonToCalendar
|
||||
|
||||
# posts containing these strings will always get screened out,
|
||||
# both incoming and outgoing.
|
||||
|
|
@ -209,8 +209,7 @@ def hasUsersPath(pathStr: str) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def validPostDate(published: str, maxAgeDays: int = 90,
|
||||
debug: bool = False) -> bool:
|
||||
def validPostDate(published: str, maxAgeDays: int, debug: bool) -> bool:
|
||||
"""Returns true if the published date is recent and is not in the future
|
||||
"""
|
||||
baselineTime = datetime.datetime(1970, 1, 1)
|
||||
|
|
@ -222,6 +221,8 @@ def validPostDate(published: str, maxAgeDays: int = 90,
|
|||
postTimeObject = \
|
||||
datetime.datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: validPostDate invalid published date ' + str(published))
|
||||
return False
|
||||
|
||||
daysDiff = postTimeObject - baselineTime
|
||||
|
|
@ -252,7 +253,7 @@ def getFullDomain(domain: str, port: int) -> str:
|
|||
|
||||
|
||||
def isDormant(baseDir: str, nickname: str, domain: str, actor: str,
|
||||
dormantMonths: int = 3) -> bool:
|
||||
dormantMonths: int) -> bool:
|
||||
"""Is the given followed actor dormant, from the standpoint
|
||||
of the given account
|
||||
"""
|
||||
|
|
@ -625,6 +626,8 @@ def removeAvatarFromCache(baseDir: str, actorStr: str) -> None:
|
|||
try:
|
||||
os.remove(avatarFilename)
|
||||
except BaseException:
|
||||
print('EX: removeAvatarFromCache ' +
|
||||
'unable to delete cached avatar ' + str(avatarFilename))
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -638,7 +641,7 @@ def saveJson(jsonObject: {}, filename: str) -> bool:
|
|||
fp.write(json.dumps(jsonObject))
|
||||
return True
|
||||
except BaseException:
|
||||
print('WARN: saveJson ' + str(tries))
|
||||
print('EX: saveJson ' + str(tries))
|
||||
time.sleep(1)
|
||||
tries += 1
|
||||
return False
|
||||
|
|
@ -656,7 +659,7 @@ def loadJson(filename: str, delaySec: int = 2, maxTries: int = 5) -> {}:
|
|||
jsonObject = json.loads(data)
|
||||
break
|
||||
except BaseException:
|
||||
print('WARN: loadJson exception')
|
||||
print('EX: loadJson exception ' + str(filename))
|
||||
if delaySec > 0:
|
||||
time.sleep(delaySec)
|
||||
tries += 1
|
||||
|
|
@ -681,7 +684,7 @@ def loadJsonOnionify(filename: str, domain: str, onionDomain: str,
|
|||
jsonObject = json.loads(data)
|
||||
break
|
||||
except BaseException:
|
||||
print('WARN: loadJson exception')
|
||||
print('EX: loadJsonOnionify exception ' + str(filename))
|
||||
if delaySec > 0:
|
||||
time.sleep(delaySec)
|
||||
tries += 1
|
||||
|
|
@ -1285,8 +1288,8 @@ def clearFromPostCaches(baseDir: str, recentPostsCache: {},
|
|||
try:
|
||||
os.remove(postFilename)
|
||||
except BaseException:
|
||||
print('WARN: clearFromPostCaches file not removed ' +
|
||||
postFilename)
|
||||
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'):
|
||||
|
|
@ -1384,6 +1387,9 @@ def setReplyIntervalHours(baseDir: str, nickname: str, domain: str,
|
|||
fp.write(str(replyIntervalHours))
|
||||
return True
|
||||
except BaseException:
|
||||
print('EX: setReplyIntervalHours unable to save reply interval ' +
|
||||
str(replyIntervalFilename) + ' ' +
|
||||
str(replyIntervalHours))
|
||||
pass
|
||||
return False
|
||||
|
||||
|
|
@ -1411,6 +1417,7 @@ def canReplyTo(baseDir: str, nickname: str, domain: str,
|
|||
try:
|
||||
pubDate = datetime.datetime.strptime(published, '%Y-%m-%dT%H:%M:%SZ')
|
||||
except BaseException:
|
||||
print('EX: canReplyTo unrecognized published date ' + str(published))
|
||||
return False
|
||||
if not currDateStr:
|
||||
currDate = datetime.datetime.utcnow()
|
||||
|
|
@ -1419,6 +1426,8 @@ def canReplyTo(baseDir: str, nickname: str, domain: str,
|
|||
currDate = datetime.datetime.strptime(currDateStr,
|
||||
'%Y-%m-%dT%H:%M:%SZ')
|
||||
except BaseException:
|
||||
print('EX: canReplyTo unrecognized current date ' +
|
||||
str(currDateStr))
|
||||
return False
|
||||
hoursSincePublication = int((currDate - pubDate).total_seconds() / 3600)
|
||||
if hoursSincePublication < 0 or \
|
||||
|
|
@ -1442,12 +1451,16 @@ def _removeAttachment(baseDir: str, httpPrefix: str, domain: str,
|
|||
try:
|
||||
os.remove(mediaFilename)
|
||||
except BaseException:
|
||||
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:
|
||||
print('EX: _removeAttachment unable to delete etag file ' +
|
||||
str(etagFilename))
|
||||
pass
|
||||
postJson['attachment'] = []
|
||||
|
||||
|
|
@ -1516,6 +1529,8 @@ def _deletePostRemoveReplies(baseDir: str, nickname: str, domain: str,
|
|||
try:
|
||||
os.remove(repliesFilename)
|
||||
except BaseException:
|
||||
print('EX: _deletePostRemoveReplies unable to delete replies file ' +
|
||||
str(repliesFilename))
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -1575,6 +1590,9 @@ def _deleteCachedHtml(baseDir: str, nickname: str, domain: str,
|
|||
try:
|
||||
os.remove(cachedPostFilename)
|
||||
except BaseException:
|
||||
print('EX: _deleteCachedHtml ' +
|
||||
'unable to delete cached post file ' +
|
||||
str(cachedPostFilename))
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -1622,6 +1640,8 @@ def _deleteHashtagsOnPost(baseDir: str, postJsonObject: {}) -> None:
|
|||
try:
|
||||
os.remove(tagIndexFilename)
|
||||
except BaseException:
|
||||
print('EX: _deleteHashtagsOnPost unable to delete tag index ' +
|
||||
str(tagIndexFilename))
|
||||
pass
|
||||
else:
|
||||
# write the new hashtag index without the given post in it
|
||||
|
|
@ -1660,10 +1680,16 @@ def _deleteConversationPost(baseDir: str, nickname: str, domain: str,
|
|||
try:
|
||||
os.remove(conversationFilename + '.muted')
|
||||
except BaseException:
|
||||
print('EX: _deleteConversationPost ' +
|
||||
'unable to remove conversation ' +
|
||||
str(conversationFilename) + '.muted')
|
||||
pass
|
||||
try:
|
||||
os.remove(conversationFilename)
|
||||
except BaseException:
|
||||
print('EX: _deleteConversationPost ' +
|
||||
'unable to remove conversation ' +
|
||||
str(conversationFilename))
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -1682,6 +1708,9 @@ def deletePost(baseDir: str, httpPrefix: str,
|
|||
try:
|
||||
os.remove(postFilename)
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: deletePost unable to delete post ' +
|
||||
str(postFilename))
|
||||
pass
|
||||
return
|
||||
|
||||
|
|
@ -1710,6 +1739,8 @@ def deletePost(baseDir: str, httpPrefix: str,
|
|||
try:
|
||||
os.remove(extFilename)
|
||||
except BaseException:
|
||||
print('EX: deletePost unable to remove ext ' +
|
||||
str(extFilename))
|
||||
pass
|
||||
|
||||
# remove cached html version of the post
|
||||
|
|
@ -1739,6 +1770,8 @@ def deletePost(baseDir: str, httpPrefix: str,
|
|||
try:
|
||||
os.remove(postFilename)
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: deletePost unable to delete post ' + str(postFilename))
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -2179,6 +2212,9 @@ def undoLikesCollectionEntry(recentPostsCache: {},
|
|||
try:
|
||||
os.remove(cachedPostFilename)
|
||||
except BaseException:
|
||||
print('EX: undoLikesCollectionEntry ' +
|
||||
'unable to delete cached post ' +
|
||||
str(cachedPostFilename))
|
||||
pass
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
|
||||
|
|
@ -2241,6 +2277,10 @@ def undoAnnounceCollectionEntry(recentPostsCache: {},
|
|||
try:
|
||||
os.remove(cachedPostFilename)
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: undoAnnounceCollectionEntry ' +
|
||||
'unable to delete cached post ' +
|
||||
str(cachedPostFilename))
|
||||
pass
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
|
||||
|
|
@ -2305,6 +2345,10 @@ def updateAnnounceCollection(recentPostsCache: {},
|
|||
try:
|
||||
os.remove(cachedPostFilename)
|
||||
except BaseException:
|
||||
if debug:
|
||||
print('EX: updateAnnounceCollection ' +
|
||||
'unable to delete cached post ' +
|
||||
str(cachedPostFilename))
|
||||
pass
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
|
||||
|
|
@ -2388,7 +2432,7 @@ def mediaFileMimeType(filename: str) -> str:
|
|||
return extensions[fileExt]
|
||||
|
||||
|
||||
def isRecentPost(postJsonObject: {}, maxDays: int = 3) -> bool:
|
||||
def isRecentPost(postJsonObject: {}, maxDays: int) -> bool:
|
||||
""" Is the given post recent?
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
|
|
@ -2407,6 +2451,8 @@ def isRecentPost(postJsonObject: {}, maxDays: int = 3) -> bool:
|
|||
datetime.datetime.strptime(publishedDateStr,
|
||||
"%Y-%m-%dT%H:%M:%SZ")
|
||||
except BaseException:
|
||||
print('EX: isRecentPost unrecognized published date ' +
|
||||
str(publishedDateStr))
|
||||
return False
|
||||
|
||||
publishedDaysSinceEpoch = \
|
||||
|
|
@ -2552,7 +2598,7 @@ def loadTranslationsFromFile(baseDir: str, language: str) -> ({}, str):
|
|||
"""
|
||||
if not os.path.isdir(baseDir + '/translations'):
|
||||
print('ERROR: translations directory not found')
|
||||
return
|
||||
return None, None
|
||||
if not language:
|
||||
systemLanguage = locale.getdefaultlocale()[0]
|
||||
else:
|
||||
|
|
@ -2849,6 +2895,7 @@ def dateStringToSeconds(dateStr: str) -> int:
|
|||
expiryTime = \
|
||||
datetime.datetime.strptime(dateStr, '%Y-%m-%dT%H:%M:%SZ')
|
||||
except BaseException:
|
||||
print('EX: dateStringToSeconds unable to parse date ' + str(dateStr))
|
||||
return None
|
||||
return int(datetime.datetime.timestamp(expiryTime))
|
||||
|
||||
|
|
@ -2983,7 +3030,7 @@ def getSupportedLanguages(baseDir: str) -> []:
|
|||
"""
|
||||
translationsDir = baseDir + '/translations'
|
||||
languagesStr = []
|
||||
for subdir, dirs, files in os.walk(translationsDir):
|
||||
for _, _, files in os.walk(translationsDir):
|
||||
for f in files:
|
||||
if not f.endswith('.json'):
|
||||
continue
|
||||
|
|
@ -2999,7 +3046,7 @@ def getCategoryTypes(baseDir: str) -> []:
|
|||
"""
|
||||
ontologyDir = baseDir + '/ontology'
|
||||
categories = []
|
||||
for subdir, dirs, files in os.walk(ontologyDir):
|
||||
for _, _, files in os.walk(ontologyDir):
|
||||
for f in files:
|
||||
if not f.endswith('.json'):
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ def _htmlCalendarDay(personCache: {}, cssCache: {}, translate: {},
|
|||
try:
|
||||
os.remove(calendarFile)
|
||||
except BaseException:
|
||||
print('EX: _htmlCalendarDay unable to delete ' + calendarFile)
|
||||
pass
|
||||
|
||||
cssFilename = baseDir + '/epicyon-calendar.css'
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ def _htmlNewswire(baseDir: str, newswire: {}, nickname: str, moderator: bool,
|
|||
publishedDate = \
|
||||
datetime.strptime(dateStr, "%Y-%m-%d %H:%M:%S%z")
|
||||
except BaseException:
|
||||
print('WARN: bad date format ' + dateStr)
|
||||
print('EX: _htmlNewswire bad date format ' + dateStr)
|
||||
continue
|
||||
dateShown = publishedDate.strftime("%Y-%m-%d %H:%M")
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ def loadPeertubeInstances(baseDir: str, peertubeInstances: []) -> None:
|
|||
|
||||
def _addEmbeddedVideoFromSites(translate: {}, content: str,
|
||||
peertubeInstances: [],
|
||||
width: int = 400, height: int = 300) -> str:
|
||||
width: int, height: int) -> str:
|
||||
"""Adds embedded videos
|
||||
"""
|
||||
if '>vimeo.com/' in content:
|
||||
|
|
@ -250,6 +250,6 @@ def addEmbeddedElements(translate: {}, content: str,
|
|||
"""Adds embedded elements for various media types
|
||||
"""
|
||||
content = _addEmbeddedVideoFromSites(translate, content,
|
||||
peertubeInstances)
|
||||
peertubeInstances, 400, 300)
|
||||
content = _addEmbeddedAudio(translate, content)
|
||||
return _addEmbeddedVideo(translate, content)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ def setMinimal(baseDir: str, domain: str, nickname: str,
|
|||
try:
|
||||
os.remove(minimalFilename)
|
||||
except BaseException:
|
||||
print('EX: setMinimal unable to delete ' + minimalFilename)
|
||||
pass
|
||||
elif not minimal and not minimalFileExists:
|
||||
with open(minimalFilename, 'w+') as fp:
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ def htmlAccountInfo(cssCache: {}, translate: {},
|
|||
followersList = \
|
||||
downloadFollowCollection(signingPrivateKeyPem,
|
||||
'followers', session,
|
||||
httpPrefix, searchActor, 1, 5)
|
||||
httpPrefix, searchActor, 1, 5, debug)
|
||||
blockedFollowers = []
|
||||
for followerActor in followersList:
|
||||
followerNickname = getNicknameFromActor(followerActor)
|
||||
|
|
@ -146,7 +146,7 @@ def htmlAccountInfo(cssCache: {}, translate: {},
|
|||
followingList = \
|
||||
downloadFollowCollection(signingPrivateKeyPem,
|
||||
'following', session,
|
||||
httpPrefix, searchActor, 1, 5)
|
||||
httpPrefix, searchActor, 1, 5, debug)
|
||||
blockedFollowing = []
|
||||
for followingActor in followingList:
|
||||
followingNickname = getNicknameFromActor(followingActor)
|
||||
|
|
|
|||
|
|
@ -1403,7 +1403,7 @@ def individualPostAsHtml(signingPrivateKeyPem: str,
|
|||
postActor, nickname, domainFull, False)
|
||||
|
||||
# create a file for use by text-to-speech
|
||||
if isRecentPost(postJsonObject):
|
||||
if isRecentPost(postJsonObject, 3):
|
||||
if postJsonObject.get('actor'):
|
||||
if not os.path.isfile(announceFilename + '.tts'):
|
||||
updateSpeaker(baseDir, httpPrefix,
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ def insertQuestion(baseDir: str, translate: {},
|
|||
try:
|
||||
votes = int(questionOption['replies']['totalItems'])
|
||||
except BaseException:
|
||||
print('EX: insertQuestion unable to convert to int')
|
||||
pass
|
||||
if votes > maxVotes:
|
||||
maxVotes = int(votes+1)
|
||||
|
|
@ -89,6 +90,7 @@ def insertQuestion(baseDir: str, translate: {},
|
|||
try:
|
||||
votes = int(questionOption['replies']['totalItems'])
|
||||
except BaseException:
|
||||
print('EX: insertQuestion unable to convert to int 2')
|
||||
pass
|
||||
votesPercent = str(int(votes * 100 / maxVotes))
|
||||
content += \
|
||||
|
|
|
|||
|
|
@ -428,7 +428,8 @@ def htmlSearch(cssCache: {}, translate: {},
|
|||
with open(cachedHashtagSwarmFilename, 'r') as fp:
|
||||
swarmStr = fp.read()
|
||||
except BaseException:
|
||||
print('WARN: Unable to read cached hashtag swarm')
|
||||
print('EX: htmlSearch unable to read cached hashtag swarm ' +
|
||||
cachedHashtagSwarmFilename)
|
||||
pass
|
||||
if not swarmStr:
|
||||
swarmStr = htmlHashTagSwarm(baseDir, actor, translate)
|
||||
|
|
@ -437,7 +438,8 @@ def htmlSearch(cssCache: {}, translate: {},
|
|||
with open(cachedHashtagSwarmFilename, 'w+') as fp:
|
||||
fp.write(swarmStr)
|
||||
except BaseException:
|
||||
print('WARN: Unable to save cached hashtag swarm')
|
||||
print('EX: htmlSearch unable to save cached hashtag swarm ' +
|
||||
cachedHashtagSwarmFilename)
|
||||
pass
|
||||
|
||||
followStr += ' <p class="hashtagswarm">' + swarmStr + '</p>\n'
|
||||
|
|
|
|||
|
|
@ -477,6 +477,7 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
|
|||
try:
|
||||
os.remove(dmFile)
|
||||
except BaseException:
|
||||
print('EX: htmlTimeline unable to delete ' + dmFile)
|
||||
pass
|
||||
|
||||
# should the Replies button be highlighted?
|
||||
|
|
@ -488,6 +489,7 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
|
|||
try:
|
||||
os.remove(replyFile)
|
||||
except BaseException:
|
||||
print('EX: htmlTimeline unable to delete ' + replyFile)
|
||||
pass
|
||||
|
||||
# should the Shares button be highlighted?
|
||||
|
|
@ -499,6 +501,7 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
|
|||
try:
|
||||
os.remove(newShareFile)
|
||||
except BaseException:
|
||||
print('EX: htmlTimeline unable to delete ' + newShareFile)
|
||||
pass
|
||||
|
||||
# should the Wanted button be highlighted?
|
||||
|
|
@ -510,6 +513,7 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
|
|||
try:
|
||||
os.remove(newWantedFile)
|
||||
except BaseException:
|
||||
print('EX: htmlTimeline unable to delete ' + newWantedFile)
|
||||
pass
|
||||
|
||||
# should the Moderation/reports button be highlighted?
|
||||
|
|
@ -521,6 +525,7 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str,
|
|||
try:
|
||||
os.remove(newReportFile)
|
||||
except BaseException:
|
||||
print('EX: htmlTimeline unable to delete ' + newReportFile)
|
||||
pass
|
||||
|
||||
separatorStr = ''
|
||||
|
|
|
|||
|
|
@ -283,6 +283,8 @@ def updateAvatarImageCache(signingPrivateKeyPem: str,
|
|||
try:
|
||||
os.remove(avatarImageFilename)
|
||||
except BaseException:
|
||||
print('EX: updateAvatarImageCache unable to delete ' +
|
||||
avatarImageFilename)
|
||||
pass
|
||||
else:
|
||||
with open(avatarImageFilename, 'wb') as f:
|
||||
|
|
@ -1217,9 +1219,9 @@ def editTextField(label: str, name: str, value: str = "",
|
|||
value + '"' + placeholderStr + requiredStr + '>\n'
|
||||
|
||||
|
||||
def editNumberField(label: str, name: str, value: int = 1,
|
||||
minValue: int = 1, maxValue: int = 999999,
|
||||
placeholder: int = 1) -> str:
|
||||
def editNumberField(label: str, name: str, value: int,
|
||||
minValue: int, maxValue: int,
|
||||
placeholder: int) -> str:
|
||||
"""Returns html for editing an integer number field
|
||||
"""
|
||||
if value is None:
|
||||
|
|
@ -1234,9 +1236,8 @@ def editNumberField(label: str, name: str, value: int = 1,
|
|||
'min="' + str(minValue) + '" max="' + str(maxValue) + '" step="1">\n'
|
||||
|
||||
|
||||
def editCurrencyField(label: str, name: str, value: str = "0.00",
|
||||
placeholder: str = "0.00",
|
||||
required: bool = False) -> str:
|
||||
def editCurrencyField(label: str, name: str, value: str,
|
||||
placeholder: str, required: bool) -> str:
|
||||
"""Returns html for editing a currency field
|
||||
"""
|
||||
if value is None:
|
||||
|
|
@ -1256,7 +1257,7 @@ def editCurrencyField(label: str, name: str, value: str = "0.00",
|
|||
requiredStr + '>\n'
|
||||
|
||||
|
||||
def editCheckBox(label: str, name: str, checked: bool = False) -> str:
|
||||
def editCheckBox(label: str, name: str, checked: bool) -> str:
|
||||
"""Returns html for editing a checkbox field
|
||||
"""
|
||||
checkedStr = ''
|
||||
|
|
@ -1268,10 +1269,8 @@ def editCheckBox(label: str, name: str, checked: bool = False) -> str:
|
|||
'name="' + name + '"' + checkedStr + '> ' + label + '<br>\n'
|
||||
|
||||
|
||||
def editTextArea(label: str, name: str, value: str = "",
|
||||
height: int = 600,
|
||||
placeholder: str = "",
|
||||
spellcheck: bool = False) -> str:
|
||||
def editTextArea(label: str, name: str, value: str,
|
||||
height: int, placeholder: str, spellcheck: bool) -> str:
|
||||
"""Returns html for editing a textarea field
|
||||
"""
|
||||
if value is None:
|
||||
|
|
|
|||
Loading…
Reference in New Issue