diff options
| author | Fabien Pinckaers <fp@tinyerp.com> | 2007-05-03 19:21:49 +0000 |
|---|---|---|
| committer | Fabien Pinckaers <fp@tinyerp.com> | 2007-05-03 19:21:49 +0000 |
| commit | 175cd4cdd6d396ef5d14119e1186823ed5f93cde (patch) | |
| tree | fa26e302c226be6487670215109058df14bebb09 /bin/addons/base/module/wizard/wizard_module_import.py | |
| parent | b46cf7ec1929e7c355c2b7e89b15e9c134d2c5d5 (diff) | |
.ZIP Module support:
improvement for supporting .zip extension
wizard for importing .ZIP
wizard for exportting .ZIP: bugfix and improve
bzr revid: fp@tinyerp.com-a9ffc9ab126a9ae33dc02e212ed6762853d908ed
Diffstat (limited to 'bin/addons/base/module/wizard/wizard_module_import.py')
| -rw-r--r-- | bin/addons/base/module/wizard/wizard_module_import.py | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/bin/addons/base/module/wizard/wizard_module_import.py b/bin/addons/base/module/wizard/wizard_module_import.py new file mode 100644 index 00000000000..0731de4030c --- /dev/null +++ b/bin/addons/base/module/wizard/wizard_module_import.py @@ -0,0 +1,103 @@ +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# 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 +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + + +import wizard +import osv +import pooler +import os +import tools + +import zipfile +import StringIO +import base64 + +finish_form ='''<?xml version="1.0"?> +<form string="Module import"> + <label string="Module successfully imported !" colspan="4"/> +</form> +''' + +ask_form ='''<?xml version="1.0"?> +<form string="Module import"> + <separator string="Module import" colspan="4"/> + <label string="Please give your module .ZIP file to import." colspan="4"/> + <field name="module_file"/> +</form> +''' + +ask_fields = { + 'module_file': {'string': 'Module .ZIP file', 'type':'binary'}, +} + +class move_module_wizard(wizard.interface): + def importzip(self, cr, uid, data, context): + module_obj=pooler.get_pool(cr.dbname).get('ir.module.module') + module_data = data['form']['module_file'] + + val =base64.decodestring(module_data) + fp = StringIO.StringIO(val) + fdata = zipfile.ZipFile(fp, 'r') + fname = fdata.namelist()[0] + module_name = os.path.split(fname)[0] + + ad = tools.config['addons_path'] + + if os.path.isdir(os.path.join(ad,module_name)) or os.path.isfile(os.path.join(ad,module_name+'.zip')): + raise wizard.except_wizard('Error !', 'This module already exist in your system !') + + 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:\n'+' '+fname+'!') + + return {} + + states = { + 'init': { + 'actions': [], + 'result': { + 'type':'form', + 'arch':ask_form, + 'fields':ask_fields, + 'state':[('end','Cancel'),('import','Import module')] + } + }, + 'import': { + 'actions': [importzip], + 'result': { + 'type':'form', + 'arch':finish_form, + 'fields':{}, + 'state':[('end','Close')] + } + } + } +move_module_wizard('base.module.import') |
