Example #1
0
    def _exec_with_lock(self, exec_method, *method_args):
        lock_file = _os.path.join(self._repo_buddy_dir, 'lock')

        if not _os.path.isdir(self._repo_buddy_dir):
            # Create the .repobuddy directory if it does not exist already
            try:
                _os.mkdir(self._repo_buddy_dir)
            except OSError as err:
                raise CommandHandlerError('Error: ' + str(err))
        else:
            Logger.debug('Found an existing .repobuddy directory...')

        try:
            # Acquire the lock before doing anything else
            with FileLock(lock_file):
                Logger.debug('Lock \'' + lock_file + '\' acquired')
                exec_method(*method_args)
        except FileLockError as err:
            # If it is a timeout error, it could be one of the following:
            # *** another instance of repobuddy is running
            # *** repobuddy was killed earlier without releasing the lock file
            if err.isTimeOut:
                raise CommandHandlerError(
                    'Error: Lock file ' + lock_file + ' already exists\n' +
                    'Is another instance of repobuddy running ?')
            else:
                raise CommandHandlerError(str(err))
        except GitWrapperError as err:
            raise CommandHandlerError('Error: Git said => ' + str(err))

        return
Example #2
0
    def _exec_with_lock(self, exec_method, *method_args):
        lock_file = _os.path.join(self._repo_buddy_dir, 'lock')

        if not _os.path.isdir(self._repo_buddy_dir):
            # Create the .repobuddy directory if it does not exist already
            try:
                _os.mkdir(self._repo_buddy_dir)
            except OSError as err:
                raise CommandHandlerError('Error: ' + str(err))
        else:
            Logger.debug('Found an existing .repobuddy directory...')

        try:
            # Acquire the lock before doing anything else
            with FileLock(lock_file):
                Logger.debug('Lock \'' + lock_file + '\' acquired')
                exec_method(*method_args)
        except FileLockError as err:
            # If it is a timeout error, it could be one of the following:
            # *** another instance of repobuddy is running
            # *** repobuddy was killed earlier without releasing the lock file
            if err.isTimeOut:
                raise CommandHandlerError(
                    'Error: Lock file ' + lock_file + ' already exists\n' +
                    'Is another instance of repobuddy running ?')
            else:
                raise CommandHandlerError(str(err))
        except GitWrapperError as err:
            raise CommandHandlerError('Error: Git said => ' + str(err))

        return
Example #3
0
    def _exec_git(self,
                  command,
                  capture_std_out=False,
                  capture_std_err=False,
                  is_clone=False):
        if is_clone:
            git_command = _shlex.split('git ' + command)
        else:
            git_command = _shlex.split(
                'git --work-tree=. --git-dir=.git ' + command)
        Logger.debug('Exec: git %s' % command)
        try:
            kwargs = {}
            if capture_std_out:
                kwargs['stdout'] = _subprocess.PIPE
            if capture_std_err:
                kwargs['stderr'] = _subprocess.PIPE

            proc = _subprocess.Popen(
                git_command,
                cwd=self._base_dir,
                **kwargs)
            (out_msg, err_msg) = proc.communicate()
            return_code = proc.wait()

            if return_code != 0:
                if capture_std_err:
                    raise GitWrapperError(
                        'Command \'git %s\' failed' % command,
                        is_git_error=True,
                        git_error_msg=err_msg.rstrip())
                else:
                    raise GitWrapperError(
                        'Command \'git %s\' failed' % command,
                        is_git_error=True)

            if capture_std_out and capture_std_err:
                return (out_msg.rstrip(), err_msg.rstrip())
            elif capture_std_out:
                return out_msg.rstrip()
            elif capture_std_err:
                return err_msg.rstrip()
        except OSError as err:
            raise GitWrapperError(str(err), is_git_error=False)
        return
    def _exec_git(self,
                  command,
                  capture_std_out=False,
                  capture_std_err=False,
                  is_clone=False):
        if is_clone:
            git_command = _shlex.split('git ' + command)
        else:
            git_command = _shlex.split('git --work-tree=. --git-dir=.git ' +
                                       command)
        Logger.debug('Exec: git %s' % command)
        try:
            kwargs = {}
            if capture_std_out:
                kwargs['stdout'] = _subprocess.PIPE
            if capture_std_err:
                kwargs['stderr'] = _subprocess.PIPE

            proc = _subprocess.Popen(git_command, cwd=self._base_dir, **kwargs)
            (out_msg, err_msg) = proc.communicate()
            return_code = proc.wait()

            if return_code != 0:
                if capture_std_err:
                    raise GitWrapperError('Command \'git %s\' failed' %
                                          command,
                                          is_git_error=True,
                                          git_error_msg=err_msg.rstrip())
                else:
                    raise GitWrapperError('Command \'git %s\' failed' %
                                          command,
                                          is_git_error=True)

            if capture_std_out and capture_std_err:
                return (out_msg.rstrip(), err_msg.rstrip())
            elif capture_std_out:
                return out_msg.rstrip()
            elif capture_std_err:
                return err_msg.rstrip()
        except OSError as err:
            raise GitWrapperError(str(err), is_git_error=False)
        return