Exemplo n.º 1
0
def update_submission(ctx, submission, name, members):
    """Create a new submission."""
    if name is None and members is None:
        click.echo('nothing to update')
        return
    s_id = submission if submission else config.SUBMISSION_ID()
    if s_id is None:
        click.echo('no submission specified')
        return
    url = ctx.obj['URLS'].update_submission(submission_id=s_id)
    headers = ctx.obj['HEADERS']
    data = dict()
    if name is not None:
        data['name'] = name
    if members is not None:
        data['members'] = members.split(',')
    try:
        r = requests.put(url, json=data, headers=headers)
        r.raise_for_status()
        body = r.json()
        if ctx.obj['RAW']:
            click.echo(json.dumps(body, indent=4))
        else:
            s_id = body['id']
            click.echo('Submission \'{}\' updated.'.format(s_id))
            members = list()
            for u in body['members']:
                members.append(u['username'])
            click.echo('Name    : {}'.format(body['name']))
            click.echo('Members : {}'.format(','.join(members)))
    except (requests.ConnectionError, requests.HTTPError) as ex:
        click.echo('{}'.format(ex))
Exemplo n.º 2
0
def list_runs(ctx, submission):
    """List all submission runs."""
    s_id = submission if submission else config.SUBMISSION_ID()
    if s_id is None:
        click.echo('no submission specified')
        return
    try:
        url = ctx.obj['URLS'].list_runs(submission_id=s_id)
        headers = ctx.obj['HEADERS']
        r = requests.get(url, headers=headers)
        r.raise_for_status()
        body = r.json()
        if ctx.obj['RAW']:
            click.echo(json.dumps(body, indent=4))
        else:
            table = ResultTable(
                headline=['ID', 'Submitted at', 'State'],
                types=[PARA_STRING] * 4
            )
            for r in body['runs']:
                run = list([r['id'], r['createdAt'], r['state']])
                table.add(run)
            for line in table.format():
                click.echo(line)
    except (requests.ConnectionError, requests.HTTPError) as ex:
        click.echo('{}'.format(ex))
    except (ValueError, IOError, OSError) as ex:
        click.echo('{}'.format(ex))
Exemplo n.º 3
0
def get_submission(ctx, submission):
    """Show submissions information."""
    s_id = submission if submission else config.SUBMISSION_ID()
    if s_id is None:
        click.echo('no submission specified')
        return
    url = ctx.obj['URLS'].get_submission(s_id)
    headers = ctx.obj['HEADERS']
    try:
        r = requests.get(url, headers=headers)
        r.raise_for_status()
        body = r.json()
        if ctx.obj['RAW']:
            click.echo(json.dumps(body, indent=4))
        else:
            members = list()
            for u in body['members']:
                members.append(u['username'])
            click.echo('ID      : {}'.format(body['id']))
            click.echo('Name    : {}'.format(body['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 body['files']:
                table.add([
                    f['id'],
                    f['name'],
                    f['createdAt'][:19],
                    f['size']
                ])
            for line in table.format():
                click.echo(line)
            # -- Runs ---------------------------------------------------------
            click.echo('\nRuns\n----\n')
            table = ResultTable(
                headline=['ID', 'Created At', 'State'],
                types=[PARA_STRING] * 3
            )
            for r in body['runs']:
                table.add([
                    r['id'],
                    r['createdAt'][:19],
                    r['state']
                ])
            for line in table.format():
                click.echo(line)
    except (requests.ConnectionError, requests.HTTPError) as ex:
        click.echo('{}'.format(ex))
Exemplo n.º 4
0
def delete_submission(ctx, submission):
    """Delete an existing submission."""
    s_id = submission if submission else config.SUBMISSION_ID()
    if s_id is None:
        click.echo('no submission specified')
        return
    msg = 'Do you really want to delete submission {}'
    if not click.confirm(msg.format(s_id)):
        return
    url = ctx.obj['URLS'].delete_submission(submission_id=s_id)
    headers = ctx.obj['HEADERS']
    try:
        r = requests.delete(url, headers=headers)
        r.raise_for_status()
        click.echo('Submission \'{}\' deleted.'.format(s_id))
    except (requests.ConnectionError, requests.HTTPError) as ex:
        click.echo('{}'.format(ex))
Exemplo n.º 5
0
def start_run(ctx, submission):
    """Start new submission run."""
    s_id = submission if submission else config.SUBMISSION_ID()
    if s_id is None:
        click.echo('no submission specified')
        return
    try:
        url = ctx.obj['URLS'].get_submission(submission_id=s_id)
        headers = ctx.obj['HEADERS']
        r = requests.get(url, headers=headers)
        r.raise_for_status()
        body = r.json()
        # Create list of file descriptors for uploaded files that are included
        # in the submission handle
        files = []
        for fh in body['files']:
            files.append((fh['id'], fh['name'], fh['createdAt'][:19]))
        # Create list of additional user-provided template parameters
        parameters = ParameterIndex.from_dict(body['parameters'])
        # Read values for all parameters
        args = read(parameters.sorted(), files=files)
        data = {'arguments': [ARG(key, val) for key, val in args.items()]}
        url = ctx.obj['URLS'].start_run(submission_id=s_id)
        r = requests.post(url, json=data, headers=headers)
        r.raise_for_status()
        body = r.json()
        if ctx.obj['RAW']:
            click.echo(json.dumps(body, indent=4))
        else:
            run_id = body['id']
            run_state = body['state']
            click.echo('run {} in state {}'.format(run_id, run_state))
    except (requests.ConnectionError, requests.HTTPError) as ex:
        click.echo('{}'.format(ex))
    except (ValueError, IOError, OSError) as ex:
        click.echo('{}'.format(ex))