mirror of https://gitlab.com/bashrc2/epicyon
Exception handling
parent
358cd2ea40
commit
3c6122c56c
40
announce.py
40
announce.py
|
@ -67,8 +67,14 @@ def undoAnnounceCollectionEntry(postFilename: str,actor: str,debug: bool) -> Non
|
||||||
collection within a post. Note that the "shares" collection has no relation
|
collection within a post. Note that the "shares" collection has no relation
|
||||||
to shared items in shares.py. It's shares of posts, not shares of physical objects.
|
to shared items in shares.py. It's shares of posts, not shares of physical objects.
|
||||||
"""
|
"""
|
||||||
with open(postFilename, 'r') as fp:
|
postJsonObject=None
|
||||||
postJsonObject=commentjson.load(fp)
|
try:
|
||||||
|
with open(postFilename, 'r') as fp:
|
||||||
|
postJsonObject=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if postJsonObject:
|
||||||
if not postJsonObject.get('type'):
|
if not postJsonObject.get('type'):
|
||||||
return
|
return
|
||||||
if postJsonObject['type']!='Create':
|
if postJsonObject['type']!='Create':
|
||||||
|
@ -103,16 +109,24 @@ def undoAnnounceCollectionEntry(postFilename: str,actor: str,debug: bool) -> Non
|
||||||
del postJsonObject['object']['shares']
|
del postJsonObject['object']['shares']
|
||||||
else:
|
else:
|
||||||
postJsonObject['object']['shares']['totalItems']=len(postJsonObject['object']['shares']['items'])
|
postJsonObject['object']['shares']['totalItems']=len(postJsonObject['object']['shares']['items'])
|
||||||
with open(postFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
with open(postFilename, 'w') as fp:
|
||||||
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
def updateAnnounceCollection(postFilename: str,actor: str,debug: bool) -> None:
|
def updateAnnounceCollection(postFilename: str,actor: str,debug: bool) -> None:
|
||||||
"""Updates the announcements collection within a post
|
"""Updates the announcements collection within a post
|
||||||
Confusingly this is known as "shares", but isn't the same as shared items within shares.py
|
Confusingly this is known as "shares", but isn't the same as shared items within shares.py
|
||||||
It's shares of posts, not shares of physical objects.
|
It's shares of posts, not shares of physical objects.
|
||||||
"""
|
"""
|
||||||
with open(postFilename, 'r') as fp:
|
postJsonObject=None
|
||||||
postJsonObject=commentjson.load(fp)
|
try:
|
||||||
|
with open(postFilename, 'r') as fp:
|
||||||
|
postJsonObject=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
if postJsonObject:
|
||||||
if not postJsonObject.get('object'):
|
if not postJsonObject.get('object'):
|
||||||
if debug:
|
if debug:
|
||||||
pprint(postJsonObject)
|
pprint(postJsonObject)
|
||||||
|
@ -154,8 +168,11 @@ def updateAnnounceCollection(postFilename: str,actor: str,debug: bool) -> None:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: saving post with shares (announcements) added')
|
print('DEBUG: saving post with shares (announcements) added')
|
||||||
pprint(postJsonObject)
|
pprint(postJsonObject)
|
||||||
with open(postFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
with open(postFilename, 'w') as fp:
|
||||||
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
def announcedByPerson(postJsonObject: {}, nickname: str,domain: str) -> bool:
|
def announcedByPerson(postJsonObject: {}, nickname: str,domain: str) -> bool:
|
||||||
"""Returns True if the given post is announced by the given person
|
"""Returns True if the given post is announced by the given person
|
||||||
|
@ -218,8 +235,11 @@ def createAnnounce(session,baseDir: str,federationList: [], \
|
||||||
if saveToFile:
|
if saveToFile:
|
||||||
outboxDir = createOutboxDir(nickname,domain,baseDir)
|
outboxDir = createOutboxDir(nickname,domain,baseDir)
|
||||||
filename=outboxDir+'/'+newAnnounceId.replace('/','#')+'.json'
|
filename=outboxDir+'/'+newAnnounceId.replace('/','#')+'.json'
|
||||||
with open(filename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(newAnnounce, fp, indent=4, sort_keys=False)
|
with open(filename, 'w') as fp:
|
||||||
|
commentjson.dump(newAnnounce, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
announceNickname=None
|
announceNickname=None
|
||||||
announceDomain=None
|
announceDomain=None
|
||||||
|
|
|
@ -26,11 +26,19 @@ def setAvailability(baseDir: str,nickname: str,domain: str, \
|
||||||
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
||||||
if not os.path.isfile(actorFilename):
|
if not os.path.isfile(actorFilename):
|
||||||
return False
|
return False
|
||||||
with open(actorFilename, 'r') as fp:
|
actorJson=None
|
||||||
actorJson=commentjson.load(fp)
|
try:
|
||||||
|
with open(actorFilename, 'r') as fp:
|
||||||
|
actorJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
if actorJson:
|
||||||
actorJson['availability']=status
|
actorJson['availability']=status
|
||||||
with open(actorFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
with open(actorFilename, 'w') as fp:
|
||||||
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def getAvailability(baseDir: str,nickname: str,domain: str) -> str:
|
def getAvailability(baseDir: str,nickname: str,domain: str) -> str:
|
||||||
|
@ -39,8 +47,13 @@ def getAvailability(baseDir: str,nickname: str,domain: str) -> str:
|
||||||
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
||||||
if not os.path.isfile(actorFilename):
|
if not os.path.isfile(actorFilename):
|
||||||
return False
|
return False
|
||||||
with open(actorFilename, 'r') as fp:
|
actorJson=None
|
||||||
actorJson=commentjson.load(fp)
|
try:
|
||||||
|
with open(actorFilename, 'r') as fp:
|
||||||
|
actorJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
if actorJson:
|
||||||
if not actorJson.get('availability'):
|
if not actorJson.get('availability'):
|
||||||
return None
|
return None
|
||||||
return actorJson['availability']
|
return actorJson['availability']
|
||||||
|
|
7
cache.py
7
cache.py
|
@ -26,8 +26,11 @@ def storePersonInCache(baseDir: str,personUrl: str,personJson: {},personCache: {
|
||||||
if os.path.isdir(baseDir+'/cache/actors'):
|
if os.path.isdir(baseDir+'/cache/actors'):
|
||||||
cacheFilename=baseDir+'/cache/actors/'+personUrl.replace('/','#')+'.json'
|
cacheFilename=baseDir+'/cache/actors/'+personUrl.replace('/','#')+'.json'
|
||||||
if not os.path.isfile(cacheFilename):
|
if not os.path.isfile(cacheFilename):
|
||||||
with open(cacheFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
with open(cacheFilename, 'w') as fp:
|
||||||
|
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
def getPersonFromCache(baseDir: str,personUrl: str,personCache: {}) -> {}:
|
def getPersonFromCache(baseDir: str,personUrl: str,personCache: {}) -> {}:
|
||||||
"""Get an actor from the cache
|
"""Get an actor from the cache
|
||||||
|
|
|
@ -127,8 +127,11 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
||||||
|
|
||||||
# if the capability already exists then load it from file
|
# if the capability already exists then load it from file
|
||||||
if os.path.isfile(ocapFilename):
|
if os.path.isfile(ocapFilename):
|
||||||
with open(ocapFilename, 'r') as fp:
|
try:
|
||||||
ocapAccept=commentjson.load(fp)
|
with open(ocapFilename, 'r') as fp:
|
||||||
|
ocapAccept=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
# otherwise create a new capability
|
# otherwise create a new capability
|
||||||
if not ocapAccept:
|
if not ocapAccept:
|
||||||
acceptedActorNickname=getNicknameFromActor(acceptedActor)
|
acceptedActorNickname=getNicknameFromActor(acceptedActor)
|
||||||
|
@ -152,8 +155,11 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
||||||
ocapAccept['actor']=httpPrefix+"://"+fullDomain+'/users/'+nickname
|
ocapAccept['actor']=httpPrefix+"://"+fullDomain+'/users/'+nickname
|
||||||
|
|
||||||
if saveToFile:
|
if saveToFile:
|
||||||
with open(ocapFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(ocapAccept, fp, indent=4, sort_keys=False)
|
with open(ocapFilename, 'w') as fp:
|
||||||
|
commentjson.dump(ocapAccept, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return ocapAccept
|
return ocapAccept
|
||||||
|
|
||||||
def capabilitiesGrantedSave(baseDir :str,nickname :str,domain :str,ocap: {}) -> bool:
|
def capabilitiesGrantedSave(baseDir :str,nickname :str,domain :str,ocap: {}) -> bool:
|
||||||
|
@ -165,8 +171,11 @@ def capabilitiesGrantedSave(baseDir :str,nickname :str,domain :str,ocap: {}) ->
|
||||||
ocapFilename=getOcapFilename(baseDir,nickname,domain,ocap['actor'],'granted')
|
ocapFilename=getOcapFilename(baseDir,nickname,domain,ocap['actor'],'granted')
|
||||||
if not ocapFilename:
|
if not ocapFilename:
|
||||||
return False
|
return False
|
||||||
with open(ocapFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(ocap, fp, indent=4, sort_keys=False)
|
with open(ocapFilename, 'w') as fp:
|
||||||
|
commentjson.dump(ocap, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def capabilitiesUpdate(baseDir: str,httpPrefix: str, \
|
def capabilitiesUpdate(baseDir: str,httpPrefix: str, \
|
||||||
|
@ -208,8 +217,11 @@ def capabilitiesUpdate(baseDir: str,httpPrefix: str, \
|
||||||
}
|
}
|
||||||
|
|
||||||
# read the existing capability
|
# read the existing capability
|
||||||
with open(ocapFilename, 'r') as fp:
|
try:
|
||||||
ocapJson=commentjson.load(fp)
|
with open(ocapFilename, 'r') as fp:
|
||||||
|
ocapJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
# set the new capabilities list. eg. ["inbox:write","objects:read"]
|
# set the new capabilities list. eg. ["inbox:write","objects:read"]
|
||||||
ocapJson['capability']=updateCaps
|
ocapJson['capability']=updateCaps
|
||||||
|
@ -228,9 +240,12 @@ def capabilitiesUpdate(baseDir: str,httpPrefix: str, \
|
||||||
ocapUpdate['object']=ocapJson
|
ocapUpdate['object']=ocapJson
|
||||||
|
|
||||||
# save it again
|
# save it again
|
||||||
with open(ocapFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(ocapJson, fp, indent=4, sort_keys=False)
|
with open(ocapFilename, 'w') as fp:
|
||||||
|
commentjson.dump(ocapJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
return ocapUpdate
|
return ocapUpdate
|
||||||
|
|
||||||
def capabilitiesReceiveUpdate(baseDir :str, \
|
def capabilitiesReceiveUpdate(baseDir :str, \
|
||||||
|
@ -251,12 +266,21 @@ def capabilitiesReceiveUpdate(baseDir :str, \
|
||||||
print(ocapFilename)
|
print(ocapFilename)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
with open(ocapFilename, 'r') as fp:
|
ocapJson=None
|
||||||
ocapJson=commentjson.load(fp)
|
try:
|
||||||
|
with open(ocapFilename, 'r') as fp:
|
||||||
|
ocapJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if ocapJson:
|
||||||
ocapJson['id']=newCapabilitiesId
|
ocapJson['id']=newCapabilitiesId
|
||||||
ocapJson['capability']=capabilityList
|
ocapJson['capability']=capabilityList
|
||||||
|
|
||||||
with open(ocapFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(ocapJson, fp, indent=4, sort_keys=False)
|
with open(ocapFilename, 'w') as fp:
|
||||||
return True
|
commentjson.dump(ocapJson, fp, indent=4, sort_keys=False)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -29,8 +29,11 @@ def setConfigParam(baseDir: str, variableName: str, variableValue) -> None:
|
||||||
"""
|
"""
|
||||||
createConfig(baseDir)
|
createConfig(baseDir)
|
||||||
configFilename=baseDir+'/config.json'
|
configFilename=baseDir+'/config.json'
|
||||||
with open(configFilename, 'r') as fp:
|
try:
|
||||||
configJson=commentjson.load(fp)
|
with open(configFilename, 'r') as fp:
|
||||||
|
configJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
configJson[variableName]=variableValue
|
configJson[variableName]=variableValue
|
||||||
try:
|
try:
|
||||||
with open(configFilename, 'w') as fp:
|
with open(configFilename, 'w') as fp:
|
||||||
|
|
14
daemon.py
14
daemon.py
|
@ -3014,13 +3014,19 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
os.remove(allowedInstancesFilename)
|
os.remove(allowedInstancesFilename)
|
||||||
# save actor json file within accounts
|
# save actor json file within accounts
|
||||||
if actorChanged:
|
if actorChanged:
|
||||||
with open(actorFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
with open(actorFilename, 'w') as fp:
|
||||||
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
# also copy to the actors cache and personCache in memory
|
# also copy to the actors cache and personCache in memory
|
||||||
storePersonInCache(self.server.baseDir,actorJson['id'],actorJson,self.server.personCache)
|
storePersonInCache(self.server.baseDir,actorJson['id'],actorJson,self.server.personCache)
|
||||||
actorCacheFilename=self.server.baseDir+'/cache/actors/'+actorJson['id'].replace('/','#')+'.json'
|
actorCacheFilename=self.server.baseDir+'/cache/actors/'+actorJson['id'].replace('/','#')+'.json'
|
||||||
with open(actorCacheFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
with open(actorCacheFilename, 'w') as fp:
|
||||||
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
# send actor update to followers
|
# send actor update to followers
|
||||||
updateActorJson={
|
updateActorJson={
|
||||||
'type': 'Update',
|
'type': 'Update',
|
||||||
|
|
29
follow.py
29
follow.py
|
@ -319,8 +319,13 @@ def followApprovalRequired(baseDir: str,nicknameToFollow: str, \
|
||||||
domainToFollow=domainToFollow.split(':')[0]
|
domainToFollow=domainToFollow.split(':')[0]
|
||||||
actorFilename=baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow+'.json'
|
actorFilename=baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow+'.json'
|
||||||
if os.path.isfile(actorFilename):
|
if os.path.isfile(actorFilename):
|
||||||
with open(actorFilename, 'r') as fp:
|
actor=None
|
||||||
actor=commentjson.load(fp)
|
try:
|
||||||
|
with open(actorFilename, 'r') as fp:
|
||||||
|
actor=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
if actor:
|
||||||
if actor.get('manuallyApprovesFollowers'):
|
if actor.get('manuallyApprovesFollowers'):
|
||||||
manuallyApproveFollows=actor['manuallyApprovesFollowers']
|
manuallyApproveFollows=actor['manuallyApprovesFollowers']
|
||||||
else:
|
else:
|
||||||
|
@ -384,9 +389,12 @@ def storeFollowRequest(baseDir: str, \
|
||||||
if not os.path.isdir(requestsDir):
|
if not os.path.isdir(requestsDir):
|
||||||
os.mkdir(requestsDir)
|
os.mkdir(requestsDir)
|
||||||
followActivityfilename=requestsDir+'/'+approveHandle+'.follow'
|
followActivityfilename=requestsDir+'/'+approveHandle+'.follow'
|
||||||
with open(followActivityfilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(followJson, fp, indent=4, sort_keys=False)
|
with open(followActivityfilename, 'w') as fp:
|
||||||
return True
|
commentjson.dump(followJson, fp, indent=4, sort_keys=False)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
|
def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
|
||||||
|
@ -828,9 +836,14 @@ def getFollowersOfActor(baseDir :str,actor :str,debug: bool) -> {}:
|
||||||
ocapFilename=baseDir+'/accounts/'+account+'/ocap/accept/'+httpPrefix+':##'+domain+':'+str(port)+'#users#'+nickname+'.json'
|
ocapFilename=baseDir+'/accounts/'+account+'/ocap/accept/'+httpPrefix+':##'+domain+':'+str(port)+'#users#'+nickname+'.json'
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: checking capabilities of'+account)
|
print('DEBUG: checking capabilities of'+account)
|
||||||
if os.path.isfile(ocapFilename):
|
if os.path.isfile(ocapFilename):
|
||||||
with open(ocapFilename, 'r') as fp:
|
ocapJson=None
|
||||||
ocapJson=commentjson.load(fp)
|
try:
|
||||||
|
with open(ocapFilename, 'r') as fp:
|
||||||
|
ocapJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
if ocapJson:
|
||||||
if ocapJson.get('id'):
|
if ocapJson.get('id'):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: capabilities id found for '+account)
|
print('DEBUG: capabilities id found for '+account)
|
||||||
|
|
40
inbox.py
40
inbox.py
|
@ -282,9 +282,11 @@ def savePostToInboxQueue(baseDir: str,httpPrefix: str, \
|
||||||
if debug:
|
if debug:
|
||||||
print('Inbox queue item created')
|
print('Inbox queue item created')
|
||||||
pprint(newQueueItem)
|
pprint(newQueueItem)
|
||||||
|
try:
|
||||||
with open(filename, 'w') as fp:
|
with open(filename, 'w') as fp:
|
||||||
commentjson.dump(newQueueItem, fp, indent=4, sort_keys=False)
|
commentjson.dump(newQueueItem, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
def inboxCheckCapabilities(baseDir :str,nickname :str,domain :str, \
|
def inboxCheckCapabilities(baseDir :str,nickname :str,domain :str, \
|
||||||
|
@ -669,9 +671,12 @@ def personReceiveUpdate(baseDir: str, \
|
||||||
# save to cache in memory
|
# save to cache in memory
|
||||||
storePersonInCache(baseDir,personJson['id'],personJson,personCache)
|
storePersonInCache(baseDir,personJson['id'],personJson,personCache)
|
||||||
# save to cache on file
|
# save to cache on file
|
||||||
with open(actorFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
with open(actorFilename, 'w') as fp:
|
||||||
print('actor updated for '+personJson['id'])
|
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
||||||
|
print('actor updated for '+personJson['id'])
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
# remove avatar if it exists so that it will be refreshed later
|
# remove avatar if it exists so that it will be refreshed later
|
||||||
# when a timeline is constructed
|
# when a timeline is constructed
|
||||||
|
@ -1263,13 +1268,19 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
|
||||||
if messageJson.get('postNickname'):
|
if messageJson.get('postNickname'):
|
||||||
if validPostContent(messageJson['post'],maxMentions):
|
if validPostContent(messageJson['post'],maxMentions):
|
||||||
obtainReplyToAvatar(baseDir,personCache,messageJson['post'])
|
obtainReplyToAvatar(baseDir,personCache,messageJson['post'])
|
||||||
with open(destinationFilename, 'w+') as fp:
|
try:
|
||||||
commentjson.dump(messageJson['post'], fp, indent=4, sort_keys=False)
|
with open(destinationFilename, 'w+') as fp:
|
||||||
|
commentjson.dump(messageJson['post'], fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
else:
|
else:
|
||||||
if validPostContent(messageJson,maxMentions):
|
if validPostContent(messageJson,maxMentions):
|
||||||
obtainReplyToAvatar(baseDir,personCache,messageJson)
|
obtainReplyToAvatar(baseDir,personCache,messageJson)
|
||||||
with open(destinationFilename, 'w+') as fp:
|
try:
|
||||||
commentjson.dump(messageJson, fp, indent=4, sort_keys=False)
|
with open(destinationFilename, 'w+') as fp:
|
||||||
|
commentjson.dump(messageJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
if not os.path.isfile(destinationFilename):
|
if not os.path.isfile(destinationFilename):
|
||||||
return False
|
return False
|
||||||
|
@ -1613,9 +1624,12 @@ def runInboxQueue(projectVersion: str, \
|
||||||
if len(recipientsDictFollowers)>0:
|
if len(recipientsDictFollowers)>0:
|
||||||
sharedInboxPostFilename=queueJson['destination'].replace(inboxHandle,inboxHandle)
|
sharedInboxPostFilename=queueJson['destination'].replace(inboxHandle,inboxHandle)
|
||||||
if not os.path.isfile(sharedInboxPostFilename):
|
if not os.path.isfile(sharedInboxPostFilename):
|
||||||
with open(sharedInboxPostFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(queueJson['post'],fp,indent=4, \
|
with open(sharedInboxPostFilename, 'w') as fp:
|
||||||
sort_keys=False)
|
commentjson.dump(queueJson['post'],fp,indent=4, \
|
||||||
|
sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
# for posts addressed to specific accounts
|
# for posts addressed to specific accounts
|
||||||
for handle,capsId in recipientsDict.items():
|
for handle,capsId in recipientsDict.items():
|
||||||
|
|
36
like.py
36
like.py
|
@ -21,9 +21,15 @@ from posts import getPersonBox
|
||||||
|
|
||||||
def undoLikesCollectionEntry(postFilename: str,objectUrl: str,actor: str,debug: bool) -> None:
|
def undoLikesCollectionEntry(postFilename: str,objectUrl: str,actor: str,debug: bool) -> None:
|
||||||
"""Undoes a like for a particular actor
|
"""Undoes a like for a particular actor
|
||||||
"""
|
"""
|
||||||
with open(postFilename, 'r') as fp:
|
postJsonObject=None
|
||||||
postJsonObject=commentjson.load(fp)
|
try:
|
||||||
|
with open(postFilename, 'r') as fp:
|
||||||
|
postJsonObject=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if postJsonObject:
|
||||||
if not postJsonObject.get('type'):
|
if not postJsonObject.get('type'):
|
||||||
return
|
return
|
||||||
if postJsonObject['type']!='Create':
|
if postJsonObject['type']!='Create':
|
||||||
|
@ -60,8 +66,11 @@ def undoLikesCollectionEntry(postFilename: str,objectUrl: str,actor: str,debug:
|
||||||
del postJsonObject['object']['likes']
|
del postJsonObject['object']['likes']
|
||||||
else:
|
else:
|
||||||
postJsonObject['object']['likes']['totalItems']=len(postJsonObject['likes']['items'])
|
postJsonObject['object']['likes']['totalItems']=len(postJsonObject['likes']['items'])
|
||||||
with open(postFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
with open(postFilename, 'w') as fp:
|
||||||
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
def likedByPerson(postJsonObject: {}, nickname: str,domain: str) -> bool:
|
def likedByPerson(postJsonObject: {}, nickname: str,domain: str) -> bool:
|
||||||
"""Returns True if the given post is liked by the given person
|
"""Returns True if the given post is liked by the given person
|
||||||
|
@ -93,8 +102,14 @@ def noOfLikes(postJsonObject: {}) -> int:
|
||||||
def updateLikesCollection(postFilename: str,objectUrl: str, actor: str,debug: bool) -> None:
|
def updateLikesCollection(postFilename: str,objectUrl: str, actor: str,debug: bool) -> None:
|
||||||
"""Updates the likes collection within a post
|
"""Updates the likes collection within a post
|
||||||
"""
|
"""
|
||||||
with open(postFilename, 'r') as fp:
|
postJsonObject=None
|
||||||
postJsonObject=commentjson.load(fp)
|
try:
|
||||||
|
with open(postFilename, 'r') as fp:
|
||||||
|
postJsonObject=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if postJsonObject:
|
||||||
if not postJsonObject.get('object'):
|
if not postJsonObject.get('object'):
|
||||||
if debug:
|
if debug:
|
||||||
pprint(postJsonObject)
|
pprint(postJsonObject)
|
||||||
|
@ -133,8 +148,11 @@ def updateLikesCollection(postFilename: str,objectUrl: str, actor: str,debug: bo
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: saving post with likes added')
|
print('DEBUG: saving post with likes added')
|
||||||
pprint(postJsonObject)
|
pprint(postJsonObject)
|
||||||
with open(postFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
with open(postFilename, 'w') as fp:
|
||||||
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
def like(session,baseDir: str,federationList: [],nickname: str,domain: str,port: int, \
|
def like(session,baseDir: str,federationList: [],nickname: str,domain: str,port: int, \
|
||||||
ccList: [],httpPrefix: str,objectUrl: str,clientToServer: bool, \
|
ccList: [],httpPrefix: str,objectUrl: str,clientToServer: bool, \
|
||||||
|
|
|
@ -97,8 +97,13 @@ def manualApproveFollowRequest(session,baseDir: str, \
|
||||||
requestsDir=accountsDir+'/requests'
|
requestsDir=accountsDir+'/requests'
|
||||||
followActivityfilename=requestsDir+'/'+handle+'.follow'
|
followActivityfilename=requestsDir+'/'+handle+'.follow'
|
||||||
if os.path.isfile(followActivityfilename):
|
if os.path.isfile(followActivityfilename):
|
||||||
with open(followActivityfilename, 'r') as fp:
|
followJson=None
|
||||||
followJson=commentjson.load(fp)
|
try:
|
||||||
|
with open(followActivityfilename, 'r') as fp:
|
||||||
|
followJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
if followJson:
|
||||||
approveNickname=approveHandle.split('@')[0]
|
approveNickname=approveHandle.split('@')[0]
|
||||||
approveDomain=approveHandle.split('@')[1].replace('\n','')
|
approveDomain=approveHandle.split('@')[1].replace('\n','')
|
||||||
approvePort=port2
|
approvePort=port2
|
||||||
|
|
83
person.py
83
person.py
|
@ -90,12 +90,21 @@ def setProfileImage(baseDir: str,httpPrefix :str,nickname: str,domain: str, \
|
||||||
iconFilename=iconFilenameBase+'.gif'
|
iconFilename=iconFilenameBase+'.gif'
|
||||||
profileFilename=baseDir+'/accounts/'+handle+'/'+iconFilename
|
profileFilename=baseDir+'/accounts/'+handle+'/'+iconFilename
|
||||||
|
|
||||||
with open(personFilename, 'r') as fp:
|
personJson=None
|
||||||
personJson=commentjson.load(fp)
|
try:
|
||||||
|
with open(personFilename, 'r') as fp:
|
||||||
|
personJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if personJson:
|
||||||
personJson[iconFilenameBase]['mediaType']=mediaType
|
personJson[iconFilenameBase]['mediaType']=mediaType
|
||||||
personJson[iconFilenameBase]['url']=httpPrefix+'://'+fullDomain+'/users/'+nickname+'/'+iconFilename
|
personJson[iconFilenameBase]['url']=httpPrefix+'://'+fullDomain+'/users/'+nickname+'/'+iconFilename
|
||||||
with open(personFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
with open(personFilename, 'w') as fp:
|
||||||
|
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
cmd = '/usr/bin/convert '+imageFilename+' -size '+resolution+' -quality 50 '+profileFilename
|
cmd = '/usr/bin/convert '+imageFilename+' -size '+resolution+' -quality 50 '+profileFilename
|
||||||
subprocess.call(cmd, shell=True)
|
subprocess.call(cmd, shell=True)
|
||||||
|
@ -115,11 +124,21 @@ def setOrganizationScheme(baseDir: str,nickname: str,domain: str, \
|
||||||
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
||||||
if not os.path.isfile(actorFilename):
|
if not os.path.isfile(actorFilename):
|
||||||
return False
|
return False
|
||||||
with open(actorFilename, 'r') as fp:
|
|
||||||
actorJson=commentjson.load(fp)
|
actorJson=None
|
||||||
|
try:
|
||||||
|
with open(actorFilename, 'r') as fp:
|
||||||
|
actorJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if actorJson:
|
||||||
actorJson['orgSchema']=schema
|
actorJson['orgSchema']=schema
|
||||||
with open(actorFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
with open(actorFilename, 'w') as fp:
|
||||||
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def accountExists(baseDir: str,nickname: str,domain: str) -> bool:
|
def accountExists(baseDir: str,nickname: str,domain: str) -> bool:
|
||||||
|
@ -239,8 +258,11 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \
|
||||||
if not os.path.isdir(baseDir+peopleSubdir+'/'+handle+'/queue'):
|
if not os.path.isdir(baseDir+peopleSubdir+'/'+handle+'/queue'):
|
||||||
os.mkdir(baseDir+peopleSubdir+'/'+handle+'/queue')
|
os.mkdir(baseDir+peopleSubdir+'/'+handle+'/queue')
|
||||||
filename=baseDir+peopleSubdir+'/'+handle+'.json'
|
filename=baseDir+peopleSubdir+'/'+handle+'.json'
|
||||||
with open(filename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(newPerson, fp, indent=4, sort_keys=False)
|
with open(filename, 'w') as fp:
|
||||||
|
commentjson.dump(newPerson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
# save to cache
|
# save to cache
|
||||||
if not os.path.isdir(baseDir+'/cache'):
|
if not os.path.isdir(baseDir+'/cache'):
|
||||||
|
@ -248,8 +270,11 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \
|
||||||
if not os.path.isdir(baseDir+'/cache/actors'):
|
if not os.path.isdir(baseDir+'/cache/actors'):
|
||||||
os.mkdir(baseDir+'/cache/actors')
|
os.mkdir(baseDir+'/cache/actors')
|
||||||
cacheFilename=baseDir+'/cache/actors/'+newPerson['id'].replace('/','#')+'.json'
|
cacheFilename=baseDir+'/cache/actors/'+newPerson['id'].replace('/','#')+'.json'
|
||||||
with open(cacheFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(newPerson, fp, indent=4, sort_keys=False)
|
with open(cacheFilename, 'w') as fp:
|
||||||
|
commentjson.dump(newPerson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
# save the private key
|
# save the private key
|
||||||
privateKeysSubdir='/keys/private'
|
privateKeysSubdir='/keys/private'
|
||||||
|
@ -504,14 +529,22 @@ def setDisplayNickname(baseDir: str,nickname: str, domain: str, \
|
||||||
filename=baseDir+'/accounts/'+handle.lower()+'.json'
|
filename=baseDir+'/accounts/'+handle.lower()+'.json'
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
personJson=None
|
personJson=None
|
||||||
with open(filename, 'r') as fp:
|
try:
|
||||||
personJson=commentjson.load(fp)
|
with open(filename, 'r') as fp:
|
||||||
|
personJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
if not personJson:
|
if not personJson:
|
||||||
return False
|
return False
|
||||||
personJson['name']=displayName
|
personJson['name']=displayName
|
||||||
with open(filename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
with open(filename, 'w') as fp:
|
||||||
|
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def setBio(baseDir: str,nickname: str, domain: str, bio: str) -> bool:
|
def setBio(baseDir: str,nickname: str, domain: str, bio: str) -> bool:
|
||||||
|
@ -521,16 +554,26 @@ def setBio(baseDir: str,nickname: str, domain: str, bio: str) -> bool:
|
||||||
filename=baseDir+'/accounts/'+handle.lower()+'.json'
|
filename=baseDir+'/accounts/'+handle.lower()+'.json'
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
personJson=None
|
personJson=None
|
||||||
with open(filename, 'r') as fp:
|
try:
|
||||||
personJson=commentjson.load(fp)
|
with open(filename, 'r') as fp:
|
||||||
|
personJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
if not personJson:
|
if not personJson:
|
||||||
return False
|
return False
|
||||||
if not personJson.get('summary'):
|
if not personJson.get('summary'):
|
||||||
return False
|
return False
|
||||||
personJson['summary']=bio
|
personJson['summary']=bio
|
||||||
with open(filename, 'w') as fp:
|
|
||||||
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
try:
|
||||||
|
with open(filename, 'w') as fp:
|
||||||
|
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def isSuspended(baseDir: str,nickname: str) -> bool:
|
def isSuspended(baseDir: str,nickname: str) -> bool:
|
||||||
|
|
16
posts.py
16
posts.py
|
@ -413,8 +413,11 @@ def savePostToBox(baseDir: str,httpPrefix: str,postId: str, \
|
||||||
|
|
||||||
boxDir = createPersonDir(nickname,domain,baseDir,boxname)
|
boxDir = createPersonDir(nickname,domain,baseDir,boxname)
|
||||||
filename=boxDir+'/'+postId.replace('/','#')+'.json'
|
filename=boxDir+'/'+postId.replace('/','#')+'.json'
|
||||||
with open(filename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
with open(filename, 'w') as fp:
|
||||||
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
def updateHashtagsIndex(baseDir: str,tag: {},newPostId: str) -> None:
|
def updateHashtagsIndex(baseDir: str,tag: {},newPostId: str) -> None:
|
||||||
|
@ -2282,7 +2285,10 @@ def downloadAnnounce(session,baseDir: str,httpPrefix: str,nickname: str,domain:
|
||||||
rejectAnnounce(announceFilename)
|
rejectAnnounce(announceFilename)
|
||||||
return None
|
return None
|
||||||
postJsonObject=announcedJson
|
postJsonObject=announcedJson
|
||||||
with open(announceFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
with open(announceFilename, 'w') as fp:
|
||||||
return postJsonObject
|
commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False)
|
||||||
|
return postJsonObject
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return None
|
return None
|
||||||
|
|
46
roles.py
46
roles.py
|
@ -28,13 +28,22 @@ def clearModeratorStatus(baseDir: str) -> None:
|
||||||
if filename.endswith(".json") and '@' in filename:
|
if filename.endswith(".json") and '@' in filename:
|
||||||
filename=os.path.join(baseDir+'/accounts/', filename)
|
filename=os.path.join(baseDir+'/accounts/', filename)
|
||||||
if '"moderator"' in open(filename).read():
|
if '"moderator"' in open(filename).read():
|
||||||
with open(filename, 'r') as fp:
|
actorJson=None
|
||||||
actorJson=commentjson.load(fp)
|
try:
|
||||||
|
with open(filename, 'r') as fp:
|
||||||
|
actorJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if actorJson:
|
||||||
if actorJson['roles'].get('instance'):
|
if actorJson['roles'].get('instance'):
|
||||||
if 'moderator' in actorJson['roles']['instance']:
|
if 'moderator' in actorJson['roles']['instance']:
|
||||||
actorJson['roles']['instance'].remove('moderator')
|
actorJson['roles']['instance'].remove('moderator')
|
||||||
with open(filename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
with open(filename, 'w') as fp:
|
||||||
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
def addModerator(baseDir: str,nickname: str,domain: str) -> None:
|
def addModerator(baseDir: str,nickname: str,domain: str) -> None:
|
||||||
"""Adds a moderator nickname to the file
|
"""Adds a moderator nickname to the file
|
||||||
|
@ -87,8 +96,15 @@ def setRole(baseDir: str,nickname: str,domain: str, \
|
||||||
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
||||||
if not os.path.isfile(actorFilename):
|
if not os.path.isfile(actorFilename):
|
||||||
return False
|
return False
|
||||||
with open(actorFilename, 'r') as fp:
|
|
||||||
actorJson=commentjson.load(fp)
|
actorJson=None
|
||||||
|
try:
|
||||||
|
with open(actorFilename, 'r') as fp:
|
||||||
|
actorJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if actorJson:
|
||||||
if role:
|
if role:
|
||||||
# add the role
|
# add the role
|
||||||
if project=='instance' and 'role'=='moderator':
|
if project=='instance' and 'role'=='moderator':
|
||||||
|
@ -107,8 +123,11 @@ def setRole(baseDir: str,nickname: str,domain: str, \
|
||||||
# if the project contains no roles then remove it
|
# if the project contains no roles then remove it
|
||||||
if len(actorJson['roles'][project])==0:
|
if len(actorJson['roles'][project])==0:
|
||||||
del actorJson['roles'][project]
|
del actorJson['roles'][project]
|
||||||
with open(actorFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
with open(actorFilename, 'w') as fp:
|
||||||
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def getRoles(baseDir: str,nickname: str,domain: str, \
|
def getRoles(baseDir: str,nickname: str,domain: str, \
|
||||||
|
@ -118,8 +137,15 @@ def getRoles(baseDir: str,nickname: str,domain: str, \
|
||||||
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
||||||
if not os.path.isfile(actorFilename):
|
if not os.path.isfile(actorFilename):
|
||||||
return False
|
return False
|
||||||
with open(actorFilename, 'r') as fp:
|
|
||||||
actorJson=commentjson.load(fp)
|
actorJson=None
|
||||||
|
try:
|
||||||
|
with open(actorFilename, 'r') as fp:
|
||||||
|
actorJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if actorJson:
|
||||||
if not actorJson.get('roles'):
|
if not actorJson.get('roles'):
|
||||||
return None
|
return None
|
||||||
if not actorJson['roles'].get(project):
|
if not actorJson['roles'].get(project):
|
||||||
|
|
69
shares.py
69
shares.py
|
@ -25,9 +25,12 @@ def removeShare(baseDir: str,nickname: str,domain: str, \
|
||||||
"""Removes a share for a person
|
"""Removes a share for a person
|
||||||
"""
|
"""
|
||||||
sharesFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/shares.json'
|
sharesFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/shares.json'
|
||||||
if os.path.isfile(sharesFilename):
|
if os.path.isfile(sharesFilename):
|
||||||
with open(sharesFilename, 'r') as fp:
|
try:
|
||||||
sharesJson=commentjson.load(fp)
|
with open(sharesFilename, 'r') as fp:
|
||||||
|
sharesJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
itemID=displayName.replace(' ','')
|
itemID=displayName.replace(' ','')
|
||||||
if sharesJson.get(itemID):
|
if sharesJson.get(itemID):
|
||||||
|
@ -42,8 +45,11 @@ def removeShare(baseDir: str,nickname: str,domain: str, \
|
||||||
os.remove(itemIDfile+'.gif')
|
os.remove(itemIDfile+'.gif')
|
||||||
# remove the item itself
|
# remove the item itself
|
||||||
del sharesJson[itemID]
|
del sharesJson[itemID]
|
||||||
with open(sharesFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
|
with open(sharesFilename, 'w') as fp:
|
||||||
|
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
def addShare(baseDir: str, \
|
def addShare(baseDir: str, \
|
||||||
httpPrefix: str,nickname: str,domain: str,port: int, \
|
httpPrefix: str,nickname: str,domain: str,port: int, \
|
||||||
|
@ -59,9 +65,12 @@ def addShare(baseDir: str, \
|
||||||
"""
|
"""
|
||||||
sharesFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/shares.json'
|
sharesFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/shares.json'
|
||||||
sharesJson={}
|
sharesJson={}
|
||||||
if os.path.isfile(sharesFilename):
|
if os.path.isfile(sharesFilename):
|
||||||
with open(sharesFilename, 'r') as fp:
|
try:
|
||||||
sharesJson=commentjson.load(fp)
|
with open(sharesFilename, 'r') as fp:
|
||||||
|
sharesJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
duration=duration.lower()
|
duration=duration.lower()
|
||||||
durationSec=0
|
durationSec=0
|
||||||
|
@ -137,8 +146,11 @@ def addShare(baseDir: str, \
|
||||||
"expire": durationSec
|
"expire": durationSec
|
||||||
}
|
}
|
||||||
|
|
||||||
with open(sharesFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
|
with open(sharesFilename, 'w') as fp:
|
||||||
|
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
def expireShares(baseDir: str,nickname: str,domain: str) -> None:
|
def expireShares(baseDir: str,nickname: str,domain: str) -> None:
|
||||||
"""Removes expired items from shares
|
"""Removes expired items from shares
|
||||||
|
@ -149,8 +161,13 @@ def expireShares(baseDir: str,nickname: str,domain: str) -> None:
|
||||||
handle=nickname+'@'+handleDomain
|
handle=nickname+'@'+handleDomain
|
||||||
sharesFilename=baseDir+'/accounts/'+handle+'/shares.json'
|
sharesFilename=baseDir+'/accounts/'+handle+'/shares.json'
|
||||||
if os.path.isfile(sharesFilename):
|
if os.path.isfile(sharesFilename):
|
||||||
with open(sharesFilename, 'r') as fp:
|
sharesJson=None
|
||||||
sharesJson=commentjson.load(fp)
|
try:
|
||||||
|
with open(sharesFilename, 'r') as fp:
|
||||||
|
sharesJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
if sharesJson:
|
||||||
currTime=int(time.time())
|
currTime=int(time.time())
|
||||||
deleteItemID=[]
|
deleteItemID=[]
|
||||||
for itemID,item in sharesJson.items():
|
for itemID,item in sharesJson.items():
|
||||||
|
@ -167,9 +184,12 @@ def expireShares(baseDir: str,nickname: str,domain: str) -> None:
|
||||||
os.remove(itemIDfile+'.jpg')
|
os.remove(itemIDfile+'.jpg')
|
||||||
if os.path.isfile(itemIDfile+'.gif'):
|
if os.path.isfile(itemIDfile+'.gif'):
|
||||||
os.remove(itemIDfile+'.gif')
|
os.remove(itemIDfile+'.gif')
|
||||||
with open(sharesFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
|
with open(sharesFilename, 'w') as fp:
|
||||||
|
commentjson.dump(sharesJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
def getSharesFeedForPerson(baseDir: str, \
|
def getSharesFeedForPerson(baseDir: str, \
|
||||||
domain: str,port: int, \
|
domain: str,port: int, \
|
||||||
path: str,httpPrefix: str, \
|
path: str,httpPrefix: str, \
|
||||||
|
@ -219,9 +239,12 @@ def getSharesFeedForPerson(baseDir: str, \
|
||||||
if headerOnly:
|
if headerOnly:
|
||||||
noOfShares=0
|
noOfShares=0
|
||||||
if os.path.isfile(sharesFilename):
|
if os.path.isfile(sharesFilename):
|
||||||
with open(sharesFilename, 'r') as fp:
|
try:
|
||||||
sharesJson=commentjson.load(fp)
|
with open(sharesFilename, 'r') as fp:
|
||||||
noOfShares=len(sharesJson.items())
|
sharesJson=commentjson.load(fp)
|
||||||
|
noOfShares=len(sharesJson.items())
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
shares = {
|
shares = {
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
'first': httpPrefix+'://'+domain+'/users/'+nickname+'/shares?page=1',
|
'first': httpPrefix+'://'+domain+'/users/'+nickname+'/shares?page=1',
|
||||||
|
@ -249,8 +272,14 @@ def getSharesFeedForPerson(baseDir: str, \
|
||||||
pageCtr=0
|
pageCtr=0
|
||||||
totalCtr=0
|
totalCtr=0
|
||||||
|
|
||||||
with open(sharesFilename, 'r') as fp:
|
sharesJson=None
|
||||||
sharesJson=commentjson.load(fp)
|
try:
|
||||||
|
with open(sharesFilename, 'r') as fp:
|
||||||
|
sharesJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if sharesJson:
|
||||||
for itemID,item in sharesJson.items():
|
for itemID,item in sharesJson.items():
|
||||||
pageCtr += 1
|
pageCtr += 1
|
||||||
totalCtr += 1
|
totalCtr += 1
|
||||||
|
|
47
skills.py
47
skills.py
|
@ -26,27 +26,47 @@ def setSkillLevel(baseDir: str,nickname: str,domain: str, \
|
||||||
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
||||||
if not os.path.isfile(actorFilename):
|
if not os.path.isfile(actorFilename):
|
||||||
return False
|
return False
|
||||||
with open(actorFilename, 'r') as fp:
|
|
||||||
actorJson=commentjson.load(fp)
|
actorJson=None
|
||||||
|
try:
|
||||||
|
with open(actorFilename, 'r') as fp:
|
||||||
|
actorJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if actorJson:
|
||||||
if not actorJson.get('skills'):
|
if not actorJson.get('skills'):
|
||||||
actorJson['skills']={}
|
actorJson['skills']={}
|
||||||
if skillLevelPercent>0:
|
if skillLevelPercent>0:
|
||||||
actorJson['skills'][skill]=skillLevelPercent
|
actorJson['skills'][skill]=skillLevelPercent
|
||||||
else:
|
else:
|
||||||
del actorJson['skills'][skill]
|
del actorJson['skills'][skill]
|
||||||
with open(actorFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
with open(actorFilename, 'w') as fp:
|
||||||
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def setSkills(baseDir: str,nickname: str,domain: str,skills: {}) -> None:
|
def setSkills(baseDir: str,nickname: str,domain: str,skills: {}) -> None:
|
||||||
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
||||||
if not os.path.isfile(actorFilename):
|
if not os.path.isfile(actorFilename):
|
||||||
return False
|
return False
|
||||||
with open(actorFilename, 'r') as fp:
|
|
||||||
actorJson=commentjson.load(fp)
|
actorJson=None
|
||||||
|
try:
|
||||||
|
with open(actorFilename, 'r') as fp:
|
||||||
|
actorJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if actorJson:
|
||||||
actorJson['skills']=skills
|
actorJson['skills']=skills
|
||||||
with open(actorFilename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
with open(actorFilename, 'w') as fp:
|
||||||
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
def getSkills(baseDir: str,nickname: str,domain: str) -> []:
|
def getSkills(baseDir: str,nickname: str,domain: str) -> []:
|
||||||
"""Returns the skills for a given person
|
"""Returns the skills for a given person
|
||||||
|
@ -54,8 +74,15 @@ def getSkills(baseDir: str,nickname: str,domain: str) -> []:
|
||||||
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
||||||
if not os.path.isfile(actorFilename):
|
if not os.path.isfile(actorFilename):
|
||||||
return False
|
return False
|
||||||
with open(actorFilename, 'r') as fp:
|
|
||||||
actorJson=commentjson.load(fp)
|
actorJson=None
|
||||||
|
try:
|
||||||
|
with open(actorFilename, 'r') as fp:
|
||||||
|
actorJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if actorJson:
|
||||||
if not actorJson.get('skills'):
|
if not actorJson.get('skills'):
|
||||||
return None
|
return None
|
||||||
return actorJson['skills']
|
return actorJson['skills']
|
||||||
|
|
1
tests.py
1
tests.py
|
@ -452,6 +452,7 @@ def testPostMessageBetweenServers():
|
||||||
with open(outboxPostFilename, 'r') as fp:
|
with open(outboxPostFilename, 'r') as fp:
|
||||||
alicePostJson=commentjson.load(fp)
|
alicePostJson=commentjson.load(fp)
|
||||||
pprint(alicePostJson)
|
pprint(alicePostJson)
|
||||||
|
|
||||||
assert 'likes' in open(outboxPostFilename).read()
|
assert 'likes' in open(outboxPostFilename).read()
|
||||||
|
|
||||||
print('\n\n*******************************************************')
|
print('\n\n*******************************************************')
|
||||||
|
|
9
utils.py
9
utils.py
|
@ -229,9 +229,14 @@ def removeModerationPostFromIndex(baseDir: str,postUrl: str,debug: bool) -> None
|
||||||
def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilename: str,debug: bool):
|
def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilename: str,debug: bool):
|
||||||
"""Recursively deletes a post and its replies and attachments
|
"""Recursively deletes a post and its replies and attachments
|
||||||
"""
|
"""
|
||||||
with open(postFilename, 'r') as fp:
|
postJsonObject=None
|
||||||
postJsonObject=commentjson.load(fp)
|
try:
|
||||||
|
with open(postFilename, 'r') as fp:
|
||||||
|
postJsonObject=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if postJsonObject:
|
||||||
# remove any attachment
|
# remove any attachment
|
||||||
removeAttachment(baseDir,httpPrefix,domain,postJsonObject)
|
removeAttachment(baseDir,httpPrefix,domain,postJsonObject)
|
||||||
|
|
||||||
|
|
21
webfinger.py
21
webfinger.py
|
@ -91,13 +91,19 @@ def storeWebfingerEndpoint(nickname: str,domain: str,port: int,baseDir: str, \
|
||||||
if not os.path.isdir(baseDir+wfSubdir):
|
if not os.path.isdir(baseDir+wfSubdir):
|
||||||
os.mkdir(baseDir+wfSubdir)
|
os.mkdir(baseDir+wfSubdir)
|
||||||
filename=baseDir+wfSubdir+'/'+handle.lower()+'.json'
|
filename=baseDir+wfSubdir+'/'+handle.lower()+'.json'
|
||||||
with open(filename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(wfJson, fp, indent=4, sort_keys=False)
|
with open(filename, 'w') as fp:
|
||||||
|
commentjson.dump(wfJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
if nickname=='inbox':
|
if nickname=='inbox':
|
||||||
handle=originalDomain+'@'+domain
|
handle=originalDomain+'@'+domain
|
||||||
filename=baseDir+wfSubdir+'/'+handle.lower()+'.json'
|
filename=baseDir+wfSubdir+'/'+handle.lower()+'.json'
|
||||||
with open(filename, 'w') as fp:
|
try:
|
||||||
commentjson.dump(wfJson, fp, indent=4, sort_keys=False)
|
with open(filename, 'w') as fp:
|
||||||
|
commentjson.dump(wfJson, fp, indent=4, sort_keys=False)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def createWebfingerEndpoint(nickname: str,domain: str,port: int, \
|
def createWebfingerEndpoint(nickname: str,domain: str,port: int, \
|
||||||
|
@ -216,6 +222,9 @@ def webfingerLookup(path: str,baseDir: str,port: int,debug: bool) -> {}:
|
||||||
print('DEBUG: WEBFINGER filename not found '+filename)
|
print('DEBUG: WEBFINGER filename not found '+filename)
|
||||||
return None
|
return None
|
||||||
wfJson={"nickname": "unknown"}
|
wfJson={"nickname": "unknown"}
|
||||||
with open(filename, 'r') as fp:
|
try:
|
||||||
wfJson=commentjson.load(fp)
|
with open(filename, 'r') as fp:
|
||||||
|
wfJson=commentjson.load(fp)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return wfJson
|
return wfJson
|
||||||
|
|
Loading…
Reference in New Issue