From 796f9d6ac5eea572169ffb7115b2362f5ac17ff4 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 14 Jul 2019 14:07:54 +0100 Subject: [PATCH] Commandline options for setting roles and skills --- epicyon.py | 38 +++++++++++++++++++++++++++++++++++++- person.py | 3 +++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/epicyon.py b/epicyon.py index 186f318b7..dd077627f 100644 --- a/epicyon.py +++ b/epicyon.py @@ -173,6 +173,14 @@ parser.add_argument("-c","--client", type=str2bool, nargs='?', \ help="Use as an ActivityPub client") parser.add_argument('--maxreplies', dest='maxReplies', type=int,default=64, \ help='Maximum number of replies to a post') +parser.add_argument('--role', dest='role', type=str,default=None, \ + help='Set a role for a person') +parser.add_argument('--organization','--project', dest='project', type=str,default=None, \ + help='Set a project for a person') +parser.add_argument('--skill', dest='skill', type=str,default=None, \ + help='Set a skill for a person') +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') args = parser.parse_args() debug=False @@ -527,7 +535,35 @@ if args.backgroundImage: else: print('Background image was not added for '+args.nickname) sys.exit() - + +if args.project: + if not nickname: + print('No nickname given') + sys.exit() + + if args.role.lower()=='none' or \ + args.role.lower()=='remove' or \ + args.role.lower()=='delete': + args.role=None + if args.role: + if setRole(baseDir,nickname,domain,args.project,args.role): + print('Role within '+args.project+' set to '+args.role) + else: + if setRole(baseDir,nickname,domain,args.project,None): + print('Left '+args.project) + sys.exit() + +if args.skill: + if args.skillLevelPercent==0: + args.skillLevelPercent=None + if args.skillLevelPercent: + if setSkillLevel(baseDir,nickname,domain,args.skill,args.skillLevelPercent): + print('Skill level for '+args.skill+' set to '+str(args.skillLevelPercent)+'%') + else: + if setSkillLevel(baseDir,nickname,domain,args.skill,args.skillLevelPercent): + print('Skill '+args.skill+' removed') + sys.exit() + if federationList: print('Federating with: '+str(federationList)) diff --git a/person.py b/person.py index 2a5c30d1f..adc8eec05 100644 --- a/person.py +++ b/person.py @@ -11,6 +11,7 @@ import commentjson import os import fileinput import subprocess +from pprint import pprint from pathlib import Path from Crypto.PublicKey import RSA from shutil import copyfile @@ -97,6 +98,8 @@ def setSkillLevel(baseDir: str,nickname: str,domain: str, \ return False with open(actorFilename, 'r') as fp: actorJson=commentjson.load(fp) + if not actorJson.get('skills'): + actorJson['skills']={} if skillLevelPercent>0: actorJson['skills'][skill]=skillLevelPercent else: