oerplib.service.db

class oerplib.service.db.DB(oerp)

New in version 0.4.

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 oerplib.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 know the API used by the OpenERP server for the /db RPC service, it will work.

list()

Return a list of the OpenERP databases:

>>> oerp.db.list()
['prod_db', 'test_db']
Returns:a list of database names
list_lang()

Return a list of codes and names of language supported by OpenERP:

>>> oerp.db.list_lang()
[['sq_AL', 'Albanian / Shqipëri'], ['ar_AR', 'Arabic / الْعَرَبيّة'], ...]
Returns:a list of pairs representing languages with their codes and names
server_version()

Return the version of the OpenERP Server:

>>> oerp.db.server_version()
'6.1'
Returns:the version of the OpenERP Server as string
dump(super_admin_passwd, database)

Return a dump of database in base64:

>>> binary_data = oerp.db.dump('super_admin_passwd', 'prod_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(super_admin_passwd, database, binary_data)

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(super_admin_passwd, database)

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
create(super_admin_passwd, database, demo_data=False, lang='en_US', admin_passwd='admin')

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_progress 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
get_progress(super_admin_passwd, database_id)

Check the state of the creating process for the database identified by the database_id parameter.

>>> oerp.db.get_progress('super_admin_passwd', database_id) # Just after the call to the 'create' method
(0, [])
>>> oerp.db.get_progress('super_admin_passwd', database_id) # Once the database is fully created
(1.0, [{'login': 'admin', 'password': 'admin', 'name': 'Administrator'},
       {'login': 'demo', 'password': 'demo', 'name': 'Demo User'}])

The super administrator password super_admin_passwd of OpenERP is required to perform this action.

Returns:A tuple with the progressing state and a list of user accounts created (once the database is fully created).
create_database(super_admin_passwd, database, demo_data=False, lang='en_US', admin_passwd='admin')

Available since OpenERP 6.1

Similar to create but blocking.

>>> oerp.db.create_database('super_admin_passwd', 'test_db', False, 'fr_FR', 'my_admin_passwd')
True

The super administrator password super_admin_passwd of OpenERP is required to perform this action.

Returns:True
duplicate_database(super_admin_passwd, original_database, database)

Available since OpenERP 7.0

Duplicate original_database’ as `database.

>>> oerp.db.duplicate_database('super_admin_passwd', 'prod_db', 'test_db')
True

The super administrator password super_admin_passwd of OpenERP is required to perform this action.

Returns:True
rename(super_admin_passwd, old_name, new_name)

Rename the old_name database to new_name.

>>> oerp.db.rename('super_admin_passwd', 'test_db', 'test_db2')
True

The super administrator password super_admin_passwd of OpenERP is required to perform this action.

Returns:True
db_exist(database)

Check if connection to database is possible.

>>> oerp.db.db_exist('prod_db')
True
Returns:True or False
change_admin_password(super_admin_passwd, new_passwd)

Change the administrator password by new_passwd.

>>> oerp.db.change_admin_password('super_admin_passwd', 'new_passwd')
True

The super administrator password super_admin_passwd of OpenERP is required to perform this action.

Returns:True
create_and_wait(super_admin_passwd, database, demo_data=False, lang='en_US', admin_passwd='admin')

Note

This method is not part of the official API of OpenERP. It’s just a wrapper around the create and get_progress methods. For OpenERP in version 6.1 or above, please prefer the use of the standard create_database method.

Like the create method, but waits the end of the creating process by executing the get_progress method regularly to check its state.

>>> oerp.db.create_and_wait('super_admin_passwd', 'test_db', False, 'fr_FR', 'my_admin_passwd')
[{'login': 'admin', 'password': 'my_admin_passwd', 'name': 'Administrateur'},
 {'login': 'demo', 'password': 'demo', 'name': '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

Previous topic

oerplib.service.common

Next topic

oerplib.service.wizard

This Page