Merge branch 'main' of gitlab.com:bashrc2/epicyon

merge-requests/30/head
Bob Mottram 2021-11-29 11:24:58 +00:00
commit c072fd63d2
12 changed files with 816 additions and 380 deletions

View File

@ -132,6 +132,7 @@ def authorizeBasic(baseDir: str, path: str, authHeader: str,
print('DEBUG: passwords file missing')
return False
providedPassword = plain.split(':')[1]
try:
with open(passwordFile, 'r') as passfile:
for line in passfile:
if not line.startswith(nickname + ':'):
@ -143,6 +144,9 @@ def authorizeBasic(baseDir: str, path: str, authHeader: str,
if debug:
print('DEBUG: Password check failed for ' + nickname)
return success
except OSError:
print('EX: failed to open password file')
return False
print('DEBUG: Did not find credentials for ' + nickname +
' in ' + passwordFile)
return False
@ -272,15 +276,15 @@ def recordLoginFailure(baseDir: str, ipAddress: str,
if not os.path.isfile(failureLog):
writeType = 'w+'
currTime = datetime.datetime.utcnow()
currTimeStr = currTime.strftime("%Y-%m-%d %H:%M:%SZ")
try:
with open(failureLog, writeType) as fp:
# here we use a similar format to an ssh log, so that
# systems such as fail2ban can parse it
fp.write(currTime.strftime("%Y-%m-%d %H:%M:%SZ") + ' ' +
fp.write(currTimeStr + ' ' +
'ip-127-0-0-1 sshd[20710]: ' +
'Disconnecting invalid user epicyon ' +
ipAddress + ' port 443: ' +
'Too many authentication failures [preauth]\n')
except OSError:
print('EX: recordLoginFailure failed ' + str(failureLog))
pass

View File

@ -94,11 +94,13 @@ def addBlock(baseDir: str, nickname: str, domain: str,
try:
with open(followingFilename, 'r') as followingFile:
followingStr = followingFile.read()
followingStr = followingStr.replace(blockHandle + '\n', '')
except OSError:
print('EX: Unable to read following ' + followingFilename)
return False
if followingStr:
followingStr = followingStr.replace(blockHandle + '\n', '')
try:
with open(followingFilename, 'w+') as followingFile:
followingFile.write(followingStr)
@ -114,11 +116,13 @@ def addBlock(baseDir: str, nickname: str, domain: str,
try:
with open(followersFilename, 'r') as followersFile:
followersStr = followersFile.read()
followersStr = followersStr.replace(blockHandle + '\n', '')
except OSError:
print('EX: Unable to read followers ' + followersFilename)
return False
if followersStr:
followersStr = followersStr.replace(blockHandle + '\n', '')
try:
with open(followersFilename, 'w+') as followersFile:
followersFile.write(followersStr)
@ -145,8 +149,8 @@ def removeGlobalBlock(baseDir: str,
unblockHandle = unblockNickname + '@' + unblockDomain
if os.path.isfile(unblockingFilename):
if unblockHandle in open(unblockingFilename).read():
with open(unblockingFilename, 'r') as fp:
try:
with open(unblockingFilename, 'r') as fp:
with open(unblockingFilename + '.new', 'w+') as fpnew:
for line in fp:
handle = \
@ -157,15 +161,21 @@ def removeGlobalBlock(baseDir: str,
print('EX: failed to remove global block ' +
unblockingFilename + ' ' + str(e))
return False
if os.path.isfile(unblockingFilename + '.new'):
os.rename(unblockingFilename + '.new', unblockingFilename)
try:
os.rename(unblockingFilename + '.new',
unblockingFilename)
except OSError:
print('EX: unable to rename ' + unblockingFilename)
return False
return True
else:
unblockHashtag = unblockNickname
if os.path.isfile(unblockingFilename):
if unblockHashtag + '\n' in open(unblockingFilename).read():
with open(unblockingFilename, 'r') as fp:
try:
with open(unblockingFilename, 'r') as fp:
with open(unblockingFilename + '.new', 'w+') as fpnew:
for line in fp:
blockLine = \
@ -176,8 +186,14 @@ def removeGlobalBlock(baseDir: str,
print('EX: failed to remove global hashtag block ' +
unblockingFilename + ' ' + str(e))
return False
if os.path.isfile(unblockingFilename + '.new'):
os.rename(unblockingFilename + '.new', unblockingFilename)
try:
os.rename(unblockingFilename + '.new',
unblockingFilename)
except OSError:
print('EX: unable to rename 2 ' + unblockingFilename)
return False
return True
return False
@ -191,8 +207,8 @@ def removeBlock(baseDir: str, nickname: str, domain: str,
unblockHandle = unblockNickname + '@' + unblockDomain
if os.path.isfile(unblockingFilename):
if unblockHandle in open(unblockingFilename).read():
with open(unblockingFilename, 'r') as fp:
try:
with open(unblockingFilename, 'r') as fp:
with open(unblockingFilename + '.new', 'w+') as fpnew:
for line in fp:
handle = line.replace('\n', '').replace('\r', '')
@ -202,8 +218,13 @@ def removeBlock(baseDir: str, nickname: str, domain: str,
print('EX: failed to remove block ' +
unblockingFilename + ' ' + str(e))
return False
if os.path.isfile(unblockingFilename + '.new'):
try:
os.rename(unblockingFilename + '.new', unblockingFilename)
except OSError:
print('EX: unable to rename 3 ' + unblockingFilename)
return False
return True
return False
@ -237,8 +258,11 @@ def getDomainBlocklist(baseDir: str) -> str:
globalBlockingFilename = baseDir + '/accounts/blocking.txt'
if not os.path.isfile(globalBlockingFilename):
return blockedStr
try:
with open(globalBlockingFilename, 'r') as fpBlocked:
blockedStr += fpBlocked.read()
except OSError:
print('EX: unable to read ' + globalBlockingFilename)
return blockedStr
@ -258,6 +282,7 @@ def updateBlockedCache(baseDir: str,
globalBlockingFilename = baseDir + '/accounts/blocking.txt'
if not os.path.isfile(globalBlockingFilename):
return blockedCacheLastUpdated
try:
with open(globalBlockingFilename, 'r') as fpBlocked:
blockedLines = fpBlocked.readlines()
# remove newlines
@ -266,6 +291,8 @@ def updateBlockedCache(baseDir: str,
# update the cache
blockedCache.clear()
blockedCache += blockedLines
except OSError as e:
print('EX: unable to read ' + globalBlockingFilename + ' ' + str(e))
return currTime
@ -305,6 +332,7 @@ def isBlockedDomain(baseDir: str, domain: str,
# instance block list
globalBlockingFilename = baseDir + '/accounts/blocking.txt'
if os.path.isfile(globalBlockingFilename):
try:
with open(globalBlockingFilename, 'r') as fpBlocked:
blockedStr = fpBlocked.read()
if '*@' + domain in blockedStr:
@ -312,6 +340,9 @@ def isBlockedDomain(baseDir: str, domain: str,
if shortDomain:
if '*@' + shortDomain in blockedStr:
return True
except OSError as e:
print('EX: unable to read ' + globalBlockingFilename +
' ' + str(e))
else:
allowFilename = baseDir + '/accounts/allowedinstances.txt'
# instance allow list
@ -572,10 +603,10 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
try:
with open(postFilename + '.muted', 'w+') as muteFile:
muteFile.write('\n')
print('MUTE: ' + postFilename + '.muted file added')
except OSError:
print('EX: Failed to save mute file ' + postFilename + '.muted')
return
print('MUTE: ' + postFilename + '.muted file added')
# if the post is in the recent posts cache then mark it as muted
if recentPostsCache.get('index'):
@ -886,6 +917,7 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
followingFilename = accountDir + '/' + followFileType
if not os.path.isfile(followingFilename):
continue
try:
with open(followingFilename, 'r') as f:
followList = f.readlines()
for handle in followList:
@ -895,6 +927,9 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
handleDomain = handle.split('@')[1]
if handleDomain not in allowedDomains:
allowedDomains.append(handleDomain)
except OSError as e:
print('EX: failed to read ' + followingFilename +
' ' + str(e))
break
# write the allow file

19
blog.py
View File

@ -72,8 +72,12 @@ def _noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {},
removals = []
replies = 0
lines = []
try:
with open(postFilename, 'r') as f:
lines = f.readlines()
except OSError:
print('EX: failed to read blog ' + postFilename)
for replyPostId in lines:
replyPostId = replyPostId.replace('\n', '').replace('\r', '')
replyPostId = replyPostId.replace('.json', '')
@ -135,12 +139,21 @@ def _getBlogReplies(baseDir: str, httpPrefix: str, translate: {},
'/postcache/' + \
postId.replace('/', '#') + '.html'
if os.path.isfile(postFilename):
try:
with open(postFilename, 'r') as postFile:
return postFile.read() + '\n'
except OSError:
print('EX: unable to read blog 3 ' + postFilename)
return ''
lines = []
try:
with open(postFilename, 'r') as f:
lines = f.readlines()
except OSError:
print('EX: unable to read blog 4 ' + postFilename)
if lines:
repliesStr = ''
for replyPostId in lines:
replyPostId = replyPostId.replace('\n', '').replace('\r', '')
@ -151,8 +164,11 @@ def _getBlogReplies(baseDir: str, httpPrefix: str, translate: {},
replyPostId.replace('/', '#') + '.html'
if not os.path.isfile(postFilename):
continue
try:
with open(postFilename, 'r') as postFile:
repliesStr += postFile.read() + '\n'
except OSError:
print('EX: unable to read blog replies ' + postFilename)
rply = _getBlogReplies(baseDir, httpPrefix, translate,
nickname, domain, domainFull,
replyPostId, depth+1)
@ -770,8 +786,11 @@ def htmlEditBlog(mediaInstance: bool, translate: {},
editBlogText = '<h1">' + translate['Write your post text below.'] + '</h1>'
if os.path.isfile(baseDir + '/accounts/newpost.txt'):
try:
with open(baseDir + '/accounts/newpost.txt', 'r') as file:
editBlogText = '<p>' + file.read() + '</p>'
except OSError:
print('EX: unable to read ' + baseDir + '/accounts/newpost.txt')
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):

View File

@ -71,8 +71,12 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
if bookmarkIndex not in open(bookmarksIndexFilename).read():
return
indexStr = ''
try:
with open(bookmarksIndexFilename, 'r') as indexFile:
indexStr = indexFile.read().replace(bookmarkIndex + '\n', '')
except OSError:
print('EX: unable to read ' + bookmarksIndexFilename)
if indexStr:
try:
with open(bookmarksIndexFilename, 'w+') as bookmarksIndexFile:
bookmarksIndexFile.write(indexStr)

View File

@ -23,8 +23,12 @@ def getHashtagCategory(baseDir: str, hashtag: str) -> str:
if not os.path.isfile(categoryFilename):
return ''
categoryStr = None
try:
with open(categoryFilename, 'r') as fp:
categoryStr = fp.read()
except OSError:
print('EX: unable to read category ' + categoryFilename)
if categoryStr:
return categoryStr
return ''
@ -161,15 +165,21 @@ def setHashtagCategory(baseDir: str, hashtag: str, category: str,
# don't overwrite any existing categories
if os.path.isfile(categoryFilename):
return False
categoryWritten = False
try:
with open(categoryFilename, 'w+') as fp:
fp.write(category)
if update:
updateHashtagCategories(baseDir)
return True
categoryWritten = True
except OSError as e:
print('EX: unable to write category ' + categoryFilename +
' ' + str(e))
if categoryWritten:
if update:
updateHashtagCategories(baseDir)
return True
return False

10
city.py
View File

@ -196,16 +196,23 @@ def spoofGeolocation(baseDir: str,
default_latdirection, default_longdirection,
"", "", 0)
cities = []
try:
with open(locationsFilename, 'r') as f:
cities = f.readlines()
except OSError:
print('EX: unable to read locations ' + locationsFilename)
nogo = []
if nogoList:
nogo = nogoList
else:
if os.path.isfile(nogoFilename):
nogoList = []
try:
with open(nogoFilename, 'r') as f:
nogoList = f.readlines()
except OSError:
print('EX: unable to read ' + nogoFilename)
for line in nogoList:
if line.startswith(city + ':'):
polygon = parseNogoString(line)
@ -295,8 +302,11 @@ def getSpoofedCity(city: str, baseDir: str, nickname: str, domain: str) -> str:
city = ''
cityFilename = acctDir(baseDir, nickname, domain) + '/city.txt'
if os.path.isfile(cityFilename):
try:
with open(cityFilename, 'r') as fp:
city = fp.read().replace('\n', '')
except OSError:
print('EX: unable to read ' + cityFilename)
return city

View File

@ -178,9 +178,14 @@ def dangerousCSS(filename: str, allowLocalNetworkAccess: bool) -> bool:
if not os.path.isfile(filename):
return False
content = None
try:
with open(filename, 'r') as fp:
content = fp.read().lower()
except OSError:
print('EX: unable to read css file ' + filename)
if content:
cssMatches = ('behavior:', ':expression', '?php', '.php',
'google', 'regexp', 'localhost',
'127.0.', '192.168', '10.0.', '@import')
@ -221,8 +226,11 @@ def switchWords(baseDir: str, nickname: str, domain: str, content: str,
acctDir(baseDir, nickname, domain) + '/replacewords.txt'
if not os.path.isfile(switchWordsFilename):
return content
try:
with open(switchWordsFilename, 'r') as fp:
rules = fp.readlines()
except OSError:
print('EX: unable to read switches ' + switchWordsFilename)
for line in rules:
replaceStr = line.replace('\n', '').replace('\r', '')
@ -779,8 +787,11 @@ def _loadAutoTags(baseDir: str, nickname: str, domain: str) -> []:
filename = acctDir(baseDir, nickname, domain) + '/autotags.txt'
if not os.path.isfile(filename):
return []
try:
with open(filename, 'r') as f:
return f.readlines()
except OSError:
print('EX: unable to read auto tags ' + filename)
return []
@ -853,8 +864,12 @@ def addHtmlTags(baseDir: str, httpPrefix: str,
petnames = None
if '@' in words:
if os.path.isfile(followingFilename):
following = []
try:
with open(followingFilename, 'r') as f:
following = f.readlines()
except OSError:
print('EX: unable to read ' + followingFilename)
for handle in following:
pet = getPetName(baseDir, nickname, domain, handle)
if pet:

299
daemon.py
View File

@ -2355,13 +2355,16 @@ class PubServer(BaseHTTPRequestHandler):
else:
if os.path.isdir(accountDir):
nwFilename = newswireBlockedFilename
nwWritten = False
try:
with open(nwFilename, 'w+') as noNewswireFile:
noNewswireFile.write('\n')
refreshNewswire(self.server.baseDir)
nwWritten = True
except OSError as e:
print('EX: unable to write ' + nwFilename +
' ' + str(e))
if nwWritten:
refreshNewswire(self.server.baseDir)
usersPathStr = \
usersPath + '/' + self.server.defaultTimeline + \
'?page=' + str(pageNumber)
@ -2398,13 +2401,16 @@ class PubServer(BaseHTTPRequestHandler):
else:
if os.path.isdir(accountDir):
featFilename = featuresBlockedFilename
featWritten = False
try:
with open(featFilename, 'w+') as noFeaturesFile:
noFeaturesFile.write('\n')
refreshNewswire(self.server.baseDir)
featWritten = True
except OSError as e:
print('EX: unable to write ' + featFilename +
' ' + str(e))
if featWritten:
refreshNewswire(self.server.baseDir)
usersPathStr = \
usersPath + '/' + self.server.defaultTimeline + \
'?page=' + str(pageNumber)
@ -3167,7 +3173,15 @@ class PubServer(BaseHTTPRequestHandler):
self._write(msg)
self.server.POSTbusy = False
return
elif searchStr.startswith('*'):
elif (searchStr.startswith('*') or
searchStr.endswith(' skill')):
possibleEndings = (
' skill'
)
for possEnding in possibleEndings:
if searchStr.endswith(possEnding):
searchStr = searchStr.replace(possEnding, '')
break
# skill search
searchStr = searchStr.replace('*', '').strip()
skillStr = \
@ -3187,7 +3201,34 @@ class PubServer(BaseHTTPRequestHandler):
self._write(msg)
self.server.POSTbusy = False
return
elif searchStr.startswith("'"):
elif (searchStr.startswith("'") or
searchStr.endswith(' history') or
searchStr.endswith(' in sent') or
searchStr.endswith(' in outbox') or
searchStr.endswith(' in outgoing') or
searchStr.endswith(' in sent items') or
searchStr.endswith(' in sent posts') or
searchStr.endswith(' in outgoing posts') or
searchStr.endswith(' in my history') or
searchStr.endswith(' in my outbox') or
searchStr.endswith(' in my posts')):
possibleEndings = (
' in my posts',
' in my history',
' in my outbox',
' in sent posts',
' in outgoing posts',
' in sent items',
' in history',
' in outbox',
' in outgoing',
' in sent',
' history'
)
for possEnding in possibleEndings:
if searchStr.endswith(possEnding):
searchStr = searchStr.replace(possEnding, '')
break
# your post history search
nickname = getNicknameFromActor(actorStr)
searchStr = searchStr.replace("'", '', 1).strip()
@ -3227,7 +3268,35 @@ class PubServer(BaseHTTPRequestHandler):
self._write(msg)
self.server.POSTbusy = False
return
elif searchStr.startswith('-'):
elif (searchStr.startswith('-') or
searchStr.endswith(' in my saved items') or
searchStr.endswith(' in my saved posts') or
searchStr.endswith(' in my bookmarks') or
searchStr.endswith(' in my saved') or
searchStr.endswith(' in my saves') or
searchStr.endswith(' in saved posts') or
searchStr.endswith(' in saved items') or
searchStr.endswith(' in bookmarks') or
searchStr.endswith(' in saved') or
searchStr.endswith(' in saves') or
searchStr.endswith(' bookmark')):
possibleEndings = (
' in my bookmarks'
' in my saved posts'
' in my saved items'
' in my saved'
' in my saves'
' in saved posts'
' in saved items'
' in saved'
' in saves'
' in bookmarks'
' bookmark'
)
for possEnding in possibleEndings:
if searchStr.endswith(possEnding):
searchStr = searchStr.replace(possEnding, '')
break
# bookmark search
nickname = getNicknameFromActor(actorStr)
searchStr = searchStr.replace('-', '', 1).strip()
@ -3906,8 +3975,11 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('editedLinks'):
linksStr = fields['editedLinks']
try:
with open(linksFilename, 'w+') as linksFile:
linksFile.write(linksStr)
except OSError:
print('EX: _linksUpdate unable to write ' + linksFilename)
else:
if os.path.isfile(linksFilename):
try:
@ -3923,8 +3995,11 @@ class PubServer(BaseHTTPRequestHandler):
aboutStr = fields['editedAbout']
if not dangerousMarkup(aboutStr,
allowLocalNetworkAccess):
try:
with open(aboutFilename, 'w+') as aboutFile:
aboutFile.write(aboutStr)
except OSError:
print('EX: unable to write about ' + aboutFilename)
else:
if os.path.isfile(aboutFilename):
try:
@ -3937,8 +4012,11 @@ class PubServer(BaseHTTPRequestHandler):
TOSStr = fields['editedTOS']
if not dangerousMarkup(TOSStr,
allowLocalNetworkAccess):
try:
with open(TOSFilename, 'w+') as TOSFile:
TOSFile.write(TOSStr)
except OSError:
print('EX: unable to write TOS ' + TOSFilename)
else:
if os.path.isfile(TOSFilename):
try:
@ -4731,7 +4809,7 @@ class PubServer(BaseHTTPRequestHandler):
with open(cityFilename, 'w+') as fp:
fp.write(fields['cityDropdown'])
except OSError:
print('EX: unable to write ' + cityFilename)
print('EX: unable to write city ' + cityFilename)
# change displayed name
if fields.get('displayNickname'):
@ -5375,14 +5453,21 @@ class PubServer(BaseHTTPRequestHandler):
if ',' in fields['moderators']:
# if the list was given as comma separated
mods = fields['moderators'].split(',')
with open(moderatorsFile, 'w+') as modFile:
try:
with open(moderatorsFile,
'w+') as modFile:
for modNick in mods:
modNick = modNick.strip()
modDir = baseDir + \
'/accounts/' + modNick + \
'@' + domain
if os.path.isdir(modDir):
modFile.write(modNick + '\n')
modFile.write(modNick +
'\n')
except OSError:
print('EX: ' +
'unable to write moderators ' +
moderatorsFile)
for modNick in mods:
modNick = modNick.strip()
@ -5396,7 +5481,9 @@ class PubServer(BaseHTTPRequestHandler):
else:
# nicknames on separate lines
mods = fields['moderators'].split('\n')
with open(moderatorsFile, 'w+') as modFile:
try:
with open(moderatorsFile,
'w+') as modFile:
for modNick in mods:
modNick = modNick.strip()
modDir = \
@ -5404,7 +5491,12 @@ class PubServer(BaseHTTPRequestHandler):
'/accounts/' + modNick + \
'@' + domain
if os.path.isdir(modDir):
modFile.write(modNick + '\n')
modFile.write(modNick +
'\n')
except OSError:
print('EX: ' +
'unable to write moderators 2 ' +
moderatorsFile)
for modNick in mods:
modNick = modNick.strip()
@ -5429,6 +5521,7 @@ class PubServer(BaseHTTPRequestHandler):
if ',' in fields['editors']:
# if the list was given as comma separated
eds = fields['editors'].split(',')
try:
with open(editorsFile, 'w+') as edFile:
for edNick in eds:
edNick = edNick.strip()
@ -5437,6 +5530,9 @@ class PubServer(BaseHTTPRequestHandler):
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
print('EX: unable to write editors ' +
editorsFile + ' ' + str(e))
for edNick in eds:
edNick = edNick.strip()
@ -5450,7 +5546,9 @@ class PubServer(BaseHTTPRequestHandler):
else:
# nicknames on separate lines
eds = fields['editors'].split('\n')
with open(editorsFile, 'w+') as edFile:
try:
with open(editorsFile,
'w+') as edFile:
for edNick in eds:
edNick = edNick.strip()
edDir = \
@ -5459,6 +5557,9 @@ class PubServer(BaseHTTPRequestHandler):
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
print('EX: unable to write editors ' +
editorsFile + ' ' + str(e))
for edNick in eds:
edNick = edNick.strip()
@ -5483,7 +5584,9 @@ class PubServer(BaseHTTPRequestHandler):
if ',' in fields['counselors']:
# if the list was given as comma separated
eds = fields['counselors'].split(',')
with open(counselorsFile, 'w+') as edFile:
try:
with open(counselorsFile,
'w+') as edFile:
for edNick in eds:
edNick = edNick.strip()
edDir = baseDir + \
@ -5491,6 +5594,10 @@ class PubServer(BaseHTTPRequestHandler):
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
print('EX: ' +
'unable to write counselors ' +
counselorsFile + ' ' + str(e))
for edNick in eds:
edNick = edNick.strip()
@ -5504,7 +5611,9 @@ class PubServer(BaseHTTPRequestHandler):
else:
# nicknames on separate lines
eds = fields['counselors'].split('\n')
with open(counselorsFile, 'w+') as edFile:
try:
with open(counselorsFile,
'w+') as edFile:
for edNick in eds:
edNick = edNick.strip()
edDir = \
@ -5513,6 +5622,10 @@ class PubServer(BaseHTTPRequestHandler):
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
print('EX: ' +
'unable to write counselors ' +
counselorsFile + ' ' + str(e))
for edNick in eds:
edNick = edNick.strip()
@ -5537,6 +5650,7 @@ class PubServer(BaseHTTPRequestHandler):
if ',' in fields['artists']:
# if the list was given as comma separated
eds = fields['artists'].split(',')
try:
with open(artistsFile, 'w+') as edFile:
for edNick in eds:
edNick = edNick.strip()
@ -5545,6 +5659,9 @@ class PubServer(BaseHTTPRequestHandler):
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
print('EX: unable to write artists ' +
artistsFile + ' ' + str(e))
for edNick in eds:
edNick = edNick.strip()
@ -5558,6 +5675,7 @@ class PubServer(BaseHTTPRequestHandler):
else:
# nicknames on separate lines
eds = fields['artists'].split('\n')
try:
with open(artistsFile, 'w+') as edFile:
for edNick in eds:
edNick = edNick.strip()
@ -5567,6 +5685,9 @@ class PubServer(BaseHTTPRequestHandler):
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
print('EX: unable to write artists ' +
artistsFile + ' ' + str(e))
for edNick in eds:
edNick = edNick.strip()
@ -5666,16 +5787,25 @@ class PubServer(BaseHTTPRequestHandler):
if onFinalWelcomeScreen:
# initial default setting created via
# the welcome screen
try:
with open(followDMsFilename, 'w+') as fFile:
fFile.write('\n')
except OSError:
print('EX: unable to write follow DMs ' +
followDMsFilename)
actorChanged = True
else:
followDMsActive = False
if fields.get('followDMs'):
if fields['followDMs'] == 'on':
followDMsActive = True
with open(followDMsFilename, 'w+') as fFile:
try:
with open(followDMsFilename,
'w+') as fFile:
fFile.write('\n')
except OSError:
print('EX: unable to write follow DMs 2 ' +
followDMsFilename)
if not followDMsActive:
if os.path.isfile(followDMsFilename):
try:
@ -5693,9 +5823,13 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('removeTwitter'):
if fields['removeTwitter'] == 'on':
removeTwitterActive = True
try:
with open(removeTwitterFilename,
'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write remove twitter ' +
removeTwitterFilename)
if not removeTwitterActive:
if os.path.isfile(removeTwitterFilename):
try:
@ -5716,8 +5850,12 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('hideLikeButton'):
if fields['hideLikeButton'] == 'on':
hideLikeButtonActive = True
try:
with open(hideLikeButtonFile, 'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write hide like ' +
hideLikeButtonFile)
# remove notify likes selection
if os.path.isfile(notifyLikesFilename):
try:
@ -5746,8 +5884,13 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('hideReactionButton'):
if fields['hideReactionButton'] == 'on':
hideReactionButtonActive = True
with open(hideReactionButtonFile, 'w+') as rFile:
try:
with open(hideReactionButtonFile,
'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write hide reaction ' +
hideReactionButtonFile)
# remove notify Reaction selection
if os.path.isfile(notifyReactionsFilename):
try:
@ -5768,8 +5911,12 @@ class PubServer(BaseHTTPRequestHandler):
# notify about new Likes
if onFinalWelcomeScreen:
# default setting from welcome screen
try:
with open(notifyLikesFilename, 'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write notify likes ' +
notifyLikesFilename)
actorChanged = True
else:
notifyLikesActive = False
@ -5777,8 +5924,13 @@ class PubServer(BaseHTTPRequestHandler):
if fields['notifyLikes'] == 'on' and \
not hideLikeButtonActive:
notifyLikesActive = True
with open(notifyLikesFilename, 'w+') as rFile:
try:
with open(notifyLikesFilename,
'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write notify likes ' +
notifyLikesFilename)
if not notifyLikesActive:
if os.path.isfile(notifyLikesFilename):
try:
@ -5793,8 +5945,12 @@ class PubServer(BaseHTTPRequestHandler):
'/.notifyReactions'
if onFinalWelcomeScreen:
# default setting from welcome screen
try:
with open(notifyReactionsFilename, 'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write notify reactions ' +
notifyReactionsFilename)
actorChanged = True
else:
notifyReactionsActive = False
@ -5802,9 +5958,14 @@ class PubServer(BaseHTTPRequestHandler):
if fields['notifyReactions'] == 'on' and \
not hideReactionButtonActive:
notifyReactionsActive = True
try:
with open(notifyReactionsFilename,
'w+') as rFile:
rFile.write('\n')
except OSError:
print('EX: unable to write ' +
'notify reactions ' +
notifyReactionsFilename)
if not notifyReactionsActive:
if os.path.isfile(notifyReactionsFilename):
try:
@ -5867,8 +6028,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \
'/filters.txt'
if fields.get('filteredWords'):
try:
with open(filterFilename, 'w+') as filterfile:
filterfile.write(fields['filteredWords'])
except OSError:
print('EX: unable to write filter ' +
filterFilename)
else:
if os.path.isfile(filterFilename):
try:
@ -5883,8 +6048,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \
'/replacewords.txt'
if fields.get('switchWords'):
try:
with open(switchFilename, 'w+') as switchfile:
switchfile.write(fields['switchWords'])
except OSError:
print('EX: unable to write switches ' +
switchFilename)
else:
if os.path.isfile(switchFilename):
try:
@ -5899,8 +6068,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \
'/autotags.txt'
if fields.get('autoTags'):
try:
with open(autoTagsFilename, 'w+') as autoTagsFile:
autoTagsFile.write(fields['autoTags'])
except OSError:
print('EX: unable to write auto tags ' +
autoTagsFilename)
else:
if os.path.isfile(autoTagsFilename):
try:
@ -5915,8 +6088,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \
'/autocw.txt'
if fields.get('autoCW'):
try:
with open(autoCWFilename, 'w+') as autoCWFile:
autoCWFile.write(fields['autoCW'])
except OSError:
print('EX: unable to write auto CW ' +
autoCWFilename)
else:
if os.path.isfile(autoCWFilename):
try:
@ -5931,8 +6108,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \
'/blocking.txt'
if fields.get('blocked'):
try:
with open(blockedFilename, 'w+') as blockedfile:
blockedfile.write(fields['blocked'])
except OSError:
print('EX: unable to write blocked accounts ' +
blockedFilename)
else:
if os.path.isfile(blockedFilename):
try:
@ -5949,8 +6130,13 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \
'/dmAllowedinstances.txt'
if fields.get('dmAllowedInstances'):
with open(dmAllowedInstancesFilename, 'w+') as aFile:
try:
with open(dmAllowedInstancesFilename,
'w+') as aFile:
aFile.write(fields['dmAllowedInstances'])
except OSError:
print('EX: unable to write allowed DM instances ' +
dmAllowedInstancesFilename)
else:
if os.path.isfile(dmAllowedInstancesFilename):
try:
@ -5966,8 +6152,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \
'/allowedinstances.txt'
if fields.get('allowedInstances'):
try:
with open(allowedInstancesFilename, 'w+') as aFile:
aFile.write(fields['allowedInstances'])
except OSError:
print('EX: unable to write allowed instances ' +
allowedInstancesFilename)
else:
if os.path.isfile(allowedInstancesFilename):
try:
@ -6021,8 +6211,13 @@ class PubServer(BaseHTTPRequestHandler):
baseDir + '/accounts/peertube.txt'
if fields.get('ptInstances'):
self.server.peertubeInstances.clear()
with open(peertubeInstancesFile, 'w+') as aFile:
try:
with open(peertubeInstancesFile,
'w+') as aFile:
aFile.write(fields['ptInstances'])
except OSError:
print('EX: unable to write peertube ' +
peertubeInstancesFile)
ptInstancesList = \
fields['ptInstances'].split('\n')
if ptInstancesList:
@ -6048,8 +6243,12 @@ class PubServer(BaseHTTPRequestHandler):
acctDir(baseDir, nickname, domain) + \
'/gitprojects.txt'
if fields.get('gitProjects'):
try:
with open(gitProjectsFilename, 'w+') as aFile:
aFile.write(fields['gitProjects'].lower())
except OSError:
print('EX: unable to write git ' +
gitProjectsFilename)
else:
if os.path.isfile(gitProjectsFilename):
try:
@ -6299,8 +6498,13 @@ class PubServer(BaseHTTPRequestHandler):
return
else:
if os.path.isfile(faviconFilename):
favBinary = None
try:
with open(faviconFilename, 'rb') as favFile:
favBinary = favFile.read()
except OSError:
print('EX: unable to read favicon ' + faviconFilename)
if favBinary:
self._set_headers_etag(faviconFilename,
favType,
favBinary, None,
@ -6345,8 +6549,13 @@ class PubServer(BaseHTTPRequestHandler):
filename = path.split('/exports/', 1)[1]
filename = baseDir + '/exports/' + filename
if os.path.isfile(filename):
exportBinary = None
try:
with open(filename, 'rb') as fp:
exportBinary = fp.read()
except OSError:
print('EX: unable to read theme export ' + filename)
if exportBinary:
exportType = 'application/zip'
self._set_headers_etag(filename, exportType,
exportBinary, None,
@ -6394,8 +6603,13 @@ class PubServer(BaseHTTPRequestHandler):
return
else:
if os.path.isfile(fontFilename):
fontBinary = None
try:
with open(fontFilename, 'rb') as fontFile:
fontBinary = fontFile.read()
except OSError:
print('EX: unable to load font ' + fontFilename)
if fontBinary:
self._set_headers_etag(fontFilename,
fontType,
fontBinary, None,
@ -6818,8 +7032,13 @@ class PubServer(BaseHTTPRequestHandler):
lastModifiedTimeStr = \
lastModifiedTime.strftime('%a, %d %b %Y %H:%M:%S GMT')
mediaBinary = None
try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read media binary ' + mediaFilename)
if mediaBinary:
self._set_headers_etag(mediaFilename, mediaFileType,
mediaBinary, None,
None, True,
@ -6851,8 +7070,11 @@ class PubServer(BaseHTTPRequestHandler):
ontologyFileType = 'application/ld+json'
if os.path.isfile(ontologyFilename):
ontologyFile = None
try:
with open(ontologyFilename, 'r') as fp:
ontologyFile = fp.read()
except OSError:
print('EX: unable to read ontology ' + ontologyFilename)
if ontologyFile:
ontologyFile = \
ontologyFile.replace('static.datafoodconsortium.org',
@ -6890,8 +7112,13 @@ class PubServer(BaseHTTPRequestHandler):
return
mediaImageType = getImageMimeType(emojiFilename)
mediaBinary = None
try:
with open(emojiFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read emoji image ' + emojiFilename)
if mediaBinary:
self._set_headers_etag(emojiFilename,
mediaImageType,
mediaBinary, None,
@ -6938,8 +7165,13 @@ class PubServer(BaseHTTPRequestHandler):
return
else:
if os.path.isfile(mediaFilename):
mediaBinary = None
try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read icon image ' + mediaFilename)
if mediaBinary:
mimeType = mediaFileMimeType(mediaFilename)
self._set_headers_etag(mediaFilename,
mimeType,
@ -6980,8 +7212,13 @@ class PubServer(BaseHTTPRequestHandler):
self._304()
return
if os.path.isfile(mediaFilename):
mediaBinary = None
try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read help image ' + mediaFilename)
if mediaBinary:
mimeType = mediaFileMimeType(mediaFilename)
self._set_headers_etag(mediaFilename,
mimeType,
@ -7005,8 +7242,13 @@ class PubServer(BaseHTTPRequestHandler):
# The file has not changed
self._304()
return
mediaBinary = None
try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read cached avatar ' + mediaFilename)
if mediaBinary:
mimeType = mediaFileMimeType(mediaFilename)
self._set_headers_etag(mediaFilename,
mimeType,
@ -12404,8 +12646,13 @@ class PubServer(BaseHTTPRequestHandler):
return True
mediaFileType = getImageMimeType(mediaFilename)
mediaBinary = None
try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read binary ' + mediaFilename)
if mediaBinary:
self._set_headers_etag(mediaFilename,
mediaFileType,
mediaBinary, None,
@ -12474,8 +12721,13 @@ class PubServer(BaseHTTPRequestHandler):
lastModifiedTime.strftime('%a, %d %b %Y %H:%M:%S GMT')
mediaImageType = getImageMimeType(avatarFile)
mediaBinary = None
try:
with open(avatarFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read avatar ' + avatarFilename)
if mediaBinary:
self._set_headers_etag(avatarFilename, mediaImageType,
mediaBinary, None,
refererDomain, True,
@ -15885,8 +16137,13 @@ class PubServer(BaseHTTPRequestHandler):
# check that the file exists
filename = self.server.baseDir + self.path
if os.path.isfile(filename):
content = None
try:
with open(filename, 'r', encoding='utf-8') as File:
content = File.read()
except OSError:
print('EX: unable to read file ' + filename)
if content:
contentJson = json.loads(content)
msg = json.dumps(contentJson,
ensure_ascii=False).encode('utf-8')
@ -15949,8 +16206,14 @@ class PubServer(BaseHTTPRequestHandler):
print('EX: do_HEAD unable to read ' +
mediaTagFilename)
else:
mediaBinary = None
try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
except OSError:
print('EX: unable to read media binary ' +
mediaFilename)
if mediaBinary:
etag = md5(mediaBinary).hexdigest() # nosec
try:
with open(mediaTagFilename, 'w+') as etagFile:

View File

@ -18,8 +18,11 @@ def addFilter(baseDir: str, nickname: str, domain: str, words: str) -> bool:
if os.path.isfile(filtersFilename):
if words in open(filtersFilename).read():
return False
try:
with open(filtersFilename, 'a+') as filtersFile:
filtersFile.write(words + '\n')
except OSError:
print('EX: unable to append filters ' + filtersFilename)
return True
@ -35,8 +38,11 @@ def addGlobalFilter(baseDir: str, words: str) -> bool:
if os.path.isfile(filtersFilename):
if words in open(filtersFilename).read():
return False
try:
with open(filtersFilename, 'a+') as filtersFile:
filtersFile.write(words + '\n')
except OSError:
print('EX: unable to append filters ' + filtersFilename)
return True
@ -50,12 +56,15 @@ def removeFilter(baseDir: str, nickname: str, domain: str,
if words not in open(filtersFilename).read():
return False
newFiltersFilename = filtersFilename + '.new'
try:
with open(filtersFilename, 'r') as fp:
with open(newFiltersFilename, 'w+') as fpnew:
for line in fp:
line = line.replace('\n', '')
if line != words:
fpnew.write(line + '\n')
except OSError as e:
print('EX: unable to remove filter ' + filtersFilename + ' ' + str(e))
if os.path.isfile(newFiltersFilename):
os.rename(newFiltersFilename, filtersFilename)
return True
@ -71,12 +80,16 @@ def removeGlobalFilter(baseDir: str, words: str) -> bool:
if words not in open(filtersFilename).read():
return False
newFiltersFilename = filtersFilename + '.new'
try:
with open(filtersFilename, 'r') as fp:
with open(newFiltersFilename, 'w+') as fpnew:
for line in fp:
line = line.replace('\n', '')
if line != words:
fpnew.write(line + '\n')
except OSError as e:
print('EX: unable to remove global filter ' +
filtersFilename + ' ' + str(e))
if os.path.isfile(newFiltersFilename):
os.rename(newFiltersFilename, filtersFilename)
return True
@ -100,6 +113,7 @@ def _isFilteredBase(filename: str, content: str) -> bool:
if not os.path.isfile(filename):
return False
try:
with open(filename, 'r') as fp:
for line in fp:
filterStr = line.replace('\n', '').replace('\r', '')
@ -116,6 +130,8 @@ def _isFilteredBase(filename: str, content: str) -> bool:
if word not in content:
return False
return True
except OSError as e:
print('EX: _isFilteredBase ' + filename + ' ' + str(e))
return False

View File

@ -58,8 +58,12 @@ def createInitialLastSeen(baseDir: str, httpPrefix: str) -> None:
lastSeenDir = accountDir + '/lastseen'
if not os.path.isdir(lastSeenDir):
os.mkdir(lastSeenDir)
followingHandles = []
try:
with open(followingFilename, 'r') as fp:
followingHandles = fp.readlines()
except OSError:
print('EX: createInitialLastSeen ' + followingFilename)
for handle in followingHandles:
if '#' in handle:
continue
@ -74,8 +78,12 @@ def createInitialLastSeen(baseDir: str, httpPrefix: str) -> None:
lastSeenFilename = \
lastSeenDir + '/' + actor.replace('/', '#') + '.txt'
if not os.path.isfile(lastSeenFilename):
try:
with open(lastSeenFilename, 'w+') as fp:
fp.write(str(100))
except OSError:
print('EX: createInitialLastSeen 2 ' +
lastSeenFilename)
break
@ -124,6 +132,7 @@ def _removeFromFollowBase(baseDir: str,
break
if not actorFound:
return
try:
with open(approveFollowsFilename + '.new', 'w+') as approvefilenew:
with open(approveFollowsFilename, 'r') as approvefile:
if not acceptDenyActor:
@ -134,6 +143,9 @@ def _removeFromFollowBase(baseDir: str,
for approveHandle in approvefile:
if acceptDenyActor not in approveHandle:
approvefilenew.write(approveHandle)
except OSError as e:
print('EX: _removeFromFollowBase ' +
approveFollowsFilename + ' ' + str(e))
os.rename(approveFollowsFilename + '.new', approveFollowsFilename)
@ -218,8 +230,11 @@ def getFollowerDomains(baseDir: str, nickname: str, domain: str) -> []:
return []
lines = []
try:
with open(followersFile, 'r') as fpFollowers:
lines = fpFollowers.readlines()
except OSError:
print('EX: getFollowerDomains ' + followersFile)
domainsList = []
for handle in lines:
@ -251,8 +266,11 @@ def isFollowerOfPerson(baseDir: str, nickname: str, domain: str,
alreadyFollowing = False
followersStr = ''
try:
with open(followersFile, 'r') as fpFollowers:
followersStr = fpFollowers.read()
except OSError:
print('EX: isFollowerOfPerson ' + followersFile)
if handle in followersStr:
alreadyFollowing = True
@ -294,8 +312,13 @@ def unfollowAccount(baseDir: str, nickname: str, domain: str,
print('DEBUG: handle to unfollow ' + handleToUnfollow +
' is not in ' + filename)
return
lines = []
try:
with open(filename, 'r') as f:
lines = f.readlines()
except OSError:
print('EX: unfollowAccount ' + filename)
if lines:
try:
with open(filename, 'w+') as f:
for line in lines:
@ -312,8 +335,11 @@ def unfollowAccount(baseDir: str, nickname: str, domain: str,
if os.path.isfile(unfollowedFilename):
if handleToUnfollowLower not in \
open(unfollowedFilename).read().lower():
try:
with open(unfollowedFilename, 'a+') as f:
f.write(handleToUnfollow + '\n')
except OSError:
print('EX: unable to append ' + unfollowedFilename)
else:
try:
with open(unfollowedFilename, 'w+') as f:
@ -371,8 +397,13 @@ def _getNoOfFollows(baseDir: str, nickname: str, domain: str,
if not os.path.isfile(filename):
return 0
ctr = 0
lines = []
try:
with open(filename, 'r') as f:
lines = f.readlines()
except OSError:
print('EX: _getNoOfFollows ' + filename)
if lines:
for line in lines:
if '#' in line:
continue
@ -483,8 +514,12 @@ def getFollowingFeed(baseDir: str, domain: str, port: int, path: str,
currPage = 1
pageCtr = 0
totalCtr = 0
lines = []
try:
with open(filename, 'r') as f:
lines = f.readlines()
except OSError:
print('EX: getFollowingFeed ' + filename)
for line in lines:
if '#' not in line:
if '@' in line and not line.startswith('http'):
@ -568,8 +603,13 @@ def _noOfFollowRequests(baseDir: str,
if not os.path.isfile(approveFollowsFilename):
return 0
ctr = 0
lines = []
try:
with open(approveFollowsFilename, 'r') as f:
lines = f.readlines()
except OSError:
print('EX: _noOfFollowRequests ' + approveFollowsFilename)
if lines:
if followType == "onion":
for fileLine in lines:
if '.onion' in fileLine:
@ -607,8 +647,11 @@ def _storeFollowRequest(baseDir: str,
alreadyFollowing = False
followersStr = ''
try:
with open(followersFilename, 'r') as fpFollowers:
followersStr = fpFollowers.read()
except OSError:
print('EX: _storeFollowRequest ' + followersFilename)
if approveHandle in followersStr:
alreadyFollowing = True
@ -649,8 +692,11 @@ def _storeFollowRequest(baseDir: str,
if os.path.isfile(approveFollowsFilename):
if approveHandle not in open(approveFollowsFilename).read():
try:
with open(approveFollowsFilename, 'a+') as fp:
fp.write(approveHandleStored + '\n')
except OSError:
print('EX: _storeFollowRequest 2 ' + approveFollowsFilename)
else:
if debug:
print('DEBUG: ' + approveHandleStored +
@ -660,7 +706,7 @@ def _storeFollowRequest(baseDir: str,
with open(approveFollowsFilename, 'w+') as fp:
fp.write(approveHandleStored + '\n')
except OSError:
print('EX: unable to write ' + approveFollowsFilename)
print('EX: _storeFollowRequest 3 ' + approveFollowsFilename)
# store the follow request in its own directory
# We don't rely upon the inbox because items in there could expire
@ -1053,11 +1099,14 @@ def sendFollowRequest(session, baseDir: str,
if os.path.isfile(unfollowedFilename):
if followHandle in open(unfollowedFilename).read():
unfollowedFile = None
try:
with open(unfollowedFilename, 'r') as fp:
unfollowedFile = fp.read()
except OSError:
print('EX: sendFollowRequest ' + unfollowedFilename)
if unfollowedFile:
unfollowedFile = \
unfollowedFile.replace(followHandle + '\n', '')
if unfollowedFile:
try:
with open(unfollowedFilename, 'w+') as fp:
fp.write(unfollowedFile)

View File

@ -44,13 +44,18 @@ def receivingCalendarEvents(baseDir: str, nickname: str, domain: str,
if not os.path.isfile(followingFilename):
return False
# create a new calendar file from the following file
followingHandles = None
try:
with open(followingFilename, 'r') as followingFile:
followingHandles = followingFile.read()
except OSError:
print('EX: receivingCalendarEvents ' + followingFilename)
if followingHandles:
try:
with open(calendarFilename, 'w+') as fp:
fp.write(followingHandles)
except OSError:
print('EX: unable to write ' + calendarFilename)
print('EX: receivingCalendarEvents 2 ' + calendarFilename)
return handle + '\n' in open(calendarFilename).read()
@ -83,14 +88,20 @@ def _receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
followingHandles = ''
if os.path.isfile(calendarFilename):
print('Calendar file exists')
try:
with open(calendarFilename, 'r') as calendarFile:
followingHandles = calendarFile.read()
except OSError:
print('EX: _receiveCalendarEvents ' + calendarFilename)
else:
# create a new calendar file from the following file
print('Creating calendar file ' + calendarFilename)
followingHandles = ''
try:
with open(followingFilename, 'r') as followingFile:
followingHandles = followingFile.read()
except OSError:
print('EX: _receiveCalendarEvents 2 ' + calendarFilename)
if add:
try:
with open(calendarFilename, 'w+') as fp:
@ -110,7 +121,7 @@ def _receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
with open(calendarFilename, 'w+') as fp:
fp.write(followingHandles)
except OSError:
print('EX: unable to write ' + calendarFilename)
print('EX: _receiveCalendarEvents 3 ' + calendarFilename)
else:
print(handle + ' not in followingCalendar.txt')
# not already in the calendar file
@ -121,7 +132,7 @@ def _receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
with open(calendarFilename, 'w+') as fp:
fp.write(followingHandles)
except OSError:
print('EX: unable to write ' + calendarFilename)
print('EX: _receiveCalendarEvents 4 ' + calendarFilename)
def addPersonToCalendar(baseDir: str, nickname: str, domain: str,

2
git.py
View File

@ -217,5 +217,5 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str,
patchFile.write(patchStr)
return True
except OSError as e:
print('EX: unable to write patch ' + patchFilename + ' ' + str(e))
print('EX: receiveGitPatch ' + patchFilename + ' ' + str(e))
return False