diff options
-rw-r--r-- | morphlib/buildbranch.py | 18 | ||||
-rw-r--r-- | morphlib/plugins/build_plugin.py | 14 | ||||
-rw-r--r-- | morphlib/plugins/deploy_plugin.py | 14 |
3 files changed, 28 insertions, 18 deletions
diff --git a/morphlib/buildbranch.py b/morphlib/buildbranch.py index d415e7e1..7aa75dc1 100644 --- a/morphlib/buildbranch.py +++ b/morphlib/buildbranch.py @@ -84,14 +84,14 @@ class BuildBranch(object): def _register_cleanup(self, func, *args, **kwargs): self._cleanup.append((func, args, kwargs)) - def add_uncommitted_changes(self): + def add_uncommitted_changes(self, add_cb=lambda **kwargs: None): '''Add any uncommitted changes to temporary build GitIndexes''' for gd, (build_ref, index) in self._to_push.iteritems(): changed = [to_path for code, to_path, from_path in index.get_uncommitted_changes()] if not changed: continue - yield gd, build_ref + add_cb(gd=gd, build_ref=gd, changed=changed) index.add_files_from_working_tree(changed) @staticmethod @@ -102,7 +102,7 @@ class BuildBranch(object): sha1 = gd.store_blob(loader.save_to_string(morphology)) yield 0100644, sha1, morphology.filename - def inject_build_refs(self, loader): + def inject_build_refs(self, loader, inject_cb=lambda **kwargs: None): '''Update system and stratum morphologies to point to our branch. For all edited repositories, this alter the temporary GitIndex @@ -141,12 +141,13 @@ class BuildBranch(object): morphs.traverse_specs(process, filter) if any(m.dirty for m in morphs.morphologies): - yield self._root + inject_cb(gd=self._root) self._root_index.add_files_from_index_info( self._hash_morphologies(self._root, morphs.morphologies, loader)) - def update_build_refs(self, name, email, uuid): + def update_build_refs(self, name, email, uuid, + commit_cb=lambda **kwargs: None): '''Commit changes in temporary GitIndexes to temporary branches. `name` and `email` are required to construct the commit author info. @@ -176,7 +177,7 @@ class BuildBranch(object): with morphlib.branchmanager.LocalRefManager() as lrm: for gd, (build_ref, index) in self._to_push.iteritems(): - yield gd, build_ref + commit_cb(gd=gd, build_ref=build_ref) tree = index.write_tree() try: parent = gd.resolve_ref_to_commit(build_ref) @@ -201,7 +202,7 @@ class BuildBranch(object): # a problem. lrm.update(gd, build_ref, commit, old_commit) - def push_build_branches(self): + def push_build_branches(self, push_cb=lambda **kwargs: None): '''Push all temporary build branches to the remote repositories. This is a no-op if the BuildBranch was constructed with @@ -219,8 +220,9 @@ class BuildBranch(object): with morphlib.branchmanager.RemoteRefManager(False) as rrm: for gd, (build_ref, index) in self._to_push.iteritems(): remote = gd.get_remote('origin') - yield gd, build_ref, remote refspec = morphlib.gitdir.RefSpec(build_ref) + push_cb(gd=gd, build_ref=build_ref, + remote=remote, refspec=refspec) rrm.push(remote, refspec) self._register_cleanup(rrm.close) diff --git a/morphlib/plugins/build_plugin.py b/morphlib/plugins/build_plugin.py index 1a4fb573..3a489a61 100644 --- a/morphlib/plugins/build_plugin.py +++ b/morphlib/plugins/build_plugin.py @@ -187,27 +187,31 @@ class BuildPlugin(cliapp.Plugin): bb = morphlib.buildbranch.BuildBranch(sb, build_ref_prefix, push_temporary=push) with contextlib.closing(bb) as bb: - - for gd, build_ref in bb.add_uncommitted_changes(): + def report_add(gd, build_ref, changed): self.app.status(msg='Adding uncommitted changes '\ 'in %(dirname)s to %(ref)s', dirname=gd.dirname, ref=build_ref, chatty=True) + bb.add_uncommitted_changes(add_cb=report_add) - for gd in bb.inject_build_refs(loader): + def report_inject(gd): self.app.status(msg='Injecting temporary build refs '\ 'into morphologies in %(dirname)s', dirname=gd.dirname, chatty=True) + bb.inject_build_refs(loader, inject_cb=report_inject) - for gd, build_ref in bb.update_build_refs(name, email, build_uuid): + def report_commit(gd, build_ref): self.app.status(msg='Committing changes in %(dirname)s '\ 'to %(ref)s', dirname=gd.dirname, ref=build_ref, chatty=True) + bb.update_build_refs(name, email, build_uuid, + commit_cb=report_commit) - for gd, build_ref, remote in bb.push_build_branches(): + def report_push(gd, build_ref, remote, refspec): self.app.status(msg='Pushing %(ref)s in %(dirname)s '\ 'to %(remote)s', ref=build_ref, dirname=gd.dirname, remote=remote.get_push_url(), chatty=True) + bb.push_build_branches(push_cb=report_push) build_command.build([bb.root_repo_url, bb.root_ref, diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py index 38c17bc2..99ca6fc3 100644 --- a/morphlib/plugins/deploy_plugin.py +++ b/morphlib/plugins/deploy_plugin.py @@ -322,27 +322,31 @@ class DeployPlugin(cliapp.Plugin): bb = morphlib.buildbranch.BuildBranch(sb, build_ref_prefix, push_temporary=False) with contextlib.closing(bb) as bb: - - for gd, build_ref in bb.add_uncommitted_changes(): + def report_add(gd, build_ref, changed): self.app.status(msg='Adding uncommitted changes '\ 'in %(dirname)s to %(ref)s', dirname=gd.dirname, ref=build_ref, chatty=True) + bb.add_uncommitted_changes(add_cb=report_add) - for gd in bb.inject_build_refs(loader): + def report_inject(gd): self.app.status(msg='Injecting temporary build refs '\ 'into morphologies in %(dirname)s', dirname=gd.dirname, chatty=True) + bb.inject_build_refs(loader, inject_cb=report_inject) - for gd, build_ref in bb.update_build_refs(name, email, build_uuid): + def report_commit(gd, build_ref): self.app.status(msg='Committing changes in %(dirname)s '\ 'to %(ref)s', dirname=gd.dirname, ref=build_ref, chatty=True) + bb.update_build_refs(name, email, build_uuid, + commit_cb=report_commit) - for gd, build_ref, remote in bb.push_build_branches(): + def report_push(gd, build_ref, remote, refspec): self.app.status(msg='Pushing %(ref)s in %(dirname)s '\ 'to %(remote)s', ref=build_ref, dirname=gd.dirname, remote=remote.get_push_url(), chatty=True) + bb.push_build_branches(push_cb=report_push) # Create a tempdir for this deployment to work in deploy_tempdir = tempfile.mkdtemp( |