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

16.0 : DeprecationWarning: Since 16.0, use subprocess directly. #252

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion auto_backup/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'author': "Yenthe Van Ginneken",
'website': "http://www.odoo.yenthevg.com",
'category': 'Administration',
'version': '16.0.0.1',
'version': '16.0.0.2',
'installable': True,
'license': 'LGPL-3',

Expand Down
14 changes: 7 additions & 7 deletions auto_backup/models/db_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import shutil
import json
import tempfile

import subprocess
from odoo import models, fields, api, tools, _
from odoo.exceptions import Warning, AccessDenied
import odoo

from odoo.tools import find_pg_tool, exec_pg_environ
import logging
_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -276,16 +276,16 @@ def schedule_backup(self):
def _take_dump(self, db_name, stream, model, backup_format='zip'):
"""Dump database `db` into file-like object `stream` if stream is None
return a file object with the dump """

env = exec_pg_environ()
cron_user_id = self.env.ref('auto_backup.backup_scheduler').user_id.id
if self._name != 'db.backup' or cron_user_id != self.env.user.id:
_logger.error('Unauthorized database operation. Backups should only be available from the cron job.')
raise AccessDenied()

_logger.info('DUMP DB: %s format %s', db_name, backup_format)

cmd = ['pg_dump', '--no-owner']
cmd.append(db_name)
cmd = [find_pg_tool('pg_dump'), '--no-owner', db_name]
# cmd.append(db_name)

if backup_format == 'zip':
with tempfile.TemporaryDirectory() as dump_dir:
Expand All @@ -297,7 +297,7 @@ def _take_dump(self, db_name, stream, model, backup_format='zip'):
with db.cursor() as cr:
json.dump(self._dump_db_manifest(cr), fh, indent=4)
cmd.insert(-1, '--file=' + os.path.join(dump_dir, 'dump.sql'))
odoo.tools.exec_pg_command(*cmd)
subprocess.run(cmd, env=env, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=True)
if stream:
odoo.tools.osutil.zip_dir(dump_dir, stream, include_dir=False, fnct_sort=lambda file_name: file_name != 'dump.sql')
else:
Expand All @@ -307,7 +307,7 @@ def _take_dump(self, db_name, stream, model, backup_format='zip'):
return t
else:
cmd.insert(-1, '--format=c')
stdin, stdout = odoo.tools.exec_pg_command_pipe(*cmd)
stdout = subprocess.Popen(cmd, env=env, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE).stdout
if stream:
shutil.copyfileobj(stdout, stream)
else:
Expand Down