예제 #1
0
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)
예제 #2
0
def show_run(run):
    """Show workflow run information."""
    with service() as api:
        doc = api.runs().get_run(run_id=run)
    click.echo('ID: {}'.format(doc[labels.RUN_ID]))
    if labels.RUN_STARTED in doc:
        click.echo('Started at: {}'.format(doc[labels.RUN_STARTED][:19]))
    if labels.RUN_FINISHED in doc:
        click.echo('Finished at: {}'.format(doc[labels.RUN_FINISHED][:19]))
    click.echo('State: {}'.format(doc[labels.RUN_STATE]))
    # Get index of parameters. The index contains the parameter name
    # and type
    parameters = ParameterIndex.from_dict(doc[labels.RUN_PARAMETERS])
    click.echo('\nArguments:')
    for arg in doc['arguments']:
        para = parameters[arg['name']]
        if para.is_file():
            file_id, target_path = deserialize_fh(arg['value'])
            value = '{} ({})'.format(file_id, target_path)
        else:
            value = arg['value']
        click.echo('  {} = {}'.format(para.name, value))
    if labels.RUN_ERRORS in doc:
        click.echo('\nMessages:')
        for msg in doc[labels.RUN_ERRORS]:
            click.echo('  {}'.format(msg))
    elif labels.RUN_FILES in doc:
        click.echo('\nFiles:')
        for res in doc[labels.RUN_FILES]:
            click.echo('  {} ({})'.format(res[flbls.FILE_ID], res[flbls.FILE_NAME]))
예제 #3
0
def download_file(ctx, group, file, output):
    """Download a previously uploaded file."""
    group_id = ctx.obj.get_group(ctx.params)
    with service() as api:
        buf = api.uploads().get_uploaded_file(group_id=group_id, file_id=file)
        with open(output, 'wb') as local_file:
            local_file.write(buf.read())
예제 #4
0
def start_run(ctx, group, configfile):
    """Start new workflow run."""
    group_id = ctx.obj.get_group(ctx.params)
    config = factory.read_config(configfile) if configfile else None
    with service() as api:
        doc = api.groups().get_group(group_id=group_id)
        config = config if config else doc[glbls.ENGINE_CONFIG]
        # Create list of file descriptors for uploaded files that are included
        # in the submission handle
        files = []
        for fh in doc[glbls.GROUP_UPLOADS]:
            files.append((
                fh[flbls.FILE_ID],
                fh[flbls.FILE_NAME],
                fh[flbls.FILE_DATE][:19])
            )
        # Create list of additional user-provided template parameters
        parameters = ParameterIndex.from_dict(doc[glbls.GROUP_PARAMETERS])
        # Read values for all parameters.
        user_input = read(parameters.sorted(), files=files)
        args = [serialize_arg(key, val) for key, val in user_input.items()]
        # Start the run and print returned run state information.
        doc = api.runs().start_run(group_id=group_id, arguments=args, config=config)
        run_id = doc[labels.RUN_ID]
        run_state = doc[labels.RUN_STATE]
        click.echo('started run {} is {}'.format(run_id, run_state))
예제 #5
0
def login_user(ctx, username, password):
    """Login to to obtain access token."""
    with service() as api:
        doc = api.users().login_user(username=username, password=password)
    # Get the access token from the response and print it to the console.
    token = doc[labels.USER_TOKEN]
    click.echo('export {}={}'.format(ctx.obj.vars['token'], token))
예제 #6
0
def delete_group(ctx, group, force):
    """Delete an existing user group."""
    group_id = ctx.obj.get_group(ctx.params)
    if not force:  # pragma: no cover
        msg = 'Do you really want to delete the group {}'.format(group_id)
        click.confirm(msg, default=True, abort=True)
    with service() as api:
        api.groups().delete_group(group_id)
    click.echo("Submission '{}' deleted.".format(group_id))
