~therp-nl/therp-addons/6.1-web_mode_visibility_separator_use_override

« back to all changes in this revision

Viewing changes to trp_encrypted_backup_rsync/trp_encrypted_backup_rsync.py

  • Committer: Holger Brunn
  • Date: 2012-10-12 07:41:44 UTC
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: hbrunn@therp.nl-20121012074144-zjtl80aeu5hseyqm
[IMP] renamed modules to better reflect their purpose
[IMP] only restart rsync transfer if the error code indicates a connection
issue
[FIX] fixed copyright notices

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    This module copyright (C) 2011-2012 Therp BV (<http://therp.nl>)
 
6
#    All Rights Reserved
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
from openerp.osv.orm import TransientModel,except_orm
 
23
import subprocess
 
24
from openerp.tools.translate import _
 
25
 
 
26
class trp_backup_wizard(TransientModel):
 
27
    _inherit='trp_backup.wizard'
 
28
 
 
29
    def do_backup(self, cr, uid):
 
30
        success, messages, backup_file=super(trp_backup_wizard, self).do_backup(cr, 
 
31
                uid)
 
32
 
 
33
        if success:
 
34
            messages+='\n'
 
35
            params=self.pool.get('ir.config_parameter')
 
36
            rsync_host=self.pool.get('ir.config_parameter').get_param(cr, uid, 
 
37
                    'trp_backup_rsync.host')
 
38
            
 
39
            self._logger.info(_('copying %s to %s')%(backup_file,rsync_host))
 
40
            
 
41
            run_transfer=True
 
42
            while run_transfer:
 
43
                rsync_process=subprocess.Popen(['rsync', 
 
44
                    '--partial',
 
45
                    backup_file,
 
46
                    rsync_host], 
 
47
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
48
                
 
49
                output=rsync_process.communicate()
 
50
                
 
51
                if rsync_process.returncode==0:
 
52
                    messages+=_('Sucessfully copied %s to %s')%(backup_file,
 
53
                            rsync_host)
 
54
                    messages+=(output[0]+'\n') if output[0] else ''
 
55
                    messages+=(output[1]+'\n') if output[1] else ''
 
56
                    run_transfer=False
 
57
                else:
 
58
                    messages+=_('There was an error during transfer:')+'\n'
 
59
                    messages+=(output[0]+'\n') if output[0] else ''
 
60
                    messages+=(output[1]+'\n') if output[1] else ''
 
61
                    if rsync_process.returncode not in [23,30,35]:
 
62
                        run_transfer=False
 
63
                    
 
64
                self._logger.info(messages)
 
65
        else:
 
66
            self._logger(_('Backup failed, not running transfer'))
 
67
 
 
68
        return success, messages, backup_file