summaryrefslogtreecommitdiff
path: root/morphlib/plugins
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-08-08 23:05:10 +0100
committerRichard Maw <richard.maw@codethink.co.uk>2014-08-12 11:00:08 +0100
commit1aaa11a10d03202063e15b6dd0a3b5217de51fc2 (patch)
treec22e953272e9cac2e15b03856028500792c0e3fe /morphlib/plugins
parent1a6fb660b94228745efc4543138b9dc1fa50e912 (diff)
downloadmorph-1aaa11a10d03202063e15b6dd0a3b5217de51fc2.tar.gz
Turn BuildBranch methods into regular functions
Previously they were generator functions, which yielded interesting context at interesting times so that the caller could respond by printing status messages. The only benefits this had over callbacks were: 1. 1 fewer function scope to worry about. I don't have data on the amount of memory used for a function scope vs a generator, but it could be less cognitive load for determining which variables are defined in the callback's body. 2. It is possible to yield in the caller, so you could make that into a coroutine too, however this wasn't required in this case, as the yielded value was intended to be informational. The downsides to this are: 1. It's a rather peculiar construct, so can be difficult to understand what's going on, and the implications, which led to 2. If you call the function, but don't use the iterator it returned, then it won't do anything, which is very confusing indeed, if you're not used to how generator functions work.
Diffstat (limited to 'morphlib/plugins')
-rw-r--r--morphlib/plugins/build_plugin.py14
-rw-r--r--morphlib/plugins/deploy_plugin.py14
2 files changed, 18 insertions, 10 deletions
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(