예제 #7
0
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)
예제 #8
0
def delete_file(ctx, group, file, force):
    """Delete a previously uploaded file."""
    group_id = ctx.obj.get_group(ctx.params)
    if not force:  # pragma: no cover
        msg = 'Do you really want to delete file {}'
        click.confirm(msg, default=True, abort=True)
    with service() as api:
        api.uploads().delete_file(group_id=group_id, file_id=file)
    click.echo("File '{}' deleted.".format(file))
예제 #9
0
def download_result_archive(ctx, output, workflow):
    """Download post-processing result archive."""
    workflow_id = ctx.obj.get_workflow(ctx.params)
    if workflow_id is None:
        raise click.UsageError('no workflow specified')
    with service() as api:
        buf = api.workflows().get_result_archive(
            workflow_id=workflow_id).open()
        with open(output, 'wb') as local_file:
            local_file.write(buf.read())
예제 #10
0
def register_user(username, password):
    """Register a new user."""
    with service() as api:
        doc = api.users().register_user(
            username=username,
            password=password,
            verify=False
        )
    user_id = doc[labels.USER_ID]
    click.echo('Registered {} with ID {}.'.format(username, user_id))
예제 #11
0
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)
예제 #12
0
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)
예제 #13
0
def update_group(ctx, group, name, members):
    """Update user group."""
    if name is None and members is None:
        raise click.UsageError('nothing to update')
    group_id = ctx.obj.get_group(ctx.params)
    with service() as api:
        doc = api.groups().update_group(
            group_id=group_id,
            name=name,
            members=members.split(',') if members is not None else None)
    print_group(doc)
예제 #14
0
def upload_file(ctx, group, input):
    """Upload a file for a submission."""
    group_id = ctx.obj.get_group(ctx.params)
    filename = os.path.basename(input)
    with service() as api:
        doc = api.uploads().upload_file(group_id=group_id,
                                        file=FSFile(input),
                                        name=filename)
    file_id = doc[labels.FILE_ID]
    name = doc[labels.FILE_NAME]
    click.echo('Uploaded \'{}\' with ID {}.'.format(name, file_id))
예제 #15
0
def create_group(ctx, workflow, name, members, configfile):
    """Create a new user group."""
    workflow_id = ctx.obj.get_workflow(ctx.params)
    config = util.read_object(configfile) if configfile else None
    with service() as api:
        doc = api.groups().create_group(
            workflow_id=workflow_id,
            name=name,
            members=members.split(',') if members is not None else None,
            engine_config=config)
    group_id = doc[labels.GROUP_ID]
    click.echo('export {}={}'.format(ctx.obj.vars['group'], group_id))
예제 #16
0
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)
예제 #17
0
def update_workflow(ctx, name, description, instructions, workflow):
    """Update workflow properties."""
    workflow_id = ctx.obj.get_workflow(ctx.params)
    # Ensure that at least one of the optional arguments is given
    if name is None and description is None and instructions is None:
        click.echo('nothing to update')
    else:
        with service() as api:
            api.workflows().update_workflow(
                workflow_id=workflow_id,
                name=name,
                description=description,
                instructions=read_instructions(instructions))
        click.echo('updated workflow {}'.format(workflow_id))
예제 #18
0
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)
예제 #19
0
def list_workflows():
    """List all workflows."""
    count = 0
    with service() as api:
        doc = api.workflows().list_workflows()
    for wf in doc[labels.WORKFLOW_LIST]:
        if count != 0:
            click.echo()
        count += 1
        title = 'Workflow {}'.format(count)
        click.echo(title)
        click.echo('-' * len(title))
        click.echo()
        click.echo('ID          : {}'.format(wf[labels.WORKFLOW_ID]))
        click.echo('Name        : {}'.format(wf[labels.WORKFLOW_NAME]))
        click.echo('Description : {}'.format(
            wf.get(labels.WORKFLOW_DESCRIPTION)))
        click.echo('Instructions: {}'.format(
            wf.get(labels.WORKFLOW_INSTRUCTIONS)))
예제 #20
0
def create_workflow(ctx, key, name, description, instructions, specfile,
                    manifest, template, configfile, ignore_postproc):
    """Create a new workflow for a given template."""
    config = util.read_object(configfile) if configfile else None
    with service() as api:
        # The create_workflow() method is only supported by the local API. If
        # an attempte is made to create a new workflow via a remote API an
        # error will be raised.
        doc = api.workflows().create_workflow(
            source=template,
            identifier=key,
            name=name,
            description=description,
            instructions=read_instructions(instructions),
            specfile=specfile,
            manifestfile=manifest,
            engine_config=config,
            ignore_postproc=ignore_postproc)
    workflow_id = doc[labels.WORKFLOW_ID]
    click.echo('export {}={}'.format(ctx.obj.vars['workflow'], workflow_id))
예제 #21
0
def get_workflow(ctx, workflow):
    """Print workflow properties."""
    workflow_id = ctx.obj.get_workflow(ctx.params)
    with service() as api:
        doc = api.workflows().get_workflow(workflow_id=workflow_id)
    click.echo('ID          : {}'.format(doc[labels.WORKFLOW_ID]))
    click.echo('Name        : {}'.format(doc[labels.WORKFLOW_NAME]))
    click.echo('Description : {}'.format(doc.get(labels.WORKFLOW_DESCRIPTION)))
    click.echo('Instructions: {}'.format(doc.get(
        labels.WORKFLOW_INSTRUCTIONS)))
    if labels.POSTPROC_RUN in doc:
        postproc = doc[labels.POSTPROC_RUN]
        click.echo('\nPost-processing\n---------------')
        if rlbls.RUN_ERRORS in postproc:
            for msg in postproc[rlbls.RUN_ERRORS]:
                click.echo('{}'.format(msg))
        elif rlbls.RUN_FILES in postproc:
            for f in postproc[rlbls.RUN_FILES]:
                click.echo('{} ({})'.format(f[flbls.FILE_ID],
                                            f[flbls.FILE_NAME]))
예제 #22
0
def whoami_user(ctx):
    """Print name of current user."""
    with service() as api:
        doc = api.users().whoami_user(ctx.obj.access_token())
    click.echo('Logged in as {}.'.format(doc[labels.USER_NAME]))
예제 #23
0
def download_result_file(file, output, run):
    """Download a run result file."""
    with service() as api:
        buf = api.runs().get_result_file(run_id=run, file_id=file).open()
        with open(output, 'wb') as local_file:
            local_file.write(buf.read())
예제 #24
0
def download_result_archive(output, run):
    """Download archive of run result files."""
    with service() as api:
        buf = api.runs().get_result_archive(run_id=run).open()
        with open(output, 'wb') as local_file:
            local_file.write(buf.read())
예제 #25
0
def delete_run(run):
    """Delete run."""
    with service() as api:
        api.runs().delete_run(run_id=run)
    click.echo('run {} deleted.'.format(run))
예제 #26
0
def cancel_run(run):
    """Cancel active run."""
    with service() as api:
        doc = api.runs().cancel_run(run_id=run)
    click.echo('run {} canceled.'.format(doc[labels.RUN_ID]))
예제 #27
0
def logout_user(ctx):
    """Logout from current user session."""
    with service() as api:
        api.users().logout_user(ctx.obj.access_token())
    click.echo('See ya mate!')
예제 #28
0
def show_group(ctx, group):
    """Show user group information."""
    group_id = ctx.obj.get_group(ctx.params)
    with service() as api:
        doc = api.groups().get_group(group_id)
    print_group(doc)
예제 #29
0
def delete_workflow(ctx, workflow):
    """Delete an existing workflow and all runs."""
    workflow_id = ctx.obj.get_workflow(ctx.params)
    with service() as api:
        api.workflows().delete_workflow(workflow_id=workflow_id)
    click.echo('workflow {} deleted.'.format(workflow_id))
예제 #30
0
def delete_obsolete_runs(before, state):
    """Delete old runs."""
    with service() as api:
        count = api.runs().run_manager.delete_obsolete_runs(date=before,
                                                            state=state)
        click.echo('{} runs deleted.'.format(count))