Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add workflow import command #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions panoptes_cli/commands/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,18 @@ def ls(workflow_id, project_id, quiet):

@workflow.command()
@click.argument('workflow-id', required=True)
def info(workflow_id):
@click.argument('output-file', required=False, type=click.File('w'))
def info(workflow_id, output_file):
"""
Displays workflow metadata, or optionally writes it to a file.

OUTPUT_FILE will be overwritten if it already exists.
"""
workflow = Workflow.find(workflow_id)
click.echo(yaml.dump(workflow.raw))
if output_file:
yaml.dump(workflow.raw, output_file)
else:
click.echo(yaml.dump(workflow.raw))


@workflow.command(name='retire-subjects')
Expand Down Expand Up @@ -201,6 +210,34 @@ def delete(force, workflow_ids):
workflow.delete()


@workflow.command(name='import')
@click.argument('project-id', required=True, type=int)
@click.argument('input-file', required=True, type=click.File('r'))
@click.argument('display-name', required=True, type=str)
def import_workflow(project_id, input_file, display_name):
"""
Creates a new workflow from metadata in a YAML file (as created by the
`panoptes workflow info` command).
"""

input_data = yaml.load(input_file, Loader=yaml.FullLoader)
w = Workflow()
w.display_name = display_name
w.links.project = project_id
IMPORTED_ATTRS = (
'tasks',
'primary_language',
'configuration',
'first_task',
'mobile_friendly',
'retirement',
)
for attr in IMPORTED_ATTRS:
setattr(w, attr, input_data[attr])
w.save()
echo_workflow(w)


def echo_workflow(workflow):
click.echo(
u'{} {}'.format(
Expand Down