2009-10-20 10:52:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-05-03 18:34:39 +00:00
|
|
|
##############################################################################
|
2009-10-14 12:32:15 +00:00
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2008-06-16 11:00:21 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 12:32:15 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2007-05-03 18:34:39 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 12:32:15 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2007-05-03 18:34:39 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-05-03 18:34:39 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
|
2007-05-02 08:39:16 +00:00
|
|
|
import wizard
|
|
|
|
import osv
|
|
|
|
import pooler
|
|
|
|
import os
|
2007-05-03 18:34:39 +00:00
|
|
|
import tools
|
2007-05-02 08:39:16 +00:00
|
|
|
|
2007-05-03 19:21:49 +00:00
|
|
|
import zipfile
|
2009-01-09 12:18:20 +00:00
|
|
|
from StringIO import StringIO
|
2007-05-03 18:34:39 +00:00
|
|
|
import base64
|
2009-03-06 18:06:50 +00:00
|
|
|
from tools.translate import _
|
2007-05-02 08:39:16 +00:00
|
|
|
|
|
|
|
finish_form ='''<?xml version="1.0"?>
|
2007-05-03 19:21:49 +00:00
|
|
|
<form string="Module import">
|
2008-07-22 14:24:36 +00:00
|
|
|
<label string="Module successfully imported !" colspan="4"/>
|
2007-05-03 19:21:49 +00:00
|
|
|
</form>
|
|
|
|
'''
|
|
|
|
|
|
|
|
ask_form ='''<?xml version="1.0"?>
|
|
|
|
<form string="Module import">
|
2009-01-26 17:40:29 +00:00
|
|
|
<separator string="Module Import" colspan="4"/>
|
2008-07-22 14:24:36 +00:00
|
|
|
<label string="Please give your module .ZIP file to import." colspan="4"/>
|
|
|
|
<field name="module_file"/>
|
2007-05-02 08:39:16 +00:00
|
|
|
</form>
|
|
|
|
'''
|
|
|
|
|
2007-05-03 19:21:49 +00:00
|
|
|
ask_fields = {
|
2008-07-22 14:24:36 +00:00
|
|
|
'module_file': {'string': 'Module .ZIP file', 'type': 'binary', 'required': True},
|
2007-05-03 18:34:39 +00:00
|
|
|
}
|
2007-05-03 08:01:49 +00:00
|
|
|
|
2007-05-03 18:34:39 +00:00
|
|
|
class move_module_wizard(wizard.interface):
|
2008-07-22 14:24:36 +00:00
|
|
|
def importzip(self, cr, uid, data, context):
|
|
|
|
module_obj=pooler.get_pool(cr.dbname).get('ir.module.module')
|
|
|
|
module_data = data['form']['module_file']
|
2007-05-03 19:21:49 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
val =base64.decodestring(module_data)
|
2009-01-09 12:18:20 +00:00
|
|
|
fp = StringIO()
|
|
|
|
fp.write(val)
|
2008-07-22 14:24:36 +00:00
|
|
|
fdata = zipfile.ZipFile(fp, 'r')
|
|
|
|
fname = fdata.namelist()[0]
|
|
|
|
module_name = os.path.split(fname)[0]
|
2007-05-03 08:04:00 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
ad = tools.config['addons_path']
|
2007-05-03 19:21:49 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
fname = os.path.join(ad,module_name+'.zip')
|
|
|
|
try:
|
|
|
|
fp = file(fname, 'wb')
|
|
|
|
fp.write(val)
|
|
|
|
fp.close()
|
|
|
|
except IOError, e:
|
|
|
|
raise wizard.except_wizard(_('Error !'), _('Can not create the module file: %s !') % (fname,) )
|
2007-05-03 19:21:49 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
pooler.get_pool(cr.dbname).get('ir.module.module').update_list(cr, uid)
|
|
|
|
return {'module_name': module_name}
|
2007-07-30 13:35:27 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
def _action_module_open(self, cr, uid, data, context):
|
|
|
|
return {
|
|
|
|
'domain': str([('name', '=', data['form']['module_name'])]),
|
|
|
|
'name': 'Module List',
|
|
|
|
'view_type': 'form',
|
|
|
|
'view_mode': 'tree,form',
|
|
|
|
'res_model': 'ir.module.module',
|
|
|
|
'view_id': False,
|
|
|
|
'type': 'ir.actions.act_window'
|
|
|
|
}
|
2007-05-02 08:39:16 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
states = {
|
|
|
|
'init': {
|
|
|
|
'actions': [],
|
|
|
|
'result': {
|
|
|
|
'type': 'form',
|
|
|
|
'arch': ask_form,
|
|
|
|
'fields': ask_fields,
|
|
|
|
'state': [
|
|
|
|
('end', 'Cancel', 'gtk-cancel'),
|
|
|
|
('import', 'Import module', 'gtk-ok', True)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'import': {
|
|
|
|
'actions': [importzip],
|
|
|
|
'result': {
|
|
|
|
'type':'form',
|
|
|
|
'arch':finish_form,
|
|
|
|
'fields':{},
|
|
|
|
'state':[('open_window','Close')]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'open_window': {
|
|
|
|
'actions': [],
|
|
|
|
'result': {'type': 'action', 'action': _action_module_open, 'state':'end'}
|
|
|
|
},
|
|
|
|
}
|
2007-05-03 19:21:49 +00:00
|
|
|
move_module_wizard('base.module.import')
|
2008-07-23 15:01:27 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|