odoorpc.db

Provide the DB class to manage the server databases.

class odoorpc.db.DB(odoo)

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 odoorpc.ODOO.db property.

>>> import odoorpc
>>> odoo = odoorpc.ODOO('localhost')    
>>> odoo.db
<odoorpc.db.DB object at 0x...>
change_password(password, new_password)

Change the administrator password by new_password.

>>> odoo.db.change_password('super_admin_passwd', 'new_admin_passwd') 

The super administrator password is required to perform this method.

Python 2:

Raise

odoorpc.error.RPCError (access denied)

Raise

urllib2.URLError (connection error)

Python 3:

Raise

odoorpc.error.RPCError (access denied)

Raise

urllib.error.URLError (connection error)

create(password, db, demo=False, lang='en_US', admin_password='admin')

Request the server to create a new database named db which will have admin_password as administrator password and localized with the lang parameter. You have to set the flag demo to True in order to insert demonstration data.

>>> odoo.db.create('super_admin_passwd', 'prod', False, 'fr_FR', 'my_admin_passwd') 

If you get a timeout error, increase this one before performing the request:

>>> timeout_backup = odoo.config['timeout']
>>> odoo.config['timeout'] = 600    # Timeout set to 10 minutes
>>> odoo.db.create('super_admin_passwd', 'prod', False, 'fr_FR', 'my_admin_passwd') 
>>> odoo.config['timeout'] = timeout_backup

The super administrator password is required to perform this method.

Python 2:

Raise

odoorpc.error.RPCError (access denied)

Raise

urllib2.URLError (connection error)

Python 3:

Raise

odoorpc.error.RPCError (access denied)

Raise

urllib.error.URLError (connection error)

drop(password, db)

Drop the db database. Returns True if the database was removed, False otherwise (database did not exist):

>>> odoo.db.drop('super_admin_passwd', 'test') 
True

The super administrator password is required to perform this method.

Python 2:

Returns

True or False

Raise

odoorpc.error.RPCError (access denied)

Raise

urllib2.URLError (connection error)

Python 3:

Returns

True or False

Raise

odoorpc.error.RPCError (access denied)

Raise

urllib.error.URLError (connection error)

dump(password, db, format_='zip')

Backup the db database. Returns the dump as a binary ZIP file containing the SQL dump file alongside the filestore directory (if any).

>>> dump = odoo.db.dump('super_admin_passwd', 'prod') 

If you get a timeout error, increase this one before performing the request:

>>> timeout_backup = odoo.config['timeout']
>>> odoo.config['timeout'] = 600    # Timeout set to 10 minutes
>>> dump = odoo.db.dump('super_admin_passwd', 'prod')   
>>> odoo.config['timeout'] = timeout_backup

Write it on the file system:

>>> with open('dump.zip', 'wb') as dump_zip:
...     dump_zip.write(dump.read())
...

You can manipulate the file with the zipfile module for instance:

>>> import zipfile
>>> zipfile.ZipFile('dump.zip').namelist()
['dump.sql',
'filestore/ef/ef2c882a36dbe90fc1e7e28d816ad1ac1464cfbb',
'filestore/dc/dcf00aacce882bbfd117c0277e514f829b4c5bf0',
 ...]

The super administrator password is required to perform this method.

Python 2:

Returns

io.BytesIO

Raise

odoorpc.error.RPCError (access denied / wrong database)

Raise

urllib2.URLError (connection error)

Python 3:

Returns

io.BytesIO

Raise

odoorpc.error.RPCError (access denied / wrong database)

Raise

urllib.error.URLError (connection error)

duplicate(password, db, new_db)

Duplicate db’ as `new_db.

>>> odoo.db.duplicate('super_admin_passwd', 'prod', 'test') 

The super administrator password is required to perform this method.

Python 2:

Raise

odoorpc.error.RPCError (access denied / wrong database)

Raise

urllib2.URLError (connection error)

Python 3:

Raise

odoorpc.error.RPCError (access denied / wrong database)

Raise

urllib.error.URLError (connection error)

list()

Return the list of the databases:

>>> odoo.db.list() 
['prod', 'test']

Python 2:

Returns

list of database names

Raise

urllib2.URLError (connection error)

Python 3:

Returns

list of database names

Raise

urllib.error.URLError (connection error)

restore(password, db, dump, copy=False)

Restore the dump database into the new db database. The dump file object can be obtained with the dump method. If copy is set to True, the restored database will have a new UUID.

>>> odoo.db.restore('super_admin_passwd', 'test', dump_file) 

If you get a timeout error, increase this one before performing the request:

>>> timeout_backup = odoo.config['timeout']
>>> odoo.config['timeout'] = 7200   # Timeout set to 2 hours
>>> odoo.db.restore('super_admin_passwd', 'test', dump_file) 
>>> odoo.config['timeout'] = timeout_backup

The super administrator password is required to perform this method.

Python 2:

Raise

odoorpc.error.RPCError (access denied / database already exists)

Raise

odoorpc.error.InternalError (dump file closed)

Raise

urllib2.URLError (connection error)

Python 3:

Raise

odoorpc.error.RPCError (access denied / database already exists)

Raise

odoorpc.error.InternalError (dump file closed)

Raise

urllib.error.URLError (connection error)