Exemplo n.º 1
0
    def __call__(self, arguments):
        """
            performs the given command using the given arguments.
        """
        filtered_arguments = self._filter_unused_argument_dash_m(arguments)
        configuration = self._read_configuration_file()

        if len(filtered_arguments) > 1:
            filtered_arguments = self._handle_debug_argument(
                filtered_arguments)
            self._handle_version_argument(filtered_arguments)
            self._handle_help_argument(filtered_arguments)

        if configuration.execute_before:
            LOGGER.debug('Executing command "%s" before doing anything else.',
                         configuration.execute_before)
            command_and_arguments = configuration.execute_before.split()
            execute_command(command_and_arguments[0],
                            *command_and_arguments[1:])

        try:
            self.function(filtered_arguments, configuration)
            return exit(0)

        except errors.CommitterError as committer_exception:
            LOGGER.error(committer_exception.message)
            return exit(committer_exception.error_code)

        except KeyboardInterrupt:
            LOGGER.error('Interrupted by user.\n')
            return exit(1)
Exemplo n.º 2
0
    def __call__(self, arguments):
        """
            performs the given command using the given arguments.
        """
        filtered_arguments = self._filter_unused_argument_dash_m(arguments)
        configuration = load_configuration()

        if len(filtered_arguments) > 1:
            filtered_arguments = self._handle_debug_argument(filtered_arguments)
            self._handle_version_argument(filtered_arguments)
            self._handle_help_argument(filtered_arguments)

        if configuration.execute_before:
            LOGGER.debug('Executing command "%s" before doing anything else.', configuration.execute_before)
            command_and_arguments = configuration.execute_before.split()
            execute_command(command_and_arguments[0], *command_and_arguments[1:])

        try:
            self.function(filtered_arguments, configuration)
            return exit(0)

        except errors.CommitterError as committer_exception:
            LOGGER.error(committer_exception.message)
            return exit(committer_exception.error_code)

        except KeyboardInterrupt:
            LOGGER.error('Interrupted by user.\n')
            return exit(1)
Exemplo n.º 3
0
    def test_should_not_log_stdout_when_stdout_is_empty_string(self):
        stdout = ''
        when(self.process_mock).communicate().then_return((stdout, 'stderr'))
        when(execution).Popen(ANY_ARGUMENTS).then_return(self.process_mock)

        execute_command('command', '1', '2', '3')

        verify(execution.LOGGER, NEVER).info(stdout)
Exemplo n.º 4
0
    def test_should_call_command_using_given_arguments(self):
        when(self.process_mock).communicate().then_return(('stdout', 'stderr'))
        when(execution).Popen(ANY_ARGUMENTS).then_return(self.process_mock)

        execute_command('command', '1', '2', '3')

        verify(execution).Popen(['command', '1', '2', '3'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
        verify(self.process_mock).communicate()
Exemplo n.º 5
0
    def test_should_log_stderr_when_stderr_is_not_empty_string(self):

        stderr = 'stderr'
        when(self.process_mock).communicate().then_return(('stdout', stderr))
        when(execution).Popen(ANY_ARGUMENTS).then_return(self.process_mock)

        execute_command('command', '1', '2', '3')

        verify(execution.LOGGER).error(stderr)
Exemplo n.º 6
0
    def test_should_catch_os_error_and_exit_when_popen_raises_exception(self):
        self.process_mock.returncode = 123
        when(self.process_mock).communicate().then_return(('stdout', ''))
        when(execution).Popen(ANY_ARGUMENTS).then_raise(OSError("[Errno 2] No such file or directory"))
        when(execution).exit(ANY_ARGUMENTS).then_return(None)

        execute_command('command', '1', '2', '3')

        verify(execution).exit(1)
Exemplo n.º 7
0
def commit_changes(arguments, configuration):

    if configuration.execute_before_commit:
        command_and_arguments = configuration.execute_before_commit.split()
        execute_command(command_and_arguments[0], *command_and_arguments[1:])

    commit(arguments)

    if configuration.motivate_me:
        execute_motivation_command(configuration)
Exemplo n.º 8
0
    def test_should_exit_when_execution_of_command_failed(self):

        self.process_mock.returncode = 123
        when(self.process_mock).communicate().then_return(('stdout', ''))
        when(execution).Popen(ANY_ARGUMENTS).then_return(self.process_mock)
        when(execution).exit(ANY_ARGUMENTS).then_return(None)

        execute_command('command', '1', '2', '3')

        verify(execution).exit(1)
Exemplo n.º 9
0
    def _svn(self, *arguments):
        """
            Executes svn using the given arguments.

            @return: execution result
        """
        return execute_command(self.command, *arguments)
Exemplo n.º 10
0
    def _hg(self, *arguments):
        """
            Executes hg using the given arguments.

            @return: the execution result
        """
        return execute_command(self.command, *arguments)
Exemplo n.º 11
0
    def _svn(self, *arguments):
        """
            Executes svn using the given arguments.

            @return: execution result
        """
        return execute_command(self.command, *arguments)
Exemplo n.º 12
0
    def _hg(self, *arguments):
        """
            Executes hg using the given arguments.

            @return: the execution result
        """
        return execute_command(self.command, *arguments)
Exemplo n.º 13
0
    def test_should_return_stdout_and_stderr_and_returncode_when_executing_command(self):
        stdout = 'stdout'
        stderr = 'stderr'
        when(self.process_mock).communicate().then_return((stdout, stderr))
        when(execution).Popen(ANY_ARGUMENTS).then_return(self.process_mock)

        actual = execute_command('command', '1', '2', '3')

        self.assertEqual(stdout, actual['stdout'])
        self.assertEqual(stderr, actual['stderr'])
        self.assertEqual(0, actual['returncode'])
Exemplo n.º 14
0
def commit_changes(arguments, configuration=None):
    if configuration.execute_before_commit:
        command_and_arguments = configuration.execute_before_commit.split()
        execute_command(command_and_arguments[0], *command_and_arguments[1:])

    commit(arguments)
Exemplo n.º 15
0
 def _git(self, *arguments):
     """
         Executes git using the given arguments.
     """
     return execute_command(self.command, *arguments)
Exemplo n.º 16
0
 def _git(self, *arguments):
     """
         Executes git using the given arguments.
     """
     return execute_command(self.command, *arguments)
def commit_changes(arguments, configuration=None):
    if configuration.execute_before_commit:
        command_and_arguments = configuration.execute_before_commit.split()
        execute_command(command_and_arguments[0], *command_and_arguments[1:])

    commit(arguments)