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

Proposed by Boris Timokhin
Status: Merged
Merged at revision: 3625
Proposed branch: lp:~openerp-community/openobject-server/qoqenator_base_module_import_fix
Merge into: lp:openobject-server
Diff against target: 77 lines (+26/-19)
1 file modified
openerp/addons/base/module/wizard/base_module_import.py (+26/-19)
To merge this branch: bzr merge lp:~openerp-community/openobject-server/qoqenator_base_module_import_fix
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Approve
Naresh(OpenERP) (community) Approve
Review via email: mp+69929@code.launchpad.net
To post a comment you must log in.
Revision history for this message
VO (ovailly) wrote :

Bonjour,

je suis en congés jusqu'au mardi 16 août 2011.

Pour une urgence veuillez adresser votre demande sur les deux
boites Email suivantes :

<email address hidden>
<email address hidden>

Merci

Olivier vailly

Revision history for this message
Naresh(OpenERP) (nch-openerp) :
review: Approve
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hello Boris,

Your patch looks good, I'm merging it in trunk now.

Thanks for helping to improve OpenERP!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/module/wizard/base_module_import.py'
2--- openerp/addons/base/module/wizard/base_module_import.py 2010-10-26 09:57:59 +0000
3+++ openerp/addons/base/module/wizard/base_module_import.py 2011-07-31 18:28:29 +0000
4@@ -28,6 +28,8 @@
5 from tools.translate import _
6 from osv import osv, fields
7
8+ADDONS_PATH = tools.config['addons_path'].split(",")[-1]
9+
10 class base_module_import(osv.osv_memory):
11 """ Import Module """
12
13@@ -37,7 +39,8 @@
14
15 _columns = {
16 'module_file': fields.binary('Module .ZIP file', required=True),
17- 'state':fields.selection([('init','init'),('done','done')], 'state', readonly=True),
18+ 'state':fields.selection([('init','init'),('done','done')],
19+ 'state', readonly=True),
20 'module_name': fields.char('Module Name', size=128),
21 }
22
23@@ -48,26 +51,30 @@
24 def importzip(self, cr, uid, ids, context):
25 (data,) = self.browse(cr, uid, ids , context=context)
26 module_data = data.module_file
27-
28- val = base64.decodestring(module_data)
29+ zip_data = base64.decodestring(module_data)
30 fp = StringIO()
31- fp.write(val)
32- fdata = zipfile.ZipFile(fp, 'r')
33- fname = fdata.namelist()[0]
34- module_name = os.path.split(fname)[0]
35-
36- ad = tools.config['addons_path'].split(",")[-1]
37-
38- fname = os.path.join(ad, module_name+'.zip')
39- try:
40- fp = file(fname, 'wb')
41- fp.write(val)
42- fp.close()
43+ fp.write(zip_data)
44+ try:
45+ file_data = zipfile.ZipFile(fp, 'r')
46+ except zipfile.BadZipfile:
47+ raise osv.except_osv(_('Error !'), _('File is not a zip file!'))
48+ init_file_name = sorted(file_data.namelist())[0]
49+ module_name = os.path.split(init_file_name)[0]
50+
51+ file_path = os.path.join(ADDONS_PATH, '%s.zip' % module_name)
52+ try:
53+ zip_file = open(file_path, 'wb')
54 except IOError:
55- raise osv.except_osv(_('Error !'), _('Can not create the module file: %s !') % (fname,) )
56+ raise osv.except_osv(_('Error !'),
57+ _('Can not create the module file: %s !') % \
58+ (file_path,) )
59+ zip_file.write(zip_data)
60+ zip_file.close()
61
62- self.pool.get('ir.module.module').update_list(cr, uid, {'module_name': module_name,})
63- self.write(cr, uid, ids, {'state':'done', 'module_name': module_name}, context)
64+ self.pool.get('ir.module.module').update_list(cr, uid,
65+ {'module_name': module_name,})
66+ self.write(cr, uid, ids, {'state':'done', 'module_name': module_name},
67+ context)
68 return False
69
70 def action_module_open(self, cr, uid, ids, context):
71@@ -84,4 +91,4 @@
72 base_module_import()
73
74
75-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
76\ No newline at end of file
77+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: