Skip to content

Commit

Permalink
Merge 8ff56b6 into d5dc320
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinos Kousidis committed Nov 12, 2018
2 parents d5dc320 + 8ff56b6 commit d59ee20
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
41 changes: 41 additions & 0 deletions reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,44 @@ def upload_to_server(self, workflow, paths, access_token):
logging.debug(str(e))
logging.info("Something went wrong while uploading {}".
format(fname))

def diff_workflows(self, workflow_id_a, workflow_id_b,
brief, access_token):
"""Return the list of differences between two workflows.
:param workflow_id_a: UUID which identifies the first workflow.
:param workflow_id_b: UUID which identifies the second workflow.
:param brief: Flag specifying desired detail in diff.
:param access_token: API token of user requesting diff.
:returns: A list of dictionaries composed by `asset`, `type`, `lines,
`a` and `b`. Asset refers to the workflow asset where a
difference was found, type refers to the asset type, lines refer
to the lines of the file where the differences are and a, b fields
are the actual lines that differ.
"""
try:
(response,
http_response) = self._client.api.get_files(
workflow_id_or_name_a=workflow_id_a,
workflow_id_or_name_b=workflow_id_b,
brief=brief,
access_token=access_token).result()

if http_response.status_code == 200:
return response
else:
raise Exception(
"Expected status code 200 but replied with "
"{status_code}".format(
status_code=http_response.status_code))

except HTTPError as e:
logging.debug(
'File list could not be retrieved: '
'\nStatus: {}\nReason: {}\n'
'Message: {}'.format(e.response.status_code,
e.response.reason,
e.response.json()['message']))
raise Exception(e.response.json()['message'])
except Exception as e:
raise e
57 changes: 57 additions & 0 deletions reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,63 @@ def workflow_run(ctx, file, filenames, name, skip_validation,
parameter=parameter)


@click.command(
'diff',
help='Show differences between two workflows.')
@click.option(
'-a',
'--workflow-a',
default=os.environ.get('REANA_WORKON', None),
callback=workflow_uuid_or_name,
help='Name or UUID of the first workflow to be compared. '
'Overrides value of REANA_WORKON.')
@click.option(
'-b',
'--workflow-b',
callback=workflow_uuid_or_name,
help='Name or UUID of the second workflow to be compared. '
'Overrides value of REANA_WORKON.')
@click.option(
'--brief',
is_flag=True,
help="If set, differences in the contents of the files in the two"
"workspaces are shown.")
@add_access_token_options
@click.pass_context
def workflow_diff(ctx, workflow_a, workflow_b, brief, access_token):
"""Show diff between two worklows."""
def _render_diff(asset, workflow_a, workflow_b):
print(asset)
print(workflow_a)
print(workflow_b)

logging.debug('command: {}'.format(ctx.command_path.replace(" ", ".")))
for p in ctx.params:
logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p]))
try:
response = ctx.obj.client.diff_workflows(workflow_a,
workflow_b,
brief,
access_token)
for diff in response:
_render_diff(diff['asset'], diff['a'], diff['b'])

except ValidationError as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
click.echo(click.style('{0} is not a valid REANA specification:\n{1}'
.format(click.format_filename(file),
e.message),
fg='red'), err=True)
except Exception as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
click.echo(
click.style('Something went wrong when trying to validate {}'
.format(file), fg='red'),
err=True)


workflow.add_command(workflow_workflows)
workflow.add_command(workflow_create)
workflow.add_command(workflow_start)
Expand Down

0 comments on commit d59ee20

Please sign in to comment.