[ADD] server-side web addons
bzr revid: xmo@openerp.com-20100928075257-06f2b3o6kvdb9f6y
This commit is contained in:
parent
3eac92fc4a
commit
c153c2d46b
|
@ -203,14 +203,14 @@ def get_module_filetree(module, dir='.'):
|
|||
|
||||
return tree
|
||||
|
||||
def get_module_as_zip_from_module_directory(module_directory, b64enc=True, src=True):
|
||||
"""Compress a module directory
|
||||
def zip_directory(directory, b64enc=True, src=True):
|
||||
"""Compress a directory
|
||||
|
||||
@param module_directory: The module directory
|
||||
@param directory: The directory to compress
|
||||
@param base64enc: if True the function will encode the zip file with base64
|
||||
@param src: Integrate the source files
|
||||
|
||||
@return: a stream to store in a file-like object
|
||||
@return: a string containing the zip file
|
||||
"""
|
||||
|
||||
RE_exclude = re.compile('(?:^\..+\.swp$)|(?:\.py[oc]$)|(?:\.bak$)|(?:\.~.~$)', re.I)
|
||||
|
@ -225,16 +225,16 @@ def get_module_as_zip_from_module_directory(module_directory, b64enc=True, src=T
|
|||
|
||||
archname = StringIO()
|
||||
archive = PyZipFile(archname, "w", ZIP_DEFLATED)
|
||||
archive.writepy(module_directory)
|
||||
_zippy(archive, module_directory, src=src)
|
||||
archive.writepy(directory)
|
||||
_zippy(archive, directory, src=src)
|
||||
archive.close()
|
||||
val = archname.getvalue()
|
||||
archive_data = archname.getvalue()
|
||||
archname.close()
|
||||
|
||||
if b64enc:
|
||||
val = base64.encodestring(val)
|
||||
return base64.encodestring(archive_data)
|
||||
|
||||
return val
|
||||
return archive_data
|
||||
|
||||
def get_module_as_zip(modulename, b64enc=True, src=True):
|
||||
"""Generate a module as zip file with the source or not and can do a base64 encoding
|
||||
|
@ -256,7 +256,7 @@ def get_module_as_zip(modulename, b64enc=True, src=True):
|
|||
if b64enc:
|
||||
val = base64.encodestring(val)
|
||||
else:
|
||||
val = get_module_as_zip_from_module_directory(ap, b64enc, src)
|
||||
val = zip_directory(ap, b64enc, src)
|
||||
|
||||
return val
|
||||
|
||||
|
|
|
@ -302,6 +302,7 @@ CREATE TABLE ir_module_module (
|
|||
certificate character varying(64),
|
||||
description text,
|
||||
demo boolean default False,
|
||||
web boolean DEFAULT FALSE,
|
||||
primary key(id)
|
||||
);
|
||||
ALTER TABLE ir_module_module add constraint name_uniq unique (name);
|
||||
|
|
|
@ -173,12 +173,14 @@ class module(osv.osv):
|
|||
'reports_by_module': fields.function(_get_views, method=True, string='Reports', type='text', multi="meta", store=True),
|
||||
'views_by_module': fields.function(_get_views, method=True, string='Views', type='text', multi="meta", store=True),
|
||||
'certificate' : fields.char('Quality Certificate', size=64, readonly=True),
|
||||
'web': fields.boolean('Has a web component', readonly=True),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'state': lambda *a: 'uninstalled',
|
||||
'demo': lambda *a: False,
|
||||
'license': lambda *a: 'AGPL-3',
|
||||
'web': False,
|
||||
}
|
||||
_order = 'name'
|
||||
|
||||
|
@ -332,6 +334,7 @@ class module(osv.osv):
|
|||
'website': terp.get('website', ''),
|
||||
'license': terp.get('license', 'GPL-2'),
|
||||
'certificate': terp.get('certificate') or None,
|
||||
'web': terp.get('web') or False,
|
||||
}
|
||||
|
||||
# update the list of available packages
|
||||
|
@ -470,6 +473,39 @@ class module(osv.osv):
|
|||
logger.critical('module %s: invalid quality certificate: %s', mod.name, mod.certificate)
|
||||
raise osv.except_osv(_('Error'), _('Module %s: Invalid Quality Certificate') % (mod.name,))
|
||||
|
||||
def list_web(self, cr, uid, context=False):
|
||||
""" list_web(cr, uid, context) -> [module_name]
|
||||
Lists all the currently installed modules with a web component.
|
||||
|
||||
Returns a list of addon names.
|
||||
"""
|
||||
return [
|
||||
module['name']
|
||||
for module in self.browse(cr, uid,
|
||||
self.search(cr, uid,
|
||||
[('web', '=', True),
|
||||
('state', 'in', ['installed','to upgrade','to remove'])],
|
||||
context=context),
|
||||
context=context)]
|
||||
def get_web(self, cr, uid, names, context=False):
|
||||
""" get_web(cr, uid, [module_name], context) -> [{name, depends, content}]
|
||||
|
||||
Returns the web content of all the named addons.
|
||||
|
||||
The toplevel directory of the zipped content is called 'web',
|
||||
its final naming has to be managed by the client
|
||||
"""
|
||||
modules = self.browse(cr, uid,
|
||||
self.search(cr, uid, [('name', 'in', names)], context=context),
|
||||
context=context)
|
||||
return [
|
||||
{'name': module.name,
|
||||
'depends': [dep.name for dep in module.dependencies_id],
|
||||
'content': addons.zip_directory(
|
||||
addons.get_module_resource(module.name, 'web'))}
|
||||
for module in modules
|
||||
]
|
||||
|
||||
module()
|
||||
|
||||
class module_dependency(osv.osv):
|
||||
|
@ -501,5 +537,3 @@ class module_dependency(osv.osv):
|
|||
], string='State', readonly=True, select=True),
|
||||
}
|
||||
module_dependency()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -110,11 +110,12 @@ def init_db(cr):
|
|||
id = cr.fetchone()[0]
|
||||
cr.execute('insert into ir_module_module \
|
||||
(id, author, website, name, shortdesc, description, \
|
||||
category_id, state, certificate) \
|
||||
values (%s, %s, %s, %s, %s, %s, %s, %s, %s)', (
|
||||
category_id, state, certificate, web) \
|
||||
values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', (
|
||||
id, info.get('author', ''),
|
||||
info.get('website', ''), i, info.get('name', False),
|
||||
info.get('description', ''), p_id, state, info.get('certificate') or None))
|
||||
info.get('description', ''), p_id, state, info.get('certificate') or None,
|
||||
info.get('web') or False))
|
||||
cr.execute('insert into ir_model_data \
|
||||
(name,model,module, res_id, noupdate) values (%s,%s,%s,%s,%s)', (
|
||||
'module_meta_information', 'ir.module.module', i, id, True))
|
||||
|
|
Loading…
Reference in New Issue