def update_catalog_minid(catalog, minidserver, email, code, status=None, obsoleted_by=None, title=None, test=False): catalog_location = catalog.URL(version=version) # see if this catalog or name exists checksum = catalog.CheckSum() entities = mca.get_entities(minidserver, checksum, test) if entities is None: raise MINIDError( 'No entity found to update. You must use a valid minid.') elif len(entities) > 1: raise MINIDError( "More than one minid identified. Please use a minid identifier") else: entity = entities.values()[0] if status is not None: entity['status'] = status if obsoleted_by is not None: entity['obsoleted_by'] = obsoleted_by if title is not None: entity['titles'] = [{"title": title}] updated_entity = mca.update_entity(minidserver, catalog_location, entity, email, code) return updated_entity
def get_minid_fields(minid): r = mn.get_entities(MINID_SERVER, minid, False) minid_json = r[minid] locations = minid_json['locations'] link = locations[0]['link'] filename = os.path.basename(link) try: title = str(minid_json['titles'][0]['title']) except: title = '' return ((minid_json['checksum'], title, link, filename))
def lookup_catalog_minid(catalog, minidserver, test=False): """ Return a list of entities by looking up values using the checksum :param catalog: VersionedCatalog object :param minidserver: Hostname of minid server :param test: user test MINID server :return: List of entitys that match the requested catalog """ checksum = catalog.CheckSum() entities = mca.get_entities(minidserver, checksum, test) return entities
def create_catalog_minid(catalog, minidserver, email, code, title=None, test=False, key=None): """ Create a MIND from a ERMRest catalog :param catalog: VersionedCatalog object :param minidserver: Host name of minid service :param email: EMAIL address to be used for MINID metadata :param code: Authentication code for MINID serivce users :param title: Title of catalog MIND. Will default to catalog URL and version if not provided :param test: Use MINID test ID space :param key: contect key :return: ID of an ARK """ catalog_path = catalog.path # Create a default title... if title is None: title = "ERMRest Catalog: " + catalog_path # see if this catalog or name exists checksum = catalog.CheckSum() entities = mca.get_entities(minidserver, checksum, test) # register file or display info about the entity if entities: raise MINIDError("MINID for this catalog version already exists: " + [x for x in entities.keys()][0]) else: # register_entity wants a list of locations.... minid = mca.register_entity(minidserver, checksum, email, code, [catalog.URL()], title, test, key) return minid
def main(): args = parse_cli() if not args.quiet: mca.configure_logging() config = mca.parse_config(args.config) server = config["minid_server"] if args.server: server = args.server entities = None # register a new user if args.register_user: mca.register_user(server, args.email, args.name, args.orcid) return # if we got this far we *must* have a filename (or identifier) arg if not args.filename: print("Either a file name or an identifier must be specified.") return # see if this file or name exists file_exists = os.path.isfile(args.filename) if file_exists: checksum = mca.compute_checksum(args.filename) entities = mca.get_entities(server, checksum, args.test) else: entities = mca.get_entities(server, args.filename, False) if entities is None: print("No entity registered with identifier: %s" % args.filename) return # register file or display info about the entity if args.register: if entities and not file_exists: print("You must use the --update command to update a minid") return else: locations = args.locations if locations is None or len(locations) == 0: if "local_server" in config: locations = [ "%s%s" % (config["local_server"], os.path.abspath(args.filename)) ] mca.register_entity(server, checksum, args.email if args.email else config["email"], args.code if args.code else config["code"], locations, args.title, args.test, args.content_key) elif args.update: if entities is None: print("No entity found to update. You must use a valid minid.") return elif len(entities) > 1: print( "More than one minid identified. Please use a minid identifier" ) else: entity = entities.values()[0] if args.status: entity['status'] = args.status if args.obsoleted_by: entity['obsoleted_by'] = args.obsoleted_by if args.title: entity['titles'] = [{"title": args.title}] if args.locations: locs = [] for l in args.locations: locs.append({'uri': l}) entity['locations'] = locs updated_entity = mca.update_entity( server, args.filename, entity, args.email if args.email else config["email"], args.code if args.code else config["code"]) print(updated_entity) else: if entities: mca.print_entities(entities, args.json) else: print( "File is not named. Use --register to create a name for this file." )
def main(): args = parse_cli() # Need to change this.... args.scheme = 'https' if not (args.register or args.update or args.register_user or args.url or args.landingpage): args.register = True if not args.quiet: mca.configure_logging() config = mca.parse_config(args.config) email = args.email if args.email else config["email"] code = args.code if args.code else config["code"] server = args.server if args.server else config['minid_server'] try: # register a new user if args.register_user: mca.register_user(server, email, config['name'], args.orcid) return if args.url: url = resolve_catalog_minid(args.path) print(url) return if args.landingpage: if args.path[0:len('ark:')] == 'ark:': entities = mca.get_entities(server, args.path, args.test) else: vc = VersionedCatalog(args.url, args.version) entities = lookup_catalog_minid(vc, server, test=args.test) if entities is not None: mca.print_entities(entities, args.json) else: print( "Catalog is not named. Use --register to create a name for this file." ) return if args.path is None: print("Catalog path must be specified") return vc = VersionedCatalog(args.path, args.version) # register file or display info about the entity if args.register: create_catalog_minid(vc, server, email, code, title=args.title, test=args.test) elif args.update: update_catalog_minid(vc, server, email, code, title=args.title, status=args.status, obsoleted_by=args.obsoleted_by, test=args.test) except MINIDError as err: print('ERROR: ' + err.message) except requests.exceptions.HTTPError as err: print(err)