vcs: Remove dead code.
This commit is contained in:
parent
272d4625b1
commit
aab8b8038b
1 changed files with 0 additions and 136 deletions
|
|
@ -25,15 +25,10 @@ Provides the implementation of various client utilities to reach the vcsserver.
|
|||
|
||||
import copy
|
||||
import logging
|
||||
import threading
|
||||
import urlparse
|
||||
import uuid
|
||||
import weakref
|
||||
from urllib2 import URLError
|
||||
|
||||
import msgpack
|
||||
import Pyro4
|
||||
import requests
|
||||
from pyramid.threadlocal import get_current_request
|
||||
from Pyro4.errors import CommunicationError, ConnectionClosedError, DaemonError
|
||||
|
||||
|
|
@ -43,137 +38,6 @@ from rhodecode.lib.vcs.conf import settings
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# TODO: mikhail: Keep it in sync with vcsserver's
|
||||
# HTTPApplication.ALLOWED_EXCEPTIONS
|
||||
EXCEPTIONS_MAP = {
|
||||
'KeyError': KeyError,
|
||||
'URLError': URLError,
|
||||
}
|
||||
|
||||
|
||||
class HTTPRepoMaker(object):
|
||||
def __init__(self, server_and_port, backend_endpoint):
|
||||
self.url = urlparse.urljoin(
|
||||
'http://%s' % server_and_port, backend_endpoint)
|
||||
|
||||
def __call__(self, path, config, with_wire=None):
|
||||
log.debug('HTTPRepoMaker call on %s', path)
|
||||
return HTTPRemoteRepo(path, config, self.url, with_wire=with_wire)
|
||||
|
||||
def __getattr__(self, name):
|
||||
def f(*args, **kwargs):
|
||||
return self._call(name, *args, **kwargs)
|
||||
return f
|
||||
|
||||
@exceptions.map_vcs_exceptions
|
||||
def _call(self, name, *args, **kwargs):
|
||||
payload = {
|
||||
'id': str(uuid.uuid4()),
|
||||
'method': name,
|
||||
'params': {'args': args, 'kwargs': kwargs}
|
||||
}
|
||||
return _remote_call(self.url, payload, EXCEPTIONS_MAP)
|
||||
|
||||
|
||||
class VcsHttpProxy(object):
|
||||
|
||||
CHUNK_SIZE = 16384
|
||||
|
||||
def __init__(self, server_and_port, backend_endpoint):
|
||||
adapter = requests.adapters.HTTPAdapter(max_retries=5)
|
||||
self.base_url = urlparse.urljoin(
|
||||
'http://%s' % server_and_port, backend_endpoint)
|
||||
self.session = requests.Session()
|
||||
self.session.mount('http://', adapter)
|
||||
|
||||
def handle(self, environment, input_data, *args, **kwargs):
|
||||
data = {
|
||||
'environment': environment,
|
||||
'input_data': input_data,
|
||||
'args': args,
|
||||
'kwargs': kwargs
|
||||
}
|
||||
result = self.session.post(
|
||||
self.base_url, msgpack.packb(data), stream=True)
|
||||
return self._get_result(result)
|
||||
|
||||
def _deserialize_and_raise(self, error):
|
||||
exception = Exception(error['message'])
|
||||
try:
|
||||
exception._vcs_kind = error['_vcs_kind']
|
||||
except KeyError:
|
||||
pass
|
||||
raise exception
|
||||
|
||||
def _iterate(self, result):
|
||||
unpacker = msgpack.Unpacker()
|
||||
for line in result.iter_content(chunk_size=self.CHUNK_SIZE):
|
||||
unpacker.feed(line)
|
||||
for chunk in unpacker:
|
||||
yield chunk
|
||||
|
||||
def _get_result(self, result):
|
||||
iterator = self._iterate(result)
|
||||
error = iterator.next()
|
||||
if error:
|
||||
self._deserialize_and_raise(error)
|
||||
|
||||
status = iterator.next()
|
||||
headers = iterator.next()
|
||||
|
||||
return iterator, status, headers
|
||||
|
||||
|
||||
class HTTPRemoteRepo(object):
|
||||
def __init__(self, path, config, url, with_wire=None):
|
||||
self.url = url
|
||||
self._wire = {
|
||||
"path": path,
|
||||
"config": config,
|
||||
"context": str(uuid.uuid4()),
|
||||
}
|
||||
if with_wire:
|
||||
self._wire.update(with_wire)
|
||||
|
||||
def __getattr__(self, name):
|
||||
def f(*args, **kwargs):
|
||||
return self._call(name, *args, **kwargs)
|
||||
return f
|
||||
|
||||
@exceptions.map_vcs_exceptions
|
||||
def _call(self, name, *args, **kwargs):
|
||||
log.debug('Calling %s@%s', self.url, name)
|
||||
# TODO: oliver: This is currently necessary pre-call since the
|
||||
# config object is being changed for hooking scenarios
|
||||
wire = copy.deepcopy(self._wire)
|
||||
wire["config"] = wire["config"].serialize()
|
||||
payload = {
|
||||
'id': str(uuid.uuid4()),
|
||||
'method': name,
|
||||
'params': {'wire': wire, 'args': args, 'kwargs': kwargs}
|
||||
}
|
||||
return _remote_call(self.url, payload, EXCEPTIONS_MAP)
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self.revision(key)
|
||||
|
||||
|
||||
def _remote_call(url, payload, exceptions_map):
|
||||
response = requests.post(url, data=msgpack.packb(payload))
|
||||
response = msgpack.unpackb(response.content)
|
||||
error = response.get('error')
|
||||
if error:
|
||||
type_ = error.get('type', 'Exception')
|
||||
exc = exceptions_map.get(type_, Exception)
|
||||
exc = exc(error.get('message'))
|
||||
try:
|
||||
exc._vcs_kind = error['_vcs_kind']
|
||||
except KeyError:
|
||||
pass
|
||||
raise exc
|
||||
return response.get('result')
|
||||
|
||||
|
||||
class RepoMaker(object):
|
||||
|
||||
def __init__(self, proxy_factory):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue