New in version 0.4.0.
The DB class represents the database management service. It provides functionalities such as list, create, drop, dump and restore databases.
Note
This service have to be used through the OERP.db property.
>>> import oerplib
>>> oerp = oerplib.OERP('localhost')
>>> oerp.db
<oerplib.service.db.DB object at 0xb75fb04c>
Warning
All methods documented below are not strictly implemented in OERPLib (except the create_and_wait method).
Method calls are purely dynamic, and the following documentation can be wrong if the API of OpenERP is changed between versions. Anyway, if you known the API used by the OpenERP server for the /db RPC service, it will work (see the tutorial <REF NEEDED>).
Return a list of the OpenERP databases:
>>> oerp.db.list()
>>> ['production_db', 'test_db']
Returns: | a list of database names |
---|
Return a list of codes and names of language supported by OpenERP:
>>> oerp.db.list_lang()
>>> [['sq_AL', u'Albanian / Shqipëri'], ['ar_AR', 'Arabic / الْعَرَبيّة'], ...]
Returns: | a list of pairs representing languages with their codes and names |
---|
Return the version of the OpenERP Server:
>>> oerp.db.server_version()
>>> '6.1'
Returns: | the version of the OpenERP Server as string |
---|
Return a dump of database in base64:
>>> binary_data = oerp.db.dump('super_admin_passwd', 'production_db')
The super administrator password super_admin_passwd of OpenERP is required to perform this action.
Returns: | the base64 string representation of the database |
---|
Restore in database a dump previously created with the dump method:
>>> oerp.db.restore('super_admin_passwd', 'test_db', binary_data)
The super administrator password super_admin_passwd of OpenERP is required to perform this action.
Drop the database from OpenERP:
>>> oerp.db.drop('super_admin_passwd', 'test_db')
True
The super administrator password super_admin_passwd of OpenERP is required to perform this action.
Returns: | True |
---|
Request the OpenERP server to create a new database named database which will have admin_passwd as administrator password and localized with the lang parameter. You have to set the flag demo_data to True in order to insert demonstration data.
As the creating process may take some time, you can execute the get_process method with the database ID returned to know its current state.
>>> database_id = oerp.db.create('super_admin_passwd', 'test_db', False, 'fr_FR', 'my_admin_passwd')
The super administrator password super_admin_passwd of OpenERP is required to perform this action.
Returns: | the ID of the new database |
---|
Check the state of the creating process for the database identified by the database_id parameter.
>>> oerp.db.get_process('super_admin_passwd', database_id) # Just after the call to the 'create' method
(0, [])
>>> oerp.db.get_process('super_admin_passwd', database_id) # Once the database is fully created
(1.0, [{'login': u'admin', 'password': u'admin', 'name': u'Administrator'},
{'login': u'demo', 'password': u'demo', 'name': u'Demo User'}])
Returns: | A tuple with the progressing state and a list of user accounts created (once the database is fully created). |
---|
Note
This method is not part of the official API of OpenERP. It’s just a wrapper around the create and get_process methods.
Like the create method, but waits the end of the creating process by executing the get_process method regularly to check its state.
>>> oerp.db.create_and_wait('super_admin_passwd', 'test_db', False, 'fr_FR', 'my_admin_passwd')
[{'login': u'admin', 'password': u'admin', 'name': u'Administrator'},
{'login': u'demo', 'password': u'demo', 'name': u'Demo User'}]
The super administrator password super_admin_passwd of OpenERP is required to perform this action.
Returns: | a list of user accounts created |
---|---|
Raise: | oerplib.error.RPCError |