def print_group(doc): """Print group handle information to console. Parameters ---------- doc: dict Serialization of a workflow group handle. """ members = list() for u in doc[labels.GROUP_MEMBERS]: members.append(u[labels.USER_NAME]) click.echo('ID : {}'.format(doc[labels.GROUP_ID])) click.echo('Name : {}'.format(doc[labels.GROUP_NAME])) click.echo('Members : {}'.format(','.join(members))) # -- Uploaded files ----------------------------------------------- click.echo('\nUploaded Files\n--------------\n') table = ResultTable( headline=['ID', 'Name', 'Created At', 'Size'], types=[PARA_STRING, PARA_STRING, PARA_STRING, PARA_INT]) for f in doc[labels.GROUP_UPLOADS]: table.add([ f[filelabels.FILE_ID], f[filelabels.FILE_NAME], f[filelabels.FILE_DATE][:19], f[filelabels.FILE_SIZE] ]) for line in table.format(): click.echo(line)
def show_ranking(ctx, workflow, all): """Show ranking for workflow results.""" workflow_id = ctx.obj.get_workflow(ctx.params) with service() as api: doc = api.workflows().get_ranking(workflow_id=workflow_id, include_all=all) # Print ranking. headline = ['Rank', 'Name'] types = [PARA_INT, PARA_STRING] mapping = dict() for col in doc[labels.WORKFLOW_SCHEMA]: headline.append(col[labels.COLUMN_TITLE]) types.append(col[labels.COLUMN_TYPE]) mapping[col[labels.COLUMN_NAME]] = len(mapping) table = ResultTable(headline=headline, types=types) rank = 1 for run in doc[labels.RANKING]: group = run[labels.WORKFLOW_GROUP][labels.GROUP_NAME] row = [rank, group] + ([None] * (len(headline) - 2)) for r in run[labels.RUN_RESULTS]: row[mapping[r[labels.COLUMN_NAME]] + 2] = r[labels.COLUMN_VALUE] table.add(row) rank += 1 for line in table.format(): click.echo(line)
def list_users(): """List all registered users.""" with service() as api: doc = api.users().list_users() table = ResultTable(['Name', 'ID'], [PARA_STRING, PARA_STRING]) for user in doc[labels.USER_LIST]: table.add([user[labels.USER_NAME], user[labels.USER_ID]]) for line in table.format(): click.echo(line)
def list_groups(): """List user groups (for current user).""" with service() as api: doc = api.groups().list_groups() # Print listing of groups as output table. table = ResultTable(['ID', 'Name'], [PARA_STRING] * 2) for g in doc[labels.GROUP_LIST]: table.add([g[labels.GROUP_ID], g[labels.GROUP_NAME]]) for line in table.format(): click.echo(line)
def list_obsolete_runs(before, state): """List old runs.""" table = ResultTable(headline=['ID', 'Submitted at', 'State'], types=[PARA_STRING] * 3) with service() as api: runs = api.runs().run_manager.list_obsolete_runs(date=before, state=state) for run in runs: table.add([run.run_id, run.created_at[:19], run.state_type]) for line in table.format(): click.echo(line)
def list_runs(ctx, group, state): """List workflow runs.""" group_id = ctx.obj.get_group(ctx.params) with service() as api: doc = api.runs().list_runs(group_id=group_id, state=state) table = ResultTable( headline=['ID', 'Submitted at', 'State'], types=[PARA_STRING] * 3 ) for r in doc[labels.RUN_LIST]: run = list([r[labels.RUN_ID], r[labels.RUN_CREATED][:19], r[labels.RUN_STATE]]) table.add(run) for line in table.format(): click.echo(line)
def list_files(ctx, group): """List uploaded files for a submission.""" group_id = ctx.obj.get_group(ctx.params) with service() as api: doc = api.uploads().list_uploaded_files(group_id) table = ResultTable( headline=['ID', 'Name', 'Created At', 'Size'], types=[PARA_STRING, PARA_STRING, PARA_STRING, PARA_INT]) for f in doc['files']: table.add([ f[labels.FILE_ID], f[labels.FILE_NAME], f[labels.FILE_DATE][:19], f[labels.FILE_SIZE] ]) for line in table.format(): click.echo(line)
def read_file( para: Parameter, scanner: Scanner, files: Optional[Tuple[str, str, str]] = None ): """Read value for a file parameter. Parameters ---------- para: flowserv.model.parameter.base.Parameter Workflow template parameter declaration scanner: flowserv.scanner.Scanner Input scanner. files: list, default=None List of tuples representing uploaded files. Each tuple has three elements: file_id, name, timestamp. """ # Distinguish between the case where a list of uploaded files # is given or not. if files is not None: print('\nSelect file identifier from uploaded files:\n') table = ResultTable( headline=['ID', 'Name', 'Created at'], types=[PARA_STRING] * 3 ) for file_id, name, created_at in files: table.add([file_id, name, created_at]) for line in table.format(): print(line) print('\n{}'.format(para.prompt()), end='') filename = scanner.next_string() else: filename = scanner.next_file() target_path = None if para.target is None: print('Target Path:', end='') target_path = scanner.next_string() if target_path == '': target_path = para.default else: target_path = para.target # The type of the returned value depends on whether the list of # uploaded files is given or not. if files is not None: return serialize_fh(file_id=filename, target=target_path) else: return InputFile(FSFile(filename), target_path)