Skip to content

Commit

Permalink
replace duplicate_database with a simpler clone_database method
Browse files Browse the repository at this point in the history
  • Loading branch information
florentx committed Nov 21, 2018
1 parent fff73e8 commit 41de72e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Changelog

* Fully support Odoo 10 and Odoo 11.

* New method ``Client.clone_database`` based on ``Client.db.duplicate_database``.


1.6.3 (2015-12-30)
~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ list or install Odoo add-ons.

.. automethod:: Client.create_database

.. automethod:: Client.duplicate_database
.. automethod:: Client.clone_database

.. automethod:: Client.login

Expand Down
17 changes: 6 additions & 11 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,27 +120,22 @@ Default password is ``"admin"``.
Then we connect to any environment with ``erppeek --env demo`` or switch
during an interactive session with ``client.connect('demo')``.

Duplicate a database
Clone a database
--------------------

It is sometimes useful to duplicate a database (testing, backup,
migration, ...). A shortcut is available for that, the required
parameters are the original database name, the new database name and
the superadmin password (this is the ``admin_passwd`` in the
``odoo-server.conf`` file). Default password is ``"admin"``.

.. note:: This password gives full control on the databases. Set a strong
password in the configuration to prevent unauthorized access.
It is sometimes useful to clone a database (testing, backup, migration, ...).
A shortcut is available for that, the required parameters are the new
database name and the superadmin password.


.. sourcecode:: pycon

>>> client.duplicate_database('super_password', 'demo', 'demo_test')
>>> client.clone_database('super_password', 'demo_test')
Logged in as 'admin'
>>> client
<Client 'http://localhost:8069#demo_test'>
>>> client.db.list()
['demo_test']
['demo', 'demo_test']
>>> client.user
'admin'
>>> client.modules(installed=True)
Expand Down
21 changes: 12 additions & 9 deletions erppeek.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ def create_database(self, passwd, database, demo=False, lang='en_US',
The superadmin `passwd` and the `database` name are mandatory.
By default, `demo` data are not loaded and `lang` is ``en_US``.
Wait for the thread to finish and login if successful.
Login if successful.
"""
if self.major_version in ('5.0', '6.0'):
thread_id = self.db.create(passwd, database, demo, lang,
Expand All @@ -662,16 +662,19 @@ def create_database(self, passwd, database, demo=False, lang='en_US',
user_password)
return self.login('admin', user_password, database=database)

def duplicate_database(self, passwd, db_original_name, db_name,
user_password='admin'):
"""Duplicate an existing database.
def clone_database(self, passwd, db_name):
"""Clone the current database.
The superadmin `passwd`, `db_original_name` and `db_name` are
mandatory.
Wait for the thread to finish and login if successful.
The superadmin `passwd` and `db_name` are mandatory.
Login if successful.
Supported since OpenERP 7.
"""
self.db.duplicate_database(passwd, db_original_name, db_name)
return self.login('admin', user_password, database=db_name)
self.db.duplicate_database(passwd, self._db, db_name)

# Login with the current user into the new database
(uid, password) = self._auth(self._db, self.user, None)
return self.login(self.user, password, database=db_name)

def execute(self, obj, method, *params, **kwargs):
"""Wrapper around ``object.execute`` RPC method.
Expand Down

0 comments on commit 41de72e

Please sign in to comment.