.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
This commit is contained in:
parent
b46cf7ec19
commit
175cd4cdd6
|
@ -131,9 +131,11 @@ def create_graph(module_list, force=[]):
|
|||
packages = []
|
||||
|
||||
for module in module_list:
|
||||
if module[-4:]=='.zip':
|
||||
module = module[:-4]
|
||||
terp_file = opj(ad, module, '__terp__.py')
|
||||
mod_path = opj(ad, module)
|
||||
if os.path.isfile(terp_file) or zipfile.is_zipfile(mod_path):
|
||||
if os.path.isfile(terp_file) or zipfile.is_zipfile(mod_path+'.zip'):
|
||||
info = eval(tools.file_open(terp_file).read())
|
||||
if info.get('installable', True):
|
||||
packages.append((module, info.get('depends', []), info))
|
||||
|
@ -191,6 +193,7 @@ def load_module_graph(cr, graph, status={}):
|
|||
for filename in package.datas.get('%s_xml' % kind, []):
|
||||
mode = 'update'
|
||||
if hasattr(package, 'init') or package_state=='to install':
|
||||
print 'Mode', mode, filename
|
||||
mode = 'init'
|
||||
logger.notifyChannel('init', netsvc.LOG_INFO, 'addon:%s:loading %s' % (m, filename))
|
||||
name, ext = os.path.splitext(filename)
|
||||
|
@ -235,7 +238,7 @@ def register_classes():
|
|||
imp.load_module(m, *imp.find_module(m))
|
||||
except ImportError:
|
||||
import zipimport
|
||||
mod_path = opj(ad, m)
|
||||
mod_path = opj(ad, m+'.zip')
|
||||
zimp = zipimport.zipimporter(mod_path)
|
||||
zimp.load_module(m)
|
||||
|
||||
|
|
|
@ -9,15 +9,21 @@
|
|||
name="module.info_get"/>
|
||||
-->
|
||||
<wizard
|
||||
string="Module Transfer Wizard"
|
||||
string="Export module"
|
||||
model="ir.module.module"
|
||||
name="tmp.wizard"
|
||||
id="move_module_wizard"/>
|
||||
name="base.module.export"
|
||||
id="wizard_base_module_export"/>
|
||||
|
||||
<wizard
|
||||
string="Import module"
|
||||
model="ir.module.module"
|
||||
name="base.module.import"
|
||||
id="wizard_base_module_import"/>
|
||||
<menuitem
|
||||
name="Administration/Modules Management/Transfer Module"
|
||||
action="move_module_wizard"
|
||||
name="Administration/Modules Management/Import a new module"
|
||||
action="wizard_base_module_import"
|
||||
type="wizard"
|
||||
id="menu_wizard_move_module"/>
|
||||
id="menu_wizard_module_import"/>
|
||||
|
||||
<record model="ir.actions.wizard" id="wizard_update">
|
||||
<field name="name">Download module list</field>
|
||||
|
|
|
@ -33,4 +33,5 @@ import wizard_module_lang_install
|
|||
import add_new
|
||||
import wizard_export_lang
|
||||
import wizard_import_lang
|
||||
import move_module_wizard
|
||||
import wizard_module_export
|
||||
import wizard_module_import
|
||||
|
|
|
@ -95,4 +95,4 @@ class move_module_wizard(wizard.interface):
|
|||
}
|
||||
}
|
||||
}
|
||||
move_module_wizard('tmp.wizard')
|
||||
move_module_wizard('base.module.export')
|
|
@ -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')
|
|
@ -67,6 +67,7 @@ def init_db(cr):
|
|||
elif zipfile.is_zipfile(mod_path):
|
||||
zfile = zipfile.ZipFile(mod_path)
|
||||
i = os.path.splitext(i)[0]
|
||||
print i
|
||||
info = eval(zfile.read(opj(i, '__terp__.py')))
|
||||
if info:
|
||||
categs = info.get('category', 'Uncategorized').split('/')
|
||||
|
@ -179,11 +180,11 @@ def file_open(name, mode="r", subdir='addons'):
|
|||
name = os.path.join(tail, name)
|
||||
else:
|
||||
name = tail
|
||||
if zipfile.is_zipfile(head):
|
||||
if zipfile.is_zipfile(head+'.zip'):
|
||||
import StringIO
|
||||
zfile = zipfile.ZipFile(head)
|
||||
zfile = zipfile.ZipFile(head+'.zip')
|
||||
return StringIO.StringIO(zfile.read(os.path.join(os.path.basename(head), name)))
|
||||
raise IOError, 'File not found : '+str(name)
|
||||
raise IOError, 'File not found : '+str(name)
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue