Exemple #1
0
    def run_svn_command(self, wire, cmd, **opts):
        path = wire.get('path', None)

        if path and os.path.isdir(path):
            opts['cwd'] = path

        safe_call = False
        if '_safe' in opts:
            safe_call = True

        svnenv = os.environ.copy()
        svnenv.update(opts.pop('extra_env', {}))

        _opts = {'env': svnenv, 'shell': False}

        try:
            _opts.update(opts)
            p = subprocessio.SubprocessIOChunker(cmd, **_opts)

            return ''.join(p), ''.join(p.error)
        except (EnvironmentError, OSError) as err:
            cmd = ' '.join(cmd)  # human friendly CMD
            tb_err = ("Couldn't run svn command (%s).\n"
                      "Original error was:%s\n"
                      "Call options:%s\n" % (cmd, err, _opts))
            log.exception(tb_err)
            if safe_call:
                return '', err
            else:
                raise exceptions.VcsException()(tb_err)
Exemple #2
0
 def wrapper(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except (ChecksumMismatch, WrongObjectException, MissingCommitError,
             ObjectMissing) as e:
         raise exceptions.LookupException(e.message)
     except (HangupException, UnexpectedCommandError) as e:
         raise exceptions.VcsException(e.message)
Exemple #3
0
def _handle_exception(result):
    exception_class = result.get('exception')
    if exception_class == 'HTTPLockedRC':
        raise exceptions.RepositoryLockedException(*result['exception_args'])
    elif exception_class == 'RepositoryError':
        raise exceptions.VcsException(*result['exception_args'])
    elif exception_class:
        raise Exception('Got remote exception "%s" with args "%s"' %
                        (exception_class, result['exception_args']))
Exemple #4
0
 def bulk_request(self, wire, rev, pre_load):
     result = {}
     for attr in pre_load:
         try:
             method = self._bulk_methods[attr]
             result[attr] = method(wire, rev)
         except KeyError:
             raise exceptions.VcsException(
                 'Unknown bulk attribute: "%s"' % attr)
     return result
Exemple #5
0
 def _bulk_request(_repo_id, _rev, _pre_load):
     result = {}
     for attr in pre_load:
         try:
             method = self._bulk_methods[attr]
             args = [wire, rev]
             result[attr] = method(*args)
         except KeyError as e:
             raise exceptions.VcsException(e)(
                 "Unknown bulk attribute: %s" % attr)
     return result
Exemple #6
0
    def run_git_command(self, wire, cmd, **opts):
        path = wire.get('path', None)

        if path and os.path.isdir(path):
            opts['cwd'] = path

        if '_bare' in opts:
            _copts = []
            del opts['_bare']
        else:
            _copts = [
                '-c',
                'core.quotepath=false',
            ]
        safe_call = False
        if '_safe' in opts:
            # no exc on failure
            del opts['_safe']
            safe_call = True

        if '_copts' in opts:
            _copts.extend(opts['_copts'] or [])
            del opts['_copts']

        gitenv = os.environ.copy()
        gitenv.update(opts.pop('extra_env', {}))
        # need to clean fix GIT_DIR !
        if 'GIT_DIR' in gitenv:
            del gitenv['GIT_DIR']
        gitenv['GIT_CONFIG_NOGLOBAL'] = '1'
        gitenv['GIT_DISCOVERY_ACROSS_FILESYSTEM'] = '1'

        cmd = [settings.GIT_EXECUTABLE] + _copts + cmd
        _opts = {'env': gitenv, 'shell': False}

        proc = None
        try:
            _opts.update(opts)
            proc = subprocessio.SubprocessIOChunker(cmd, **_opts)

            return ''.join(proc), ''.join(proc.error)
        except (EnvironmentError, OSError) as err:
            cmd = ' '.join(cmd)  # human friendly CMD
            tb_err = ("Couldn't run git command (%s).\n"
                      "Original error was:%s\n"
                      "Call options:%s\n" % (cmd, err, _opts))
            log.exception(tb_err)
            if safe_call:
                return '', err
            else:
                raise exceptions.VcsException()(tb_err)
        finally:
            if proc:
                proc.close()
Exemple #7
0
 def bulk_request(self, wire, rev, pre_load):
     result = {}
     for attr in pre_load:
         try:
             method = self._bulk_methods[attr]
             args = [wire, rev]
             if attr == "date":
                 args.extend(["commit_time", "commit_timezone"])
             elif attr in ["author", "message", "parents"]:
                 args.append(attr)
             result[attr] = method(*args)
         except KeyError:
             raise exceptions.VcsException("Unknown bulk attribute: %s" %
                                           attr)
     return result
Exemple #8
0
def _handle_exception(result):
    exception_class = result.get('exception')
    exception_traceback = result.get('exception_traceback')

    if exception_traceback:
        log.error('Got traceback from remote call:%s', exception_traceback)

    if exception_class == 'HTTPLockedRC':
        raise exceptions.RepositoryLockedException()(*result['exception_args'])
    elif exception_class == 'HTTPBranchProtected':
        raise exceptions.RepositoryBranchProtectedException()(*result['exception_args'])
    elif exception_class == 'RepositoryError':
        raise exceptions.VcsException()(*result['exception_args'])
    elif exception_class:
        raise Exception('Got remote exception "%s" with args "%s"' %
                        (exception_class, result['exception_args']))
Exemple #9
0
 def wrapper(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except (
             ChecksumMismatch,
             WrongObjectException,
             MissingCommitError,
             ObjectMissing,
     ) as e:
         exc = exceptions.LookupException(org_exc=e)
         raise exc(safe_str(e))
     except (HangupException, UnexpectedCommandError) as e:
         exc = exceptions.VcsException(org_exc=e)
         raise exc(safe_str(e))
     except Exception as e:
         # NOTE(marcink): becuase of how dulwich handles some exceptions
         # (KeyError on empty repos), we cannot track this and catch all
         # exceptions, it's an exceptions from other handlers
         #if not hasattr(e, '_vcs_kind'):
         #log.exception("Unhandled exception in git remote call")
         #raise_from_original(exceptions.UnhandledException)
         raise