def foreach(self, args):
        '''Run a command in each repository checked out in a system branch.

        Use -- before specifying the command to separate its arguments from
        Morph's own arguments.

        Command line arguments:

        * `--` indicates the end of option processing for Morph.
        * `COMMAND` is a command to run.
        * `ARGS` is a list of arguments or options to be passed onto
          `COMMAND`.

        This runs the given `COMMAND` in each git repository belonging
        to the current system branch that exists locally in the current
        workspace.  This can be a handy way to do the same thing in all
        the local git repositories.

        For example:

            morph foreach -- git push

        The above command would push any committed changes in each
        repository to the git server.

        '''

        if not args:
            raise cliapp.AppException('morph foreach expects a command to run')

        ws = morphlib.workspace.open('.')
        sb = morphlib.sysbranchdir.open_from_within('.')

        for gd in sorted(sb.list_git_directories(), key=lambda gd: gd.dirname):
            # Get the repository's original name
            # Continue in the case of error, since the previous iteration
            # worked in the case of the user cloning a repository in the
            # system branch's directory.
            try:
                repo = gd.get_config('morph.repository')
            except cliapp.AppException:
                continue

            self.app.output.write('%s\n' % repo)
            status, output, error = self.app.runcmd_unchecked(
                args, cwd=gd.dirname)
            self.app.output.write(output)
            if status != 0:
                self.app.output.write(error)
                pretty_command = ' '.join(cliapp.shell_quote(arg)
                                          for arg in args)
                raise cliapp.AppException(
                    'Command failed at repo %s: %s'
                    % (repo, pretty_command))
            self.app.output.write('\n')
            self.app.output.flush()
Esempio n. 2
0
    def foreach(self, args):
        '''Run a command in each repository checked out in a system branch.

        Use -- before specifying the command to separate its arguments from
        Morph's own arguments.

        Command line arguments:

        * `--` indicates the end of option processing for Morph.
        * `COMMAND` is a command to run.
        * `ARGS` is a list of arguments or options to be passed onto
          `COMMAND`.

        This runs the given `COMMAND` in each git repository belonging
        to the current system branch that exists locally in the current
        workspace.  This can be a handy way to do the same thing in all
        the local git repositories.

        For example:

            morph foreach -- git push

        The above command would push any committed changes in each
        repository to the git server.

        '''

        if not args:
            raise cliapp.AppException('morph foreach expects a command to run')

        ws = morphlib.workspace.open('.')
        sb = morphlib.sysbranchdir.open_from_within('.')

        for gd in sorted(sb.list_git_directories(), key=lambda gd: gd.dirname):
            # Get the repository's original name
            # Continue in the case of error, since the previous iteration
            # worked in the case of the user cloning a repository in the
            # system branch's directory.
            try:
                repo = gd.get_config('morph.repository')
            except cliapp.AppException:
                continue

            self.app.output.write('%s\n' % repo)
            status, output, error = self.app.runcmd_unchecked(
                args, cwd=gd.dirname)
            self.app.output.write(output)
            if status != 0:
                self.app.output.write(error)
                pretty_command = ' '.join(cliapp.shell_quote(arg)
                                          for arg in args)
                raise cliapp.AppException(
                    'Command failed at repo %s: %s'
                    % (repo, pretty_command))
            self.app.output.write('\n')
            self.app.output.flush()
Esempio n. 3
0
 def test_quotes_single_quote(self):
     self.assertEqual(cliapp.shell_quote("'"), '"\'"')
Esempio n. 4
0
 def test_quotes_double_quote(self):
     self.assertEqual(cliapp.shell_quote('"'), "'\"'")
Esempio n. 5
0
 def test_quotes_space(self):
     self.assertEqual(cliapp.shell_quote(' '), "' '")
Esempio n. 6
0
 def test_returns_same_string_when_safe(self):
     self.assertEqual(cliapp.shell_quote('abc123'), 'abc123')
Esempio n. 7
0
 def test_returns_empty_string_for_empty_string(self):
     self.assertEqual(cliapp.shell_quote(''), '')