Browse Source

[FIX] review remarks

pull/620/head
archetipo 9 years ago
committed by Dave Lasley
parent
commit
622811dddc
  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" "Content-Transfer-Encoding: \n"
"Plural-Forms: \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 #. module: auto_backup
#: code:addons/auto_backup/model/backup_scheduler.py:204 #: code:addons/auto_backup/model/backup_scheduler.py:204

40
auto_backup/model/backup_scheduler.py

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