diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-09-17 13:04:39 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-09-17 18:46:38 +0100 |
commit | 3c123f8d340c2dbd3ce5fe3bcc002f81cd719614 (patch) | |
tree | 4df80cf04153cfbe17ff9dcaac60d5844633ed7c /morphlib | |
parent | debcb7429328880231a7659be5c71f322a78c235 (diff) | |
download | morph-3c123f8d340c2dbd3ce5fe3bcc002f81cd719614.tar.gz |
Add 'morph foreach'
This is a useful tool for now to work around our lack of more
specific system branch commands such as 'morph push' and 'morph pull'
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/plugins/branch_and_merge_plugin.py | 43 |
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) |