summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2015-03-27 16:47:26 +0000
committerMichael Drake <michael.drake@codethink.co.uk>2015-03-30 15:45:52 +0000
commit1fa49dcc67ce0818d083df820de3933fa8289df4 (patch)
tree078ada0066401b5d1bad2435e1b34bc7a48426e5
parent36167dd8e02f8018f6df1a34002e0ca07a061b05 (diff)
downloadmorph-1fa49dcc67ce0818d083df820de3933fa8289df4.tar.gz
Add plugin to get details of given chunk name.
Usefully, this provides the resolved repo URL, which may be aliased in the actual defintions. This makes it easier to use a workflow that avoids `morph edit`. Resolved repo URLs can be git cloned. It also provides other info about the chunk. In the case of multiple strata containing the same chunk name, the tool lists them all, saying which stratum they come from. Example output: # morph get-chunk-details libpng In stratum graphics-common: Chunk: libpng Repo: git://git.baserock.org/delta/libpng Ref: 259fb7761d747655c607efcec7a12ff1f3c24561 Change-Id: I6b540e38d9521f3f473b51c9031e508ddcb458ee
-rw-r--r--morphlib/plugins/get_chunk_details_plugin.py79
-rw-r--r--without-test-modules1
2 files changed, 80 insertions, 0 deletions
diff --git a/morphlib/plugins/get_chunk_details_plugin.py b/morphlib/plugins/get_chunk_details_plugin.py
new file mode 100644
index 00000000..842b4afe
--- /dev/null
+++ b/morphlib/plugins/get_chunk_details_plugin.py
@@ -0,0 +1,79 @@
+# Copyright (C) 2015 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import cliapp
+import morphlib
+
+class GetChunkDetailsPlugin(cliapp.Plugin):
+
+ def enable(self):
+ self.app.add_subcommand(
+ 'get-chunk-details', self.get_chunk_details,
+ arg_synopsis='[STRATUM] CHUNK')
+
+ def disable(self):
+ pass
+
+ def get_chunk_details(self, args):
+ '''Print out details for the given chunk
+
+ Command line arguments:
+
+ * `STRATUM` is the stratum to search for chunk (optional).
+ * `CHUNK` is the component to obtain a URL for.
+
+ '''
+
+ stratum_name = None
+
+ if len(args) == 1:
+ chunk_name = args[0]
+ elif len(args) == 2:
+ stratum_name = args[0]
+ chunk_name = args[1]
+ else:
+ raise cliapp.AppException(
+ 'Wrong number of arguments to get-chunk-details command '
+ '(see help)')
+
+ sb = morphlib.sysbranchdir.open_from_within('.')
+ loader = morphlib.morphloader.MorphologyLoader()
+
+ aliases = self.app.settings['repo-alias']
+ self.resolver = morphlib.repoaliasresolver.RepoAliasResolver(aliases)
+
+ found = 0
+ for morph in sb.load_all_morphologies(loader):
+ if morph['kind'] == 'stratum':
+ if (stratum_name == None or
+ morph['name'] == stratum_name):
+ for chunk in morph['chunks']:
+ if chunk['name'] == chunk_name:
+ found = found + 1
+ self._print_chunk_details(chunk, morph)
+
+ if found == 0:
+ if stratum_name == None:
+ print('Chunk `{}` not found'
+ .format(chunk_name))
+ else:
+ print('Chunk `{}` not found in stratum `{}`'
+ .format(chunk_name, stratum_name))
+
+ def _print_chunk_details(self, chunk, morph):
+ repo = self.resolver.pull_url(chunk['repo'])
+ print('In stratum {}:'.format(morph['name']))
+ print(' Chunk: {}'.format(chunk['name']))
+ print(' Repo: {}'.format(repo))
+ print(' Ref: {}'.format(chunk['ref']))
diff --git a/without-test-modules b/without-test-modules
index 55e5291d..863f6f0f 100644
--- a/without-test-modules
+++ b/without-test-modules
@@ -26,6 +26,7 @@ morphlib/plugins/__init__.py
morphlib/writeexts.py
morphlib/plugins/list_artifacts_plugin.py
morphlib/plugins/trovectl_plugin.py
+morphlib/plugins/get_chunk_details_plugin.py
morphlib/plugins/gc_plugin.py
morphlib/plugins/print_architecture_plugin.py
morphlib/plugins/add_binary_plugin.py