From a24f546197206774f846d4135285f7a918127475 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Tue, 31 Jul 2012 14:14:22 +0000 Subject: morph: move update-gits to plugin This also publicizes cache_repo_and_submodules and traverse_morphs --- morphlib/app.py | 66 +++++++++--------------------- morphlib/plugins/update_gits_plugin.py | 74 ++++++++++++++++++++++++++++++++++ without-test-modules | 1 + 3 files changed, 93 insertions(+), 48 deletions(-) create mode 100644 morphlib/plugins/update_gits_plugin.py diff --git a/morphlib/app.py b/morphlib/app.py index 3402e445..45db9bfa 100755 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -270,7 +270,7 @@ class BuildCommand(object): # Update submodules. done = set() - self.app._cache_repo_and_submodules( + self.app.cache_repo_and_submodules( self.lrc, artifact.source.repo.url, artifact.source.sha1, done) @@ -506,9 +506,9 @@ class Morph(cliapp.Application): morphology, filename) pool.add(source) - self._traverse_morphs([triplet], lrc, rrc, - update=not self.settings['no-git-update'], - visit=add_to_pool) + self.traverse_morphs([triplet], lrc, rrc, + update=not self.settings['no-git-update'], + visit=add_to_pool) return pool def _create_source_pool(self, *args): @@ -565,8 +565,8 @@ class Morph(cliapp.Application): absref = repo.resolve_ref(ref) return absref - def _traverse_morphs(self, triplets, lrc, rrc, update=True, - visit=lambda rn, rf, fn, arf, m: None): + def traverse_morphs(self, triplets, lrc, rrc, update=True, + visit=lambda rn, rf, fn, arf, m: None): morph_factory = morphlib.morphologyfactory.MorphologyFactory(lrc, rrc) queue = collections.deque(triplets) @@ -586,49 +586,13 @@ class Morph(cliapp.Application): queue.extend((c['repo'], c['ref'], '%s.morph' % c['morph']) for c in morphology['sources']) - def cmd_update_gits(self, args): - '''Update cached git repositories. - - Parse the given morphologies, and their dependencies, and - update all the git repositories referred to by them in the - morph cache directory. - - ''' - - if not os.path.exists(self.settings['cachedir']): - os.mkdir(self.settings['cachedir']) - cachedir = os.path.join(self.settings['cachedir'], 'gits') - repo_resolver = morphlib.repoaliasresolver.RepoAliasResolver( - self.settings['repo-alias']) - bundle_base_url = self.settings['bundle-server'] - cache = morphlib.localrepocache.LocalRepoCache( - self, cachedir, repo_resolver, bundle_base_url) - - subs_to_process = set() - - def visit(reponame, ref, filename, absref, morphology): - self.status(msg='Updating %(repo_name)s %(ref)s %(filename)s', - repo_name=reponame, ref=ref, filename=filename) - assert cache.has_repo(reponame) - cached_repo = cache.get_repo(reponame) - try: - submodules = morphlib.git.Submodules(self, cached_repo.path, - absref) - submodules.load() - except morphlib.git.NoModulesFileError: - pass - else: - for submod in submodules: - subs_to_process.add((submod.url, submod.commit)) - - self._traverse_morphs(self.itertriplets(args), cache, None, - update=True, visit=visit) - - done = set() - for url, ref in subs_to_process: - self._cache_repo_and_submodules(cache, url, ref, done) + def _traverse_morphs(self, *args): + warnings.warn('_traverse_morphs is deprecated, ' + 'use traverse_morphs instead', stacklevel=1, + category=DeprecationWarning) + return self.traverse_morphs(*args) - def _cache_repo_and_submodules(self, cache, url, ref, done): + def cache_repo_and_submodules(self, cache, url, ref, done): subs_to_process = set() subs_to_process.add((url, ref)) while subs_to_process: @@ -648,6 +612,12 @@ class Morph(cliapp.Application): if (submod.url, submod.commit) not in done: subs_to_process.add((submod.url, submod.commit)) + def _cache_repo_and_submodules(self, *args): + warnings.warn('_cache_repo_and_submodules is deprecated, ' + 'use cache_repo_and_submodules instead', stacklevel=1, + category=DeprecationWarning) + return self.cache_repo_and_submodules(*args) + def cmd_make_patch(self, args): '''Create a Trebuchet patch between two system images.''' diff --git a/morphlib/plugins/update_gits_plugin.py b/morphlib/plugins/update_gits_plugin.py new file mode 100644 index 00000000..ac7beaa8 --- /dev/null +++ b/morphlib/plugins/update_gits_plugin.py @@ -0,0 +1,74 @@ +# Copyright (C) 2012 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +import cliapp +import os + +import morphlib + + +class UpdateGitsPlugin(cliapp.Plugin): + + def enable(self): + self.app.add_subcommand('update-gits', + self.update_gits, + arg_synopsis='(REPO REF MORPHOLOGY)...') + + def disable(self): + pass + + def update_gits(self, args): + '''Update cached git repositories. + + Parse the given morphologies, and their dependencies, and + update all the git repositories referred to by them in the + morph cache directory. + + ''' + + app = self.app + if not os.path.exists(app.settings['cachedir']): + os.mkdir(app.settings['cachedir']) + cachedir = os.path.join(app.settings['cachedir'], 'gits') + repo_resolver = morphlib.repoaliasresolver.RepoAliasResolver( + app.settings['repo-alias']) + bundle_base_url = app.settings['bundle-server'] + cache = morphlib.localrepocache.LocalRepoCache( + app, cachedir, repo_resolver, bundle_base_url) + + subs_to_process = set() + + def visit(reponame, ref, filename, absref, morphology): + app.status(msg='Updating %(repo_name)s %(ref)s %(filename)s', + repo_name=reponame, ref=ref, filename=filename) + assert cache.has_repo(reponame) + cached_repo = cache.get_repo(reponame) + try: + submodules = morphlib.git.Submodules(app, cached_repo.path, + absref) + submodules.load() + except morphlib.git.NoModulesFileError: + pass + else: + for submod in submodules: + subs_to_process.add((submod.url, submod.commit)) + + app.traverse_morphs(app.itertriplets(args), cache, None, + update=True, visit=visit) + + done = set() + for url, ref in subs_to_process: + app.cache_repo_and_submodules(cache, url, ref, done) diff --git a/without-test-modules b/without-test-modules index 5c3beb4b..f625bc14 100644 --- a/without-test-modules +++ b/without-test-modules @@ -10,4 +10,5 @@ morphlib/plugins/graphing_plugin.py morphlib/plugins/syslinux-disk-systembuilder_plugin.py morphlib/plugins/tarball-systembuilder_plugin.py morphlib/plugins/show_dependencies_plugin.py +morphlib/plugins/update_gits_plugin.py -- cgit v1.2.1