Remove module repository
This commit is contained in:
1 parent
d2cc8c31c2
commit
addc090e18
7 files changed
+17
-252
No files matched your search
@@ -17,7 +17,6 @@
|
||||
'rule.xml',
|
||||
'property.xml',
|
||||
'module/module.xml',
|
||||
'module/repository.xml',
|
||||
'module/category.xml',
|
||||
'default.xml',
|
||||
],
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
from category import *
|
||||
from repository import *
|
||||
from module import *
|
||||
+9
-131
@@ -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',
|
||||
|
||||
@@ -16,18 +16,16 @@
|
||||
<field name="shortdesc"/>
|
||||
<separator name="description" colspan="4"/>
|
||||
<field name="description" invisible="0" colspan="4"/>
|
||||
<label name="installed_version"/>
|
||||
<field name="installed_version"/>
|
||||
<label name="latest_version"/>
|
||||
<field name="latest_version"/>
|
||||
<label name="version"/>
|
||||
<field name="version"/>
|
||||
<label name="license"/>
|
||||
<field name="license"/>
|
||||
<label name="author"/>
|
||||
<field name="author"/>
|
||||
<label name="website"/>
|
||||
<field name="website" widget="url"/>
|
||||
<label name="url"/>
|
||||
<field name="url" widget="url"/>
|
||||
<label name="license"/>
|
||||
<field name="license"/>
|
||||
<newline/>
|
||||
<label name="state"/>
|
||||
<field name="state" readonly="1"/>
|
||||
@@ -73,8 +71,7 @@
|
||||
<field name="name" select="1"/>
|
||||
<field name="shortdesc" select="2"/>
|
||||
<field name="author" select="2"/>
|
||||
<field name="installed_version"/>
|
||||
<field name="latest_version"/>
|
||||
<field name="version"/>
|
||||
<field name="website" select="2"/>
|
||||
<field name="state" select="1"/>
|
||||
<field name="description" invisible="1" select="2"/>
|
||||
@@ -116,10 +113,9 @@
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Update Module List">
|
||||
<label string="This function will check for new modules in the 'modules' path and on module repositories:"
|
||||
colspan="4" align="0.0"/>
|
||||
<field name="repositories" colspan="4"/>
|
||||
<form string="Update Module List" col="1">
|
||||
<label string="This function will check for new modules in the 'modules' path."
|
||||
align="0.0"/>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
@@ -130,8 +126,6 @@
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="New modules">
|
||||
<label name="update"/>
|
||||
<field name="update" colspan="3"/>
|
||||
<label name="add"/>
|
||||
<field name="add" colspan="3"/>
|
||||
</form>
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
"Repository"
|
||||
from trytond.osv import OSV, fields
|
||||
|
||||
|
||||
class Repository(OSV):
|
||||
"Module repository"
|
||||
_name = "ir.module.repository"
|
||||
_description = __doc__
|
||||
name = fields.Char('Name', size=128)
|
||||
url = fields.Char('Url', size=256, required=True)
|
||||
sequence = fields.Integer('Sequence', required=True)
|
||||
filter = fields.Char('Filter', size=128, required=True,
|
||||
help='Regexp to search module on the repository webpage:\n'
|
||||
'- The first parenthesis must match the name of the module.\n'
|
||||
'- The second parenthesis must match all the version number.\n'
|
||||
'- The last parenthesis must match the extension of the module.')
|
||||
active = fields.boolean('Active')
|
||||
_order = "sequence"
|
||||
|
||||
def default_sequence(self, cursor, user, context=None):
|
||||
return 5
|
||||
|
||||
def default_filter(self, cursor, user, context=None):
|
||||
return 'href="([a-zA-Z0-9_]+)-' \
|
||||
'((\\d+)((\\.\\d+)*)([a-z]?)' \
|
||||
'((_(pre|p|beta|alpha|rc)\\d*)*)(-r(\\d+))?)(\.zip)"'
|
||||
|
||||
def default_active(self, cursor, user, context=None):
|
||||
return 1
|
||||
|
||||
Repository()
|
||||
@@ -1,59 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="repository_view_form">
|
||||
<field name="model">ir.module.repository</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Repository">
|
||||
<label name="name"/>
|
||||
<field name="name"/>
|
||||
<label name="sequence"/>
|
||||
<field name="sequence"/>
|
||||
<label name="url"/>
|
||||
<field name="url" widget="url"/>
|
||||
<label name="active"/>
|
||||
<field name="active"/>
|
||||
<label name="filter"/>
|
||||
<field name="filter" colspan="3"/>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="repository_view_tree">
|
||||
<field name="model">ir.module.repository</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<tree string="Repositories">
|
||||
<field name="sequence"/>
|
||||
<field name="active" select="1"/>
|
||||
<field name="name" select="1"/>
|
||||
<field name="url" select="1"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window" id="act_repository_form">
|
||||
<field name="name">Repositories</field>
|
||||
<field name="type">ir.action.act_window</field>
|
||||
<field name="res_model">ir.module.repository</field>
|
||||
<field name="view_type">form</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_repository_form_view1">
|
||||
<field name="sequence" eval="1"/>
|
||||
<field name="view" ref="repository_view_tree"/>
|
||||
<field name="act_window" ref="act_repository_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_repository_form_view2">
|
||||
<field name="sequence" eval="2"/>
|
||||
<field name="view" ref="repository_view_form"/>
|
||||
<field name="act_window" ref="act_repository_form"/>
|
||||
</record>
|
||||
<menuitem parent="menu_modules"
|
||||
action="act_repository_form" id="menu_repository_form"/>
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -361,21 +361,6 @@
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_unlink" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_ir_module_repository">
|
||||
<field name="model" search="[('model', '=', 'ir.module.repository')]"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_unlink" eval="False"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_ir_module_repository_admin">
|
||||
<field name="model" search="[('model', '=', 'ir.module.repository')]"/>
|
||||
<field name="group" ref="group_admin"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_unlink" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.rule.group" id="rule_group_menu">
|
||||
<field name="model" search="[('model', '=', 'ir.ui.menu')]"/>
|
||||
<field name="global_p" eval="True"/>
|
||||
|
||||
Reference in new issue
Block a user