summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-09-18 08:05:37 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2012-09-18 08:05:37 +0000
commit3e702b8179e18a8ee206f9977806297906e0e620 (patch)
treeba986d0a282f141c10bd98a23dff1bdc3a55b8e3 /morphlib
parentdebcb7429328880231a7659be5c71f322a78c235 (diff)
parentd08d0afa388c8767a2e6eb13b8ba0c53e531e23f (diff)
downloadmorph-3e702b8179e18a8ee206f9977806297906e0e620.tar.gz
Merge branch 'samthursfield/S4717-morph-foreach' of git://git.baserock.org/baserock/morph
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index 75935b72..2f60c7bf 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -56,6 +56,8 @@ class BranchAndMergePlugin(cliapp.Plugin):
arg_synopsis='SYSTEM STRATUM [CHUNK]')
self.app.add_subcommand('build', self.build,
arg_synopsis='SYSTEM')
+ self.app.add_subcommand('foreach', self.foreach,
+ arg_synopsis='COMMAND')
def disable(self):
pass
@@ -949,3 +951,44 @@ class BranchAndMergePlugin(cliapp.Plugin):
repo=repo)
self.app.runcmd(['git', 'push', 'origin',
':%s' % info['build-ref']], cwd=info['dirname'])
+
+ def foreach(self, args):
+ '''Run a command in each repository checked out in a system branch
+
+ For simplicity, this simply iterates repositories in the directory
+ rather than walking through the morphologies as 'morph merge' does.
+
+ '''
+
+ if len(args) == 0:
+ raise cliapp.AppException('morph foreach expects a command to run')
+
+ workspace = self.deduce_workspace()
+ branch, branch_path = self.deduce_system_branch()
+ root_repo_dir = self.get_branch_config(branch_path, 'branch.root')
+
+ dirs = [d for d in self.walk_special_directories(
+ branch_path, special_subdir='.git')
+ if os.path.basename(d) != root_repo_dir]
+ dirs.sort()
+ root_repo_path = os.path.join(branch_path, root_repo_dir)
+ for d in [root_repo_path] + dirs:
+ try:
+ repo = self.get_repo_config(d, 'morph.repository')
+ except cliapp.AppException:
+ continue
+
+ if d != root_repo_path:
+ print
+ print repo
+
+ try:
+ output = self.app.runcmd(args, cwd=d)
+ except cliapp.AppException as e:
+ # Don't allow cliapp to swallow the output of the command
+ # as the body of the exception
+ output_start = e.msg.find('\n')
+ self.app.output.write(e.msg[output_start+1:])
+ raise cliapp.AppException(e.msg[:output_start])
+
+ self.app.output.write(output)