def inputs(ctx, client, revision, paths): r"""Show inputs files in the repository. <PATHS> Files to show. If no files are given all input files are shown. """ from renku.core.models.provenance.activities import ProcessRun graph = Graph(client) paths = set(paths) nodes = graph.build(revision=revision) commits = {node.commit for node in nodes} candidates = {(node.commit, node.path) for node in nodes if not paths or node.path in paths} input_paths = set() for commit in commits: activity = graph.activities[commit] if isinstance(activity, ProcessRun): for usage in activity.qualified_usage: for entity in usage.entity.entities: path = str((usage.client.path / entity.path).relative_to( client.path )) usage_key = (entity.commit, entity.path) if path not in input_paths and usage_key in candidates: input_paths.add(path) click.echo('\n'.join(graph._format_path(path) for path in input_paths)) ctx.exit(0 if not paths or len(input_paths) == len(paths) else 1)
def siblings(client, revision, paths): """Show siblings for given paths.""" graph = Graph(client) nodes = graph.build(paths=paths, revision=revision) siblings_ = set(nodes) for node in nodes: siblings_ |= graph.siblings(node) paths = {node.path for node in siblings_} for path in paths: click.echo(graph._format_path(path))
def outputs(ctx, client, revision, paths): r"""Show output files in the repository. <PATHS> Files to show. If no files are given all output files are shown. """ graph = Graph(client) filter = graph.build(paths=paths, revision=revision) output_paths = graph.output_paths click.echo('\n'.join(graph._format_path(path) for path in output_paths)) if paths: if not output_paths: ctx.exit(1) from renku.core.models.datastructures import DirectoryTree tree = DirectoryTree.from_list(item.path for item in filter) for output in output_paths: if tree.get(output) is None: ctx.exit(1) return
def outputs(ctx, client, revision, verbose, paths): r"""Show output files in the repository. <PATHS> Files to show. If no files are given all output files are shown. """ graph = Graph(client) filter_ = graph.build(paths=paths, revision=revision) output_paths = {} for activity in graph.activities.values(): if isinstance(activity, ProcessRun): for entity in activity.generated: if entity.path not in graph.output_paths: continue output_paths[entity.path] = Result( path=entity.path, commit=entity.commit, time=activity.ended_at_time, workflow=activity.path ) if not verbose: click.echo("\n".join(graph._format_path(path) for path in output_paths.keys())) else: records = list(output_paths.values()) records.sort(key=lambda v: v[0]) HEADERS["time"] = "generation time" click.echo(tabulate(collection=records, headers=HEADERS)) if paths: if not output_paths: ctx.exit(1) from renku.core.models.datastructures import DirectoryTree tree = DirectoryTree.from_list(item.path for item in filter_) for output in output_paths: if tree.get(output) is None: ctx.exit(1) return
def inputs(ctx, client, revision, verbose, paths): r"""Show inputs files in the repository. <PATHS> Files to show. If no files are given all input files are shown. """ graph = Graph(client) paths = set(paths) nodes = graph.build(revision=revision) commits = {node.activity.commit if hasattr(node, "activity") else node.commit for node in nodes} commits |= {node.activity.commit for node in nodes if hasattr(node, "activity")} candidates = {(node.commit, node.path) for node in nodes if not paths or node.path in paths} input_paths = {} for commit in commits: activity = graph.activities.get(commit) if not activity: continue if isinstance(activity, ProcessRun): for usage in activity.qualified_usage: for entity in usage.entity.entities: path = str((usage.client.path / entity.path).relative_to(client.path)) usage_key = (entity.commit, entity.path) if path not in input_paths and usage_key in candidates: input_paths[path] = Result( path=path, commit=entity.commit, time=activity.started_at_time, workflow=activity.path ) if not verbose: click.echo("\n".join(graph._format_path(path) for path in input_paths)) else: records = list(input_paths.values()) records.sort(key=lambda v: v[0]) HEADERS["time"] = "usage time" click.echo(tabulate(collection=records, headers=HEADERS)) ctx.exit(0 if not paths or len(input_paths) == len(paths) else 1)
def status(ctx, client, revision, no_output, path): """Show a status of the repository.""" graph = Graph(client) # TODO filter only paths = {graph.normalize_path(p) for p in path} status = graph.build_status(revision=revision, can_be_cwl=no_output) if client.has_external_files(): click.echo( 'Changes in external files are not detected automatically. To ' 'update external files run "renku dataset update -e".') try: click.echo('On branch {0}'.format(client.repo.active_branch)) except TypeError: click.echo('Git HEAD is detached!\n' ' Please move back to your working branch to use renku\n') if status['outdated']: click.echo('Files generated from newer inputs:\n' ' (use "renku log [<file>...]" to see the full lineage)\n' ' (use "renku update [<file>...]" to ' 'generate the file from its latest inputs)\n') for filepath, stts in sorted(status['outdated'].items()): outdated = (', '.join('{0}#{1}'.format( click.style(graph._format_path(n.path), fg='blue', bold=True), _format_sha1(graph, n), ) for n in stts if n.path and n.path not in status['outdated'])) click.echo('\t{0}: {1}'.format( click.style(graph._format_path(filepath), fg='red', bold=True), outdated)) click.echo() else: click.secho('All files were generated from the latest inputs.', fg='green') if status['multiple-versions']: click.echo( 'Input files used in different versions:\n' ' (use "renku log --revision <sha1> <file>" to see a lineage ' 'for the given revision)\n') for filepath, files in sorted(status['multiple-versions'].items()): # Do not show duplicated commits! (see #387) commits = {_format_sha1(graph, key) for key in files} click.echo('\t{0}: {1}'.format( click.style(graph._format_path(filepath), fg='blue', bold=True), ', '.join( # Sort the commit hashes alphanumerically to have a # predictable output. sorted(commits)))) click.echo() if status['deleted']: click.echo('Deleted files used to generate outputs:\n' ' (use "git show <sha1>:<file>" to see the file content ' 'for the given revision)\n') for filepath, node in status['deleted'].items(): click.echo('\t{0}: {1}'.format( click.style(graph._format_path(filepath), fg='blue', bold=True), _format_sha1(graph, node))) click.echo() ctx.exit(1 if status['outdated'] else 0)