Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] dump method for big databases #39

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions odoorpc/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
"""Provide the :class:`DB` class to manage the server databases."""
import base64
import io
import shutil
import sys
# Python 2
if sys.version_info[0] < 3:
from urllib import urlencode
def encode2bytes(data):
return data
# Python >= 3
else:
from urllib.parse import urlencode
def encode2bytes(data):
return bytes(data, 'ascii')

Expand Down Expand Up @@ -135,6 +138,25 @@ def dump(self, password, db, format_='zip'):
content = base64.standard_b64decode(result)
return io.BytesIO(content)

def dump_via_http_and_save_as(self, password, db, format_='zip', filename=None):
# first get Cookie if <= v9
# cf https://github.com/odoo/odoo/commit/54e4f3f96b0a93bbdee5cdffd6f671b812644a67
if v(self._odoo.version)[0] <= 9:
r = self._odoo.http('web/login?db=' + db)
r.read()

dump = self._odoo.http(
'web/database/backup',
urlencode({'master_pwd': password,
'name': db,
'backup_format': format_}))

if not filename:
filename = db + '.' + format_

with open(filename, 'wb') as f:
shutil.copyfileobj(dump, f)

def change_password(self, password, new_password):
"""Change the administrator password by `new_password`.

Expand Down