1
# -*- encoding: utf-8 -*-
2
###########################################################################
3
# Module Writen to OpenERP, Open Source Management Solution
5
# Copyright (c) 2010 Vauxoo - http://www.vauxoo.com/
7
# info Vauxoo (info@vauxoo.com)
8
############################################################################
9
# Coded by: Luis Torres (luis_t@vauxoo.com)
10
# Julio (julio@vauxoo.com)
11
############################################################################
13
# This program is free software: you can redistribute it and/or modify
14
# it under the terms of the GNU Affero General Public License as
15
# published by the Free Software Foundation, either version 3 of the
16
# License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU Affero General Public License for more details.
23
# You should have received a copy of the GNU Affero General Public License
24
# along with this program. If not, see <http://www.gnu.org/licenses/>.
26
##############################################################################
27
from openerp.osv import osv, fields
34
from openerp.tools.translate import _
44
class db_tools(osv.TransientModel):
47
def db(self, cr, uid, context=None):
48
ws_obj = service.web_services.db()
49
db_list = ws_obj.exp_list()
52
list_db.append((db.lower(), db))
55
def _db_default(self, cr, uid, context=None):
56
res = self.db(cr, uid, context)
59
if ((cr.dbname, cr.dbname) == db):
63
def db_default(self, cr, uid, context=None):
64
return self._db_default(cr, uid, context)[0][0]
67
'filter': fields.selection([
69
('restore', 'Backup-Restore')], 'Filter',
70
help='Backup creates a backup of the database and stored\
71
in the path indicated, Restore-Backup creates a backup\
72
of the database, and in turn restores the new name'),
73
'password': fields.char('Password', size=64, required=True),
74
'list_db': fields.selection(_db_default, 'Data Base Restore',
75
required=True, readonly=True),
76
'name_db': fields.char('Name DB', size=128, required=True),
77
'path_save_db': fields.char('Path save DB', size=256, required=True)
82
'list_db': db_default,
83
'name_db': lambda self, cr, uid, context=None: cr.dbname +
84
time.strftime('_%Y%m%d_%H%M%S.backup'),
85
'path_save_db': tempfile.gettempdir()
88
def backup_db(self, cr, uid, ids, uri=False, dbname=''):
89
ws_obj = service.web_services.db()
90
data = self.browse(cr, uid, ids[0])
91
filename = os.path.join(data.path_save_db, data.name_db)
92
dump_db64 = ws_obj.exp_dump(dbname)
93
dump = base64.decodestring(dump_db64)
94
file_db = file(filename, 'wb')
99
def backup_restore_db(self, cr, uid, ids, uri, dbname=''):
100
res = self.backup_db(cr, uid, ids, uri, dbname)
101
data = self.browse(cr, uid, ids[0])
102
data_base = os.path.basename(res)
103
name_db = data_base[:data_base.rfind(".")]
104
print 'name_db', name_db
106
data_b64 = base64.encodestring(f.read())
108
password = data.password
109
ws_obj = service.web_services.db()
110
ws_obj.exp_restore(name_db, data_b64)
113
def find_db(self, cr, uid, ids, context=None):
116
def confirm_action(self, cr, uid, ids, context=None):
117
uri = context.get('uri', False)
118
for lin in self.browse(cr, uid, ids, context=context):
119
if lin.filter == 'backup':
120
self.backup_db(cr, uid, ids, context.get(
121
'uri', False), lin.list_db)
122
if lin.filter == 'restore':
123
self.backup_restore_db(cr, uid, ids, context.get(
124
'uri', False), lin.list_db)
127
def cancel_action(self, cr, uid, ids, context=None):