author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 19 Apr 2013 16:25:45 +0200 | |
branch | stable |
changeset 8914 | e80dfffc2c2a |
parent 8032 | bcb87336c7d2 |
child 8985 | be04a3e01ac9 |
permissions | -rw-r--r-- |
8032
bcb87336c7d2
[doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7813
diff
changeset
|
1 |
.. _UsingPyro: |
bcb87336c7d2
[doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7813
diff
changeset
|
2 |
|
4749
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
3 |
Working with a distributed client (using Pyro) |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
4 |
============================================== |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
5 |
|
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
6 |
In some circumstances, it is practical to split the repository and |
7813
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
7 |
web-client parts of the application for load-balancing reasons. Or |
4749
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
8 |
one wants to access the repository from independant scripts to consult |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
9 |
or update the database. |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
10 |
|
7813
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
11 |
Prerequisites |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
12 |
------------- |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
13 |
|
4749
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
14 |
For this to work, several steps have to be taken in order. |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
15 |
|
7813
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
16 |
You must first ensure that the appropriate software is installed and |
8032
bcb87336c7d2
[doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7813
diff
changeset
|
17 |
running (see :ref:`ConfigEnv`):: |
4749
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
18 |
|
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
19 |
pyro-nsd -x -p 6969 |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
20 |
|
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
21 |
Then you have to set appropriate options in your configuration. For |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
22 |
instance:: |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
23 |
|
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
24 |
pyro-server=yes |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
25 |
pyro-ns-host=localhost:6969 |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
26 |
|
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
27 |
pyro-instance-id=myinstancename |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
28 |
|
7813
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
29 |
Connect to the CubicWeb repository from a python script |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
30 |
------------------------------------------------------- |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
31 |
|
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
32 |
Assuming pyro-nsd is running and your instance is configured with ``pyro-server=yes``, |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
33 |
you will be able to use :mod:`cubicweb.dbapi` api to initiate the connection. |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
34 |
|
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
35 |
.. note:: |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
36 |
Regardless of whether your instance is pyro activated or not, you can still |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
37 |
achieve this by using cubicweb-ctl shell scripts in a simpler way, as by default |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
38 |
it creates a repository 'in-memory' instead of connecting through pyro. That |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
39 |
also means you've to be on the host where the instance is running. |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
40 |
|
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
41 |
Finally, the client (for instance a python script) must connect specifically |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
42 |
as in the following example code: |
4749
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
43 |
|
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
44 |
.. sourcecode:: python |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
45 |
|
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
46 |
from cubicweb import dbapi |
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
47 |
|
7813
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
48 |
cnx = dbapi.connect(database='instance-id', user='admin', password='admin') |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
49 |
cnx.load_appobjects() |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
50 |
cur = cnx.cursor() |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
51 |
for name in (u'Personal', u'Professional', u'Computers'): |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
52 |
cur.execute('INSERT Tag T: T name %(n)s', {'n': name}) |
89ab98c4aaab
[book] merge pyro chapter with faq entry with connexion snippet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4749
diff
changeset
|
53 |
cnx.commit() |
4749
1560d51385f0
[book/admin/pyro] fix pyro options, give a small setup example
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
54 |
|
8032
bcb87336c7d2
[doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7813
diff
changeset
|
55 |
Calling :meth:`cubicweb.dbapi.load_appobjects`, will populate the |
bcb87336c7d2
[doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7813
diff
changeset
|
56 |
cubicweb registrires (see :ref:`VRegistryIntro`) with the application |
bcb87336c7d2
[doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7813
diff
changeset
|
57 |
objects installed on the host where the script runs. You'll then be |
bcb87336c7d2
[doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7813
diff
changeset
|
58 |
allowed to use the ORM goodies and custom entity methods and views. Of |
bcb87336c7d2
[doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7813
diff
changeset
|
59 |
course this is optional, without it you can still get the repository |
bcb87336c7d2
[doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7813
diff
changeset
|
60 |
data through the connection but in a roughly way: only RQL cursors |
bcb87336c7d2
[doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7813
diff
changeset
|
61 |
will be available, e.g. you can't even build entity objects from the |
bcb87336c7d2
[doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7813
diff
changeset
|
62 |
result set. |