Skip to content

Commit

Permalink
Add workflow import command
Browse files Browse the repository at this point in the history
Closes #73
  • Loading branch information
adammcmaster committed Oct 15, 2019
1 parent c9d1228 commit 7f41bac
Showing 1 changed file with 39 additions and 2 deletions.
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

0 comments on commit 7f41bac

Please sign in to comment.