def edit_role(argv): c_name = cfg.ROLES if len(argv) != 1: usage_create_role() return False role_name = argv[0] if not dataset.key_exists(c_name, role_name): print(f'{role_name} does not exist in {c_name}') return False role, err = dataset.read(c_name, role_name) if err != '': print(f'ERROR: {err}') return False for c_name in [cfg.USERS, cfg.ROLES, cfg.OBJECTS]: print(f'Collection {c_name}') perms = role[c_name] for perm in ['create', 'read', 'update', 'delete']: val = role[c_name][perm] t_or_f = input(f'{perm} is {val}, T(rue)/F(alse)/K(eep)? ').lower() if t_or_f in ['t', 'true']: role[c_name][perm] = True if t_or_f in ['f', 'false']: role[c_name][perm] = False c_name = cfg.ROLES err = dataset.update(c_name, role_name, role) if err != '': print(f'ERROR: {err}') return False return True
def set_password(argv): c_name = cfg.USERS if len(argv) < 1: return usage_password() username = argv[0] pw1, pw2 = '', ' ' i = 0 while pw1 != pw2: pw1 = getpass.getpass( prompt=f'Please enter a new password for {username}: ') pw2 = getpass.getpass( prompt=f'Please enter the password a second time: ') if pw1 != pw2: i += 1 if i > 3: print(f'Passwords do not match, exiting') return False u, err = dataset.read(c_name, username) if err != '': print(f'{username} not found in {c_name}, {err}') return False u['password'] = generate_password_hash(pw1) err = dataset.update(c_name, username, u) if err != '': print(f'{username} in {c_name}, {err}') return False return True
def load(self, cl_people_id): c_name = cfg.OBJECTS if dataset.key_exists(c_name, cl_people_id): u, err = dataset.read(c_name, cl_people_id) if err != '': return err self.cl_people_id = u['cl_people_id'] if 'cl_people_id' in u else '' self.family_name = u['family_name'] if 'family_name' in u else '' self.given_name = u['given_name'] if 'given_name' in u else '' self.thesis_id = u['thesis_id'] if 'thesis_id' in u else '' self.authors_id = u['authors_id'] if 'authors_id' in u else '' self.archivesspace_id = u[ 'archivesspace_id'] if 'archivesspace_id' in u else '' self.directory_id = u['directory_id'] if 'directory_id' in u else '' self.viaf = u['viaf'] if 'viaf' in u else '' self.lcnaf = u['lcnaf'] if 'lcnaf' in u else '' self.isni = u['isni'] if 'isni' in u else '' self.wikidata = u['wikidata'] if 'wikidata' in u else '' self.snac = u['snac'] if 'snac' in u else '' self.orcid = u['orcid'] if 'orcid' in u else '' self.image = u['image'] if 'image' in u else '' self.educated_at = u['educated_at'] if 'educated_at' in u else '' self.caltech = u['caltech'] if 'caltech' in u else False self.jpl = u['jpl'] if 'jpl' in u else False self.faculty = u['faculty'] if 'faculty' in u else False self.alumn = u['alumn'] if 'alumn' in u else False self.notes = u['notes'] if 'notes' in u else '' return ''
def get(self, role_name): if dataset.key_exists(self.c_name, role_name) == False: return False role, err = dataset.read(self.c_name, role_name) if err != '': return False self.role_name = role['role_name'] self.objects = role['objects'] self.roles = roles['roles'] self.users = roles['users'] return True
def __init__(self, username=''): self.c_name = cfg.USERS user = {} if username != '': user, err = dataset.read(self.c_name, username) if err != '': print(f'error reading {username} in {cfg.USERS}, {err}') self.id = username self.username = user['username'] if 'username' in user else '' self.display_name = user[ 'display_name'] if 'display_name' in user else '' self.email = user['email'] if 'email' in user else '' self.role = user['role'] if 'role' in user else '' self.password = user['password'] if 'password' in user else ''
def assign_role(argv): c_name = cfg.USERS if len(argv) != 2: return usage_asign_role() username, role = argv[0], argv[1] if dataset.key_exists(c_name, username) == False: print(f'{username} does not exist in {c_name}') return False u, err = dataset.read(c_name, username) if err != '': print(f'Failed to read {username} from {c_name}, {err}') return False u['role'] = role err = dataset.update(c_name, username, u) if err != '': print(f'Failed to write {username} to {c_name}, {err}') return False return True
key = obj['_Key'] err = dataset.create(c_name, key, obj) if err != '': print( f"expected '', got '{err}' for dataset.create({c_name}, {_key}, {obj})" ) sys.exit(1) expected_keys = ["k1", "k2", "k3"] keys = dataset.keys(c_name) i = 0 for key in keys: if not key in expected_keys: print(f"expected {key} in {expected_keys} for {c_name}") sys.exit(1) obj, err = dataset.read(c_name, key) if err != '': print(f"expected '', got '{err}' for dataset.read({c_name}, {key}") sys.exit(1) obj['t_count'] = i i += 1 err = dataset.update(c_name, key, obj) if err != '': print( f"expected '', got '{err}' for dataset.update({c_name}, {key}, ..." ) sys.exit(1) f_name = "f1" err = dataset.frame_create(c_name, f_name, keys[1:], ['._Key', '.title'], ['id', 'title'])
from libdataset import dataset from app import config if __name__ == '__main__': cfg = config.Config() c_name1 = 'CaltechPEOPLE.ds' c_name2 = cfg.OBJECTS keys = dataset.keys(c_name1) for key in keys: obj1, err = dataset.read(c_name1, key) if err != '': print(f'WARNING: read failed, {key} in {c_name1}, {err}') else: obj2 = {} # Initialize an empty object. for attr2 in [ "cl_people_id", "family_name", "given_name", "thesis_id", "authors_id", "archivesspace_id", "directory_id", "viaf", "lcnaf", "isni", "wikidata", "snac", "orcid", "image", "educated_at", "caltech", "jpl", "faculty", "alumn", "notes" ]: obj2[attr2] = '' for attr1 in obj1: attr2 = attr1.lower().replace(' ', '_').replace('(', '').replace( ')', '') if attr2 in [ "cl_people_id", "family_name", "given_name", "thesis_id", "authors_id", "archivesspace_id", "directory_id", "viaf", "lcnaf", "isni", "wikidata",