From 50003c9dd3deb5b2912644723481bdef802e35f7 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 18 Apr 2016 19:48:01 +0000 Subject: Make `morph list-artifacts` work from definitions checkout Change-Id: I711953b829c786911c46e413d2b7af3427b7ba26 --- morphlib/plugins/list_artifacts_plugin.py | 40 +++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'morphlib') diff --git a/morphlib/plugins/list_artifacts_plugin.py b/morphlib/plugins/list_artifacts_plugin.py index 2c098c2a..9e09e2b9 100644 --- a/morphlib/plugins/list_artifacts_plugin.py +++ b/morphlib/plugins/list_artifacts_plugin.py @@ -17,6 +17,7 @@ # See: for more information. from __future__ import print_function +import uuid import cliapp import morphlib @@ -27,7 +28,7 @@ class ListArtifactsPlugin(cliapp.Plugin): def enable(self): self.app.add_subcommand( 'list-artifacts', self.list_artifacts, - arg_synopsis='REPO REF MORPH [MORPH]...') + arg_synopsis='MORPH [MORPH]...') def disable(self): pass @@ -37,8 +38,6 @@ class ListArtifactsPlugin(cliapp.Plugin): Command line arguments: - * `REPO` is a git repository URL. - * `REF` is a branch or other commit reference in that repository. * `MORPH` is a system morphology name at that ref. You can pass multiple values for `MORPH`, in which case the command @@ -49,14 +48,41 @@ class ListArtifactsPlugin(cliapp.Plugin): ''' - if len(args) < 3: + MINARGS = 1 + + if len(args) < MINARGS: raise cliapp.AppException( 'Wrong number of arguments to list-artifacts command ' '(see help)') - repo, ref = args[0], args[1] - system_filenames = map(morphlib.util.sanitise_morphology_path, - args[2:]) + definitions_repo = morphlib.definitions_repo.open( + '.', search_for_root=True, app=self.app) + + system_filenames = [] + for arg in args: + filename = morphlib.util.sanitise_morphology_path(arg) + filename = definitions_repo.relative_path(filename, cwd='.') + system_filenames.append(filename) + + if self.app.settings['local-changes'] == 'include': + # Create a temporary branch with any local changes, and push it to + # the shared Git server. This is a convenience for developers, who + # otherwise need to commit and push each change manually in order + # for distbuild to see it. It renders the build unreproducible, as + # the branch is deleted after being built, so this feature should + # only be used during development! + build_uuid = uuid.uuid4().hex + branch = definitions_repo.branch_with_local_changes( + build_uuid, push=True) + with branch as (repo_url, commit, original_ref): + self._list_artifacts(repo_url, commit, system_filenames) + else: + ref = definitions_repo.HEAD + commit = definitions_repo.resolve_ref_to_commit(ref) + self._list_artifacts(definitions_repo.remote_url, commit, + system_filenames) + + def _list_artifacts(self, repo, ref, system_filenames): self.repo_cache = morphlib.util.new_repo_cache(self.app) self.resolver = morphlib.artifactresolver.ArtifactResolver() -- cgit v1.2.1