Browse Source

[FIX] review remarks

pull/614/head
archetipo 9 years ago
committed by Dave Lasley
parent
commit
37bf876a6d
  1. 28
      auto_backup/i18n/it.po
  2. 40
      auto_backup/model/backup_scheduler.py

28
auto_backup/i18n/it.po

@ -15,34 +15,6 @@ msgstr ""
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: auto_backup
#: model:email.template,body_html:auto_backup.email_template_autobackup_error_noificaiton
msgid "\n"
" \n"
" <p>Dear,</p>\n"
"\n"
" <p>The backup for the server ${object.host} (IP: ${object.sftpip}) failed.</p>\n"
" <p>Please check the following details:</p>\n"
" <p>IP address SFTP server: ${object.sftpip}</p>\n"
" <p>Username: ${object.sftpusername}</p>\n"
" <p>Password: ${object.sftppassword}</p>\n"
" <p>Error details: ${object.lasterrorlog}</p>\n"
" <p>With kind regards</p>\n"
"\n"
" "
msgstr "\n"
" \n"
" <p>Buongiorno,</p>\n"
"\n"
" <p>Il backup del DB del server ${object.host} (IP: ${object.sftpip}) e' fallito.</p>\n"
" <p>Si prega di controllare le seguenti impostazioni:</p>\n"
" <p>Indirizzo IP server SFTP: ${object.sftpip}</p>\n"
" <p>Username: ${object.sftpusername}</p>\n"
" <p>Password: ${object.sftppassword}</p>\n"
" <p>Dettaglio errore: ${object.lasterrorlog}</p>\n"
" <p>Cordiali Saluti</p>\n"
"\n"
" "
#. module: auto_backup
#: code:addons/auto_backup/model/backup_scheduler.py:204

40
auto_backup/model/backup_scheduler.py

@ -28,11 +28,8 @@ import re
try:
import pysftp
except ImportError:
raise ImportError(
'This module needs pysftp to automaticly write backups to the FTP '
'through SFTP.Please install pysftp on your system.'
'(sudo pip install pysftp)'
)
pass
from openerp import models, fields, api, _
from openerp.exceptions import except_orm, Warning
from openerp import tools
@ -182,7 +179,7 @@ class db_backup(models.Model):
_constraints = [
(
_check_db_exist,
_('Error ! No such database exists!'), ['name']
_('Error ,No such database exists'), ['name']
)
]
@ -196,6 +193,7 @@ class db_backup(models.Model):
# db_list = self.get_db_list(cr, uid, [], rec.host, rec.port)
try:
# pathToWriteTo = rec.sftppath
conn_success = True
ipHost = rec.sftpip
portHost = rec.sftpport
usernameLogin = rec.sftpusername
@ -210,12 +208,13 @@ class db_backup(models.Model):
messageContent = _(
"Everything seems properly set up for FTP back-ups!")
except Exception as e:
conn_success = False
messageTitle = _("Connection Test Failed!")
if len(rec.sftpip) < 8:
messageContent += _(
"\nYour IP address seems to be too short.\n")
messageContent += "Here is what we got instead:\n"
if "Failed" in messageTitle:
messageContent += _("Here is what we got instead:\n")
if not conn_success:
raise except_orm(
_(messageTitle), _(
messageContent + "%s") %
@ -247,7 +246,7 @@ class db_backup(models.Model):
bkp = execute(
conn, 'dump', tools.config['admin_passwd'], rec.name)
except:
_logger.notifyChannel(
_logger.info(
'backup', netsvc.LOG_INFO,
_(
"Couldn't backup database %s. "
@ -260,7 +259,7 @@ class db_backup(models.Model):
fp.write(bkp)
fp.close()
else:
_logger.notifyChannel(
_logger.info(
'backup', netsvc.LOG_INFO,
"database %s doesn't exist on http://%s:%s" %
(rec.name, rec.host, rec.port))
@ -284,7 +283,7 @@ class db_backup(models.Model):
# Move to the correct directory on external server. If the
# user made a typo in his path with multiple slashes
# (/odoo//backups/) it will be fixed by this regex.
pathToWriteTo = re.sub('([/]{2,5})+', '/', pathToWriteTo)
pathToWriteTo = re.sub('/+', '/', pathToWriteTo)
try:
srv.chdir(pathToWriteTo)
except IOError:
@ -342,13 +341,22 @@ class db_backup(models.Model):
srv.close()
except Exception as e:
_logger.debug(
'Exception! We couldn\'t back '
'Exception We couldn\'t back '
'up to the FTP server..'
)
# At this point the SFTP backup failed.
# We will now check if the user wants
# an e-mail notification about this.
if rec.sendmailsftpfail:
self.send_notification(rec, e)
# Remove all old files (on local server) in case this is configured..
if rec.autoremove is True:
self.remove_folder(rec)
return True
def send_notification(self, rec, e):
try:
ir_mail_server = self.env['ir.mail_server']
message = (
@ -373,10 +381,10 @@ class db_backup(models.Model):
except Exception as e:
_logger.debug(
'Exception! %s' % tools.ustr(e)
'Exception %s' % tools.ustr(e)
)
# Remove all old files (on local server) in case this is configured..
# This is done after the SFTP writing to prevent unusual behaviour:
# If the user would set local back-ups to be kept 0 days and the SFTP
# to keep backups xx days there wouldn't be any new back-ups added
@ -387,8 +395,7 @@ class db_backup(models.Model):
# (NAS for example) there wouldn't be any writing to the
# remote server if this if statement was before the SFTP write method
# right above this comment.
if rec.autoremove is True:
def remove_folder(self, rec):
dir = rec.bkp_dir
# Loop over all files in the directory.
for f in os.listdir(dir):
@ -402,4 +409,3 @@ class db_backup(models.Model):
delta = now - createtime
if delta.days >= rec.daystokeep:
os.remove(fullpath)
return True
Loading…
Cancel
Save