def _reindex_ws_type(args): """ Reindex all objects in the entire workspace server based on a type name. """ if not re.match(r'^.+\..+-\d+\.\d+$', args.type): sys.stderr.write( 'Enter the full type name, such as "KBaseGenomes.Genome-17.0"') sys.exit(1) # - Iterate over all workspaces # - For each workspace, list objects # - For each obj matching args.type, produce a reindex event ws_client = WorkspaceClient(url=config()['kbase_endpoint'], token=config()['ws_token']) evtype = 'INDEX_NONEXISTENT' if args.overwrite: evtype = 'REINDEX' for wsid in range(args.start, args.stop + 1): wsid = int(wsid) try: infos = ws_client.generate_obj_infos(wsid, admin=True) for obj_info in infos: obj_type = obj_info[2] if obj_type == args.type: _produce({ 'evtype': evtype, 'wsid': wsid, 'objid': int(obj_info[0]) }) except Exception as err: print(f'Error fetching object infos for workspace {wsid}: {err}') continue print('..done!')
def main(): counts = {} # type: dict ws = WorkspaceClient(url=WS_URL, token=WS_TOK) for obj_info in ws.generate_obj_infos(WS_ID, admin=IS_ADMIN, latest=True): obj_type = obj_info[2] if obj_type not in counts: counts[obj_type] = 0 counts[obj_type] += 1 print('Total counts by type:') print(json.dumps(counts, indent=2))
def _fetch_objects_in_workspace(ws_id): """ Get a list of dicts with keys 'obj_type' and 'name' corresponding to all data objects in the requested workspace. This discludes the narrative object. Args: ws_id - a workspace id """ ws_client = WorkspaceClient(url=config()['kbase_endpoint'], token=config()['ws_token']) obj_infos = ws_client.generate_obj_infos(ws_id, admin=True) return [{ "name": info[1], "obj_type": info[2] } for info in obj_infos if 'KBaseNarrative' not in str(info[2])]