From addc090e18f80b9556c053b4019a8b7b5e5cc8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 26 Feb 2008 18:40:24 +0100 Subject: [PATCH] Remove module repository --- trytond/ir/__tryton__.py | 1 - trytond/ir/module/__init__.py | 1 - trytond/ir/module/module.py | 140 ++----------------------------- trytond/ir/module/module.xml | 22 ++--- trytond/ir/module/repository.py | 31 ------- trytond/ir/module/repository.xml | 59 ------------- trytond/res/ir.xml | 15 ---- 7 files changed, 17 insertions(+), 252 deletions(-) delete mode 100644 trytond/ir/module/repository.py delete mode 100644 trytond/ir/module/repository.xml diff --git a/trytond/ir/__tryton__.py b/trytond/ir/__tryton__.py index 9e61fef8dc..777b35fc6b 100644 --- a/trytond/ir/__tryton__.py +++ b/trytond/ir/__tryton__.py @@ -17,7 +17,6 @@ 'rule.xml', 'property.xml', 'module/module.xml', - 'module/repository.xml', 'module/category.xml', 'default.xml', ], diff --git a/trytond/ir/module/__init__.py b/trytond/ir/module/__init__.py index e8d8328283..16aaf5efd8 100644 --- a/trytond/ir/module/__init__.py +++ b/trytond/ir/module/__init__.py @@ -1,3 +1,2 @@ from category import * -from repository import * from module import * diff --git a/trytond/ir/module/module.py b/trytond/ir/module/module.py index dd319a20f1..c14b7c13d8 100644 --- a/trytond/ir/module/module.py +++ b/trytond/ir/module/module.py @@ -133,9 +133,7 @@ class Module(OSV): description = fields.Text("Description", readonly=True) author = fields.Char("Author", size=128, readonly=True) website = fields.Char("Website", size=256, readonly=True) - installed_version = fields.Function('get_installed_version', - string='Installed version', type='char') - latest_version = fields.Char('Latest version', size=64, readonly=True) + version = fields.Function('get_version', string='Version', type='char') url = fields.Char('URL', size=128) dependencies = fields.One2Many('ir.module.module.dependency', 'module', 'Dependencies', readonly=True) @@ -188,15 +186,12 @@ class Module(OSV): return {} return info - def get_installed_version(self, cursor, user, ids, name, arg, + def get_version(self, cursor, user, ids, name, arg, context=None): res = {} for module in self.browse(cursor, user, ids, context=context): - if module.state in ('installed', 'to upgrade', 'to remove'): - res[module.id] = Module.get_module_info( - module.name).get('version', '') - else: - res[module.id] = '' + res[module.id] = Module.get_module_info( + module.name).get('version', '') return res def unlink(self, cursor, user, ids, context=None): @@ -326,8 +321,7 @@ class Module(OSV): # update the list of available packages def update_list(self, cursor, user, context=None): - robj = self.pool.get('ir.module.repository') - res = [0, 0] # [update, add] + res = 0 # iterate through installed modules and mark them as being so for name in os.listdir(MODULES_PATH): @@ -344,13 +338,6 @@ class Module(OSV): and mod.state == 'uninstallable': self.write(cursor, user, module_id, { 'state': 'uninstalled'}, context=context) - if vercmp(tryton.get('version', ''), - mod.latest_version or '0') > 0: - self.write(cursor, user, module_id, { - 'latest_version': tryton.get('version'), - 'url': '', - }, context=context) - res[0] += 1 self.write(cursor, user, module_id, { 'description': tryton.get('description', ''), 'shortdesc': tryton.get('name', ''), @@ -370,16 +357,6 @@ class Module(OSV): tryton = Module.get_module_info(mod_name) if not tryton or not tryton.get('installable', True): continue - if not os.path.isfile( - os.path.join(MODULES_PATH, mod_name+'.zip')): - import imp - # XXX must restrict to only modules paths - imp.load_module(name, *imp.find_module(mod_name)) - else: - import zipimport - mod_path = os.path.join(MODULES_PATH, mod_name+'.zip') - zimp = zipimport.zipimporter(mod_path) - zimp.load_module(mod_name) new_id = self.create(cursor, user, { 'name': mod_name, 'state': 'uninstalled', @@ -387,102 +364,13 @@ class Module(OSV): 'shortdesc': tryton.get('name', ''), 'author': tryton.get('author', 'Unknown'), 'website': tryton.get('website', ''), - 'latest_version': tryton.get('version', ''), 'license': tryton.get('license', 'GPL-2'), }) - res[1] += 1 + res += 1 self._update_dependencies(cursor, user, new_id, tryton.get('depends', [])) self._update_category(cursor, user, new_id, tryton.get('category', 'None')) - - import socket - socket.setdefaulttimeout(10) - for repository in robj.browse(cursor, user, - robj.search(cursor, user, []), context=context): - try: - index_page = urllib.urlopen(repository.url).read() - except IOError, exception: - if exception.errno == 21: - raise ExceptORM('Error', - 'This url \'%s\' must provide an html file ' - 'with links to zip modules' % (repository.url)) - else: - raise - modules = re.findall(repository.filter, index_page, re.I+re.M) - mod_sort = {} - for module in modules: - name = module[0] - version = module[1] - extension = module[-1] - if name in mod_sort: - if vercmp(version, mod_sort[name][0]) <= 0: - continue - mod_sort[name] = [version, extension] - for name in mod_sort.keys(): - version, extension = mod_sort[name] - url = repository.url+'/'+name+'-'+version+extension - ids = self.search(cursor, user, [('name', '=', name)], - context=context) - if not ids: - self.create(cursor, user, { - 'name': name, - 'latest_version': version, - 'url': url, - 'state': 'uninstalled', - }, context=context) - res[1] += 1 - else: - mod_id = ids[0] - latest_version = self.browse(cursor, user, mod_id, - context=context).latest_version - if vercmp(version, latest_version) > 0: - self.write(cursor, user, mod_id, { - 'latest_version': version, - 'url': url, - }, context=context) - res[0] += 1 - return res - - def download(self, cursor, user, ids, download=True, context=None): - # TODO download import only if all dependencies are present - res = [] - for mod in self.browse(cursor, user, ids, context=context): - if not mod.url: - continue - match = re.search('-([a-zA-Z0-9\._-]+)(\.zip)', mod.url, re.I) - version = '0' - if match: - version = match.group(1) - if vercmp(mod.installed_version or '0', version) >= 0: - continue - res.append(mod.url) - if not download: - continue - zip_file = urllib.urlopen(mod.url).read() - fname = os.path.join(MODULES_PATH, mod.name+'.zip') - try: - file_p = file(fname, 'wb') - file_p.write(zip_file) - file_p.close() - except IOError: - raise ExceptORM('Error', 'Can not create the module file: %s' - % (fname,)) - tryton = Module.get_module_info(mod.name) - self.write(cursor, user, mod.id, { - 'description': tryton.get('description', ''), - 'shortdesc': tryton.get('name', ''), - 'author': tryton.get('author', 'Unknown'), - 'website': tryton.get('website', ''), - 'license': tryton.get('license', 'GPL-2'), - }) - self._update_dependencies(cursor, user, mod.id, tryton.get('depends', - [])) - self._update_category(cursor, user, mod.id, tryton.get('category', - 'Uncategorized')) - # Import module - zimp = zipimport.zipimporter(fname) - zimp.load_module(mod.name) return res def _update_dependencies(self, cursor, user, module_id, depends=None): @@ -563,7 +451,6 @@ ModuleDependency() class ModuleUpdateListInit(WizardOSV): _name = 'ir.module.module.update_list.init' - repositories = fields.Text('Repositories', readonly=True) ModuleUpdateListInit() @@ -582,8 +469,8 @@ class ModuleUpdateList(Wizard): def _update_module(self, cursor, user, data, context): module_obj = self.pool.get('ir.module.module') - update, add = module_obj.update_list(cursor, user) - return {'update': update, 'add': add} + add = module_obj.update_list(cursor, user) + return {'add': add} def _action_module_open(self, cursor, user, data, context): return { @@ -596,18 +483,9 @@ class ModuleUpdateList(Wizard): 'type': 'ir.action.act_window', } - def _get_repositories(self, cursor, user, data, context): - repository_obj = self.pool.get('ir.module.repository') - ids = repository_obj.search(cursor, user, []) - res = repository_obj.read(cursor, user, ids, ['name', 'url'], context) - return { - 'repositories': '\n'.join([x['name']+': '+x['url'] \ - for x in res]), - } - states = { 'init': { - 'actions': [_get_repositories], + 'actions': [], 'result': { 'type': 'form', 'object': 'ir.module.module.update_list.init', diff --git a/trytond/ir/module/module.xml b/trytond/ir/module/module.xml index 9243a0b137..997cb7a1df 100644 --- a/trytond/ir/module/module.xml +++ b/trytond/ir/module/module.xml @@ -16,18 +16,16 @@ -