Option to set availability

master
Bob Mottram 2019-07-14 14:30:59 +01:00
parent f5b926482e
commit 873b4953a7
2 changed files with 28 additions and 0 deletions

View File

@ -16,6 +16,7 @@ from person import validNickname
from person import setProfileImage from person import setProfileImage
from person import setSkillLevel from person import setSkillLevel
from person import setRole from person import setRole
from person import setAvailability
from webfinger import webfingerHandle from webfinger import webfingerHandle
from posts import getPosts from posts import getPosts
from posts import createPublicPost from posts import createPublicPost
@ -181,6 +182,8 @@ parser.add_argument('--skill', dest='skill', type=str,default=None, \
help='Set a skill for a person') help='Set a skill for a person')
parser.add_argument('--level', dest='skillLevelPercent', type=int,default=None, \ parser.add_argument('--level', dest='skillLevelPercent', type=int,default=None, \
help='Set a skill level for a person as a percentage, or zero to remove') help='Set a skill level for a person as a percentage, or zero to remove')
parser.add_argument('--status','--availability', dest='availability', type=str,default=None, \
help='Set an availability status')
args = parser.parse_args() args = parser.parse_args()
debug=False debug=False
@ -536,6 +539,14 @@ if args.backgroundImage:
print('Background image was not added for '+args.nickname) print('Background image was not added for '+args.nickname)
sys.exit() sys.exit()
if args.availability:
if not nickname:
print('No nickname given')
sys.exit()
if setAvailability(baseDir,nickname,domain,args.availability):
print('Availablity set to '+args.availability)
sys.exit()
if args.project: if args.project:
if not nickname: if not nickname:
print('No nickname given') print('No nickname given')
@ -584,6 +595,7 @@ if args.testdata:
setRole(baseDir,nickname,domain,'epicyon','tester') setRole(baseDir,nickname,domain,'epicyon','tester')
setRole(baseDir,nickname,domain,'epicyon','hacker') setRole(baseDir,nickname,domain,'epicyon','hacker')
setRole(baseDir,nickname,domain,'someproject','assistant') setRole(baseDir,nickname,domain,'someproject','assistant')
setAvailability(baseDir,nickname,domain,'busy')
deleteAllPosts(baseDir,nickname,domain,'inbox') deleteAllPosts(baseDir,nickname,domain,'inbox')
deleteAllPosts(baseDir,nickname,domain,'outbox') deleteAllPosts(baseDir,nickname,domain,'outbox')
followPerson(baseDir,nickname,domain,'admin',domain,federationList,True) followPerson(baseDir,nickname,domain,'admin',domain,federationList,True)

View File

@ -137,6 +137,21 @@ def setRole(baseDir: str,nickname: str,domain: str, \
commentjson.dump(actorJson, fp, indent=4, sort_keys=False) commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
return True return True
def setAvailability(baseDir: str,nickname: str,domain: str, \
status: str) -> bool:
"""Set an availability status
"""
# avoid giant strings
if len(status)>128:
return False
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
if not os.path.isfile(actorFilename):
return False
with open(actorFilename, 'r') as fp:
actorJson=commentjson.load(fp)
actorJson['availability']=status
return True
def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \
httpPrefix: str, saveToFile: bool,password=None) -> (str,str,{},{}): httpPrefix: str, saveToFile: bool,password=None) -> (str,str,{},{}):
"""Returns the private key, public key, actor and webfinger endpoint """Returns the private key, public key, actor and webfinger endpoint
@ -177,6 +192,7 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \
'following': httpPrefix+'://'+domain+'/users/'+nickname+'/following', 'following': httpPrefix+'://'+domain+'/users/'+nickname+'/following',
'skills': {}, 'skills': {},
'roles': {}, 'roles': {},
'availability': None,
'icon': {'mediaType': 'image/png', 'icon': {'mediaType': 'image/png',
'type': 'Image', 'type': 'Image',
'url': httpPrefix+'://'+domain+'/users/'+nickname+'/icon.png'}, 'url': httpPrefix+'://'+domain+'/users/'+nickname+'/icon.png'},