From 2302e4492c84cff84e4e7731deebfe3330a1f194 Mon Sep 17 00:00:00 2001 From: ced <> Date: Sat, 21 Apr 2007 13:32:18 +0000 Subject: [PATCH] KERNEL,BASE: allow to create zip modules bzr revid: ced-4e79fd05ccde4df82f91dece060db6fd1b0e46a3 --- bin/addons/__init__.py | 16 ++++- bin/addons/base/module/module.py | 72 ++++++++++++------- bin/addons/base/module/module_wizard.xml | 8 +-- bin/addons/base/module/wizard/add_new.py | 14 +--- .../module/wizard/wizard_update_module.py | 22 ++++-- bin/report/report_sxw.py | 2 +- bin/tools/misc.py | 34 ++++++++- 7 files changed, 114 insertions(+), 54 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index e1fea8a7bdb..e25b5f081c5 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -39,6 +39,8 @@ import pooler import netsvc from osv import fields +import zipfile + logger = netsvc.Logger() opj = os.path.join @@ -130,8 +132,9 @@ def create_graph(module_list, force=[]): for module in module_list: terp_file = opj(ad, module, '__terp__.py') - if os.path.isfile(terp_file): - info = eval(file(terp_file).read()) + mod_path = opj(ad, module) + if os.path.isfile(terp_file) or zipfile.is_zipfile(mod_path): + info = eval(tools.file_open(terp_file).read()) if info.get('installable', True): packages.append((module, info.get('depends', []), info)) @@ -227,7 +230,14 @@ def register_classes(): m = package.name logger.notifyChannel('init', netsvc.LOG_INFO, 'addon:%s:registering classes' % m) sys.stdout.flush() - imp.load_module(m, *imp.find_module(m)) + try: + # XXX must restrict to only addons paths + imp.load_module(m, *imp.find_module(m)) + except ImportError: + import zipimport + mod_path = opj(ad, m) + zimp = zipimport.zipimporter(mod_path) + zimp.load_module(m) def load_modules(db, force_demo=False, status={}, update_module=False): cr = db.cursor() diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py index 4c1613200f2..c475b1a1bc3 100644 --- a/bin/addons/base/module/module.py +++ b/bin/addons/base/module/module.py @@ -31,6 +31,7 @@ import urllib import os import tools from osv import fields, osv, orm +import zipfile class module_repository(osv.osv): _name = "ir.module.repository" @@ -41,16 +42,6 @@ class module_repository(osv.osv): } module_repository() -def get_module_info(name): - try: - f = file(os.path.join(tools.config['addons_path'], name, '__terp__.py'), 'r') - data = f.read() - info = eval(data) - f.close() - except: - return {} - return info - class module_category(osv.osv): _name = "ir.module.category" _description = "Module Category" @@ -76,11 +67,21 @@ module_category() class module(osv.osv): _name = "ir.module.module" _description = "Module" - + + def get_module_info(self, name): + try: + f = tools.file_open(os.path.join(tools.config['addons_path'], name, '__terp__.py')) + data = f.read() + info = eval(data) + f.close() + except: + return {} + return info + def _get_installed_version(self, cr, uid, ids, field_name=None, arg=None, context={}): res = {} for m in self.browse(cr, uid, ids): - res[m.id] = get_module_info(m.name).get('version', False) + res[m.id] = self.get_module_info(m.name).get('version', False) return res _columns = { @@ -166,7 +167,7 @@ class module(osv.osv): langs = [l[0] for l in cr.fetchall()] modules = self.read(cr, uid, ids, ['name']) for module in modules: - files = get_module_info(module['name']).get('translations', {}) + files = self.get_module_info(module['name']).get('translations', {}) for lang in langs: if files.has_key(lang): filepath = files[lang] @@ -183,18 +184,37 @@ class module(osv.osv): # iterate through installed modules and mark them as being so for name in os.listdir(adp): - if os.path.isdir(os.path.join(adp, name)): - version = get_module_info(name).get('version', False) - if version: - ids = self.search(cr, uid, [('name','=',name)]) - if not ids: - id = self.create(cr, uid, { - 'name': name, - 'latest_version': version, - 'state': 'installed', - }) - else: - self.write(cr, uid, ids, {'state': 'installed'}) + ids = self.search(cr, uid, [('name','=',name)]) + if ids: + terp = self.get_module_info(name) + if terp.get('installable', True) and self.read(cr, uid, ids, ['state'])[0]['state'] == 'uninstallable': + self.write(cr, uid, [ids], {'state': 'uninstalled'}) + continue + terp_file = os.path.join(adp, name, '__terp__.py') + mod_path = os.path.join(adp, name) + if os.path.isdir(mod_path) or zipfile.is_zipfile(mod_path): + terp = self.get_module_info(name) + if not terp or not terp.get('installable', True): + continue + try: + import imp + # XXX must restrict to only addons paths + imp.load_module(name, *imp.find_module(name)) + except ImportError: + import zipimport + mod_path = os.path.join(adp, name) + zimp = zipimport.zipimporter(mod_path) + zimp.load_module(name) + version = terp.get('version', False) + id = self.create(cr, uid, { + 'name': name, + 'state': 'uninstalled', + 'description': terp.get('description', ''), + 'shortdesc': terp.get('name', ''), + 'author': terp.get('author', 'Unknown') + }) + for d in terp.get('depends', []): + cr.execute('INSERT INTO ir_module_module_dependency (module_id, name) values (%s, %s)', (id, d)) # make the list of all installable modules for repository in robj.browse(cr, uid, robj.search(cr, uid, [])): @@ -233,7 +253,7 @@ class module(osv.osv): if tarinfo.name.endswith('__terp__.py'): info = eval(tar.extractfile(tarinfo).read()) elif os.path.isdir(os.path.join(adp, module.name)): - info = get_module_info(module.name) + info = self.get_module_info(module.name) if info: categ = info.get('category', 'Unclassified') parent = False diff --git a/bin/addons/base/module/module_wizard.xml b/bin/addons/base/module/module_wizard.xml index 4c6182a2055..a3cab0f794e 100644 --- a/bin/addons/base/module/module_wizard.xml +++ b/bin/addons/base/module/module_wizard.xml @@ -7,19 +7,17 @@ model="ir.module.module" name="module.info_get"/> - Apply marked changes @@ -41,7 +39,7 @@ id="menu_wizard_lang_install" type="wizard"/> - + Export a language diff --git a/bin/addons/base/module/wizard/add_new.py b/bin/addons/base/module/wizard/add_new.py index 346da18bb11..c86b0812553 100644 --- a/bin/addons/base/module/wizard/add_new.py +++ b/bin/addons/base/module/wizard/add_new.py @@ -46,16 +46,6 @@ _info_arch = ''' ''' _info_fields = {} -def get_module_info(name): - try: - f = file(os.path.join(tools.config['addons_path'], name, '__terp__.py'), 'r') - data = f.read() - info = eval(data) - f.close() - except: - return {} - return info - class wizard_install_module(wizard.interface): def watch_dir(self, cr, uid, data, context): mod_obj = pooler.get_pool(cr.dbname).get('ir.module.module') @@ -66,7 +56,7 @@ class wizard_install_module(wizard.interface): for module in modules: if module in known_modules: continue - terp = get_module_info(module) + terp = mod_obj.get_module_info(module) if not terp.get('installable', True): continue imp.load_module(module, *imp.find_module(module)) @@ -80,7 +70,7 @@ class wizard_install_module(wizard.interface): for d in dependencies: cr.execute('insert into ir_module_module_dependency (module_id,name) values (%s, %s)', (mod_id, d)) for module in known_modules: - terp = get_module_info(module) + terp = mod_obj.get_module_info(module) if terp.get('installable', True): for mod in all_mods: if mod['name'] == module and mod['state'] == 'uninstallable': diff --git a/bin/addons/base/module/wizard/wizard_update_module.py b/bin/addons/base/module/wizard/wizard_update_module.py index 5a2ec58912b..996815584a1 100644 --- a/bin/addons/base/module/wizard/wizard_update_module.py +++ b/bin/addons/base/module/wizard/wizard_update_module.py @@ -29,26 +29,38 @@ import wizard import netsvc +import pooler class wizard_update_module(wizard.interface): + + arch = ''' +
+