repoapi.py
changeset 10235 684215aca046
parent 10087 ed0b076c119b
child 10236 ef3059a692cb
equal deleted inserted replaced
10232:cda1bdc3652e 10235:684215aca046
     1 # copyright 2013-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2013-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    39 def get_repository(uri=None, config=None, vreg=None):
    39 def get_repository(uri=None, config=None, vreg=None):
    40     """get a repository for the given URI or config/vregistry (in case we're
    40     """get a repository for the given URI or config/vregistry (in case we're
    41     loading the repository for a client, eg web server, configuration).
    41     loading the repository for a client, eg web server, configuration).
    42 
    42 
    43     The returned repository may be an in-memory repository or a proxy object
    43     The returned repository may be an in-memory repository or a proxy object
    44     using a specific RPC method, depending on the given URI (pyro or zmq).
    44     using a specific RPC method, depending on the given URI.
    45     """
    45     """
    46     if uri is None:
    46     if uri is None:
    47         return _get_inmemory_repo(config, vreg)
    47         return _get_inmemory_repo(config, vreg)
    48 
    48 
    49     protocol, hostport, appid = parse_repo_uri(uri)
    49     protocol, hostport, appid = parse_repo_uri(uri)
    50 
    50 
    51     if protocol == 'inmemory':
    51     if protocol == 'inmemory':
    52         # me may have been called with a dummy 'inmemory://' uri ...
    52         # me may have been called with a dummy 'inmemory://' uri ...
    53         return _get_inmemory_repo(config, vreg)
    53         return _get_inmemory_repo(config, vreg)
    54 
       
    55     if protocol == 'pyroloc':  # direct connection to the instance
       
    56         from logilab.common.pyro_ext import get_proxy
       
    57         uri = uri.replace('pyroloc', 'PYRO')
       
    58         return get_proxy(uri)
       
    59 
       
    60     if protocol == 'pyro':  # connection mediated through the pyro ns
       
    61         from logilab.common.pyro_ext import ns_get_proxy
       
    62         path = appid.strip('/')
       
    63         if not path:
       
    64             raise ConnectionError(
       
    65                 "can't find instance name in %s (expected to be the path component)"
       
    66                 % uri)
       
    67         if '.' in path:
       
    68             nsgroup, nsid = path.rsplit('.', 1)
       
    69         else:
       
    70             nsgroup = 'cubicweb'
       
    71             nsid = path
       
    72         return ns_get_proxy(nsid, defaultnsgroup=nsgroup, nshost=hostport)
       
    73 
    54 
    74     if protocol.startswith('zmqpickle-'):
    55     if protocol.startswith('zmqpickle-'):
    75         from cubicweb.zmqclient import ZMQRepositoryClient
    56         from cubicweb.zmqclient import ZMQRepositoryClient
    76         return ZMQRepositoryClient(uri)
    57         return ZMQRepositoryClient(uri)
    77     else:
    58     else: