21 _ = unicode |
21 _ = unicode |
22 |
22 |
23 import threading |
23 import threading |
24 from Pyro.errors import PyroError, ConnectionClosedError |
24 from Pyro.errors import PyroError, ConnectionClosedError |
25 |
25 |
26 from logilab.common.configuration import REQUIRED |
|
27 |
|
28 from cubicweb import dbapi |
|
29 from cubicweb import ConnectionError |
26 from cubicweb import ConnectionError |
30 from cubicweb.server.sources import ConnectionWrapper |
27 from cubicweb.server.sources import ConnectionWrapper |
31 |
28 |
32 from cubicweb.server.sources.remoterql import RemoteSource |
29 from cubicweb.server.sources.remoterql import RemoteSource |
33 |
30 |
34 class PyroRQLSource(RemoteSource): |
31 class PyroRQLSource(RemoteSource): |
35 """External repository source, using Pyro connection""" |
32 """External repository source, using Pyro connection""" |
36 |
|
37 CNX_TYPE = 'pyro' |
|
38 |
|
39 options = RemoteSource.options + ( |
|
40 # XXX pyro-ns host/port |
|
41 ('pyro-ns-id', |
|
42 {'type' : 'string', |
|
43 'default': REQUIRED, |
|
44 'help': 'identifier of the repository in the pyro name server', |
|
45 'group': 'remote-source', 'level': 0, |
|
46 }), |
|
47 ('pyro-ns-host', |
|
48 {'type' : 'string', |
|
49 'default': None, |
|
50 'help': 'Pyro name server\'s host. If not set, default to the value \ |
|
51 from all_in_one.conf. It may contains port information using <host>:<port> notation.', |
|
52 'group': 'remote-source', 'level': 1, |
|
53 }), |
|
54 ('pyro-ns-group', |
|
55 {'type' : 'string', |
|
56 'default': None, |
|
57 'help': 'Pyro name server\'s group where the repository will be \ |
|
58 registered. If not set, default to the value from all_in_one.conf.', |
|
59 'group': 'remote-source', 'level': 2, |
|
60 }), |
|
61 ) |
|
62 |
|
63 def _get_connection(self): |
|
64 """open and return a connection to the source""" |
|
65 nshost = self.config.get('pyro-ns-host') or self.repo.config['pyro-ns-host'] |
|
66 nsgroup = self.config.get('pyro-ns-group') or self.repo.config['pyro-ns-group'] |
|
67 self.info('connecting to instance :%s.%s for user %s', |
|
68 nsgroup, self.config['pyro-ns-id'], self.config['cubicweb-user']) |
|
69 return dbapi.connect(database=self.config['pyro-ns-id'], |
|
70 login=self.config['cubicweb-user'], |
|
71 password=self.config['cubicweb-password'], |
|
72 host=nshost, group=nsgroup, |
|
73 setvreg=False) |
|
74 |
33 |
75 def get_connection(self): |
34 def get_connection(self): |
76 try: |
35 try: |
77 return self._get_connection() |
36 return self._get_connection() |
78 except (ConnectionError, PyroError), ex: |
37 except (ConnectionError, PyroError), ex: |