← Back to team overview

openerp-community team mailing list archive

lp:~openerp-community/openobject-server/qoqenator_base_module_import_fix into lp:openobject-server

 

Boris Timokhin has proposed merging lp:~openerp-community/openobject-server/qoqenator_base_module_import_fix into lp:openobject-server.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #818951 in OpenERP Server: "Import module wizard crashed with not-zip files and not work with correct zip"
  https://bugs.launchpad.net/openobject-server/+bug/818951

For more details, see:
https://code.launchpad.net/~openerp-community/openobject-server/qoqenator_base_module_import_fix/+merge/69929
-- 
https://code.launchpad.net/~openerp-community/openobject-server/qoqenator_base_module_import_fix/+merge/69929
Your team OpenERP Community is subscribed to branch lp:~openerp-community/openobject-server/qoqenator_base_module_import_fix.
=== modified file 'openerp/addons/base/module/wizard/base_module_import.py'
--- openerp/addons/base/module/wizard/base_module_import.py	2010-10-26 09:57:59 +0000
+++ openerp/addons/base/module/wizard/base_module_import.py	2011-07-31 18:28:29 +0000
@@ -28,6 +28,8 @@
 from tools.translate import _
 from osv import osv, fields
 
+ADDONS_PATH = tools.config['addons_path'].split(",")[-1]
+
 class base_module_import(osv.osv_memory):
     """ Import Module """
 
@@ -37,7 +39,8 @@
 
     _columns = {
           'module_file': fields.binary('Module .ZIP file', required=True),
-          'state':fields.selection([('init','init'),('done','done')], 'state', readonly=True),
+          'state':fields.selection([('init','init'),('done','done')],
+                                   'state', readonly=True),
           'module_name': fields.char('Module Name', size=128),
     }
 
@@ -48,26 +51,30 @@
     def importzip(self, cr, uid, ids, context):
         (data,) = self.browse(cr, uid, ids , context=context)
         module_data = data.module_file
-
-        val = base64.decodestring(module_data)
+        zip_data = base64.decodestring(module_data)
         fp = StringIO()
-        fp.write(val)
-        fdata = zipfile.ZipFile(fp, 'r')
-        fname = fdata.namelist()[0]
-        module_name = os.path.split(fname)[0]
-
-        ad = tools.config['addons_path'].split(",")[-1]
-
-        fname = os.path.join(ad, module_name+'.zip')
-        try:
-            fp = file(fname, 'wb')
-            fp.write(val)
-            fp.close()
+        fp.write(zip_data)
+        try:
+            file_data = zipfile.ZipFile(fp, 'r')
+        except zipfile.BadZipfile:
+            raise osv.except_osv(_('Error !'), _('File is not a zip file!'))
+        init_file_name = sorted(file_data.namelist())[0]
+        module_name = os.path.split(init_file_name)[0]
+
+        file_path = os.path.join(ADDONS_PATH, '%s.zip' % module_name)
+        try:
+            zip_file = open(file_path, 'wb')
         except IOError:
-            raise osv.except_osv(_('Error !'), _('Can not create the module file: %s !') % (fname,) )
+            raise osv.except_osv(_('Error !'),
+                                 _('Can not create the module file: %s !') % \
+                                 (file_path,) )
+        zip_file.write(zip_data)
+        zip_file.close()
 
-        self.pool.get('ir.module.module').update_list(cr, uid, {'module_name': module_name,})
-        self.write(cr, uid, ids, {'state':'done', 'module_name': module_name}, context)
+        self.pool.get('ir.module.module').update_list(cr, uid,
+                                                  {'module_name': module_name,})
+        self.write(cr, uid, ids, {'state':'done', 'module_name': module_name},
+                   context)
         return False
 
     def action_module_open(self, cr, uid, ids, context):
@@ -84,4 +91,4 @@
 base_module_import()
 
 
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:


Follow ups