Ejemplo n.º 1
0
 def _get_desc(self):
     for module in self:
         path = modules.get_module_resource(
             module.name, 'static/description/index.html')
         if path:
             with tools.file_open(path, 'rb') as desc_file:
                 doc = desc_file.read()
                 html = lxml.html.document_fromstring(doc)
                 for element, attribute, link, pos in html.iterlinks():
                     if element.get('src') and not '//' in element.get(
                             'src') and not 'static/' in element.get('src'):
                         element.set(
                             'src', "/%s/static/description/%s" %
                             (module.name, element.get('src')))
                 module.description_html = tools.html_sanitize(
                     lxml.html.tostring(html))
         else:
             overrides = {
                 'embed_stylesheet': False,
                 'doctitle_xform': False,
                 'output_encoding': 'unicode',
                 'xml_declaration': False,
                 'file_insertion_enabled': False,
             }
             output = publish_string(
                 source=module.description
                 if not module.application and module.description else '',
                 settings_overrides=overrides,
                 writer=MyWriter())
             module.description_html = tools.html_sanitize(output)
Ejemplo n.º 2
0
 def load_templates(self, **kwargs):
     base_url = request.httprequest.base_url
     templates = [
         'mail/static/src/xml/abstract_thread_window.xml',
         'mail/static/src/xml/discuss.xml',
         'mail/static/src/xml/thread.xml',
         'im_livechat/static/src/xml/im_livechat.xml',
     ]
     return [tools.file_open(tmpl, 'rb').read() for tmpl in templates]
Ejemplo n.º 3
0
 def read_image(self, path):
     if not path:
         return False
     path_info = path.split(',')
     icon_path = get_module_resource(path_info[0], path_info[1])
     icon_image = False
     if icon_path:
         with tools.file_open(icon_path, 'rb') as icon_file:
             icon_image = base64.encodestring(icon_file.read())
     return icon_image
Ejemplo n.º 4
0
 def _get_icon_image(self):
     for module in self:
         module.icon_image = ''
         if module.icon:
             path_parts = module.icon.split('/')
             path = modules.get_module_resource(path_parts[1],
                                                *path_parts[2:])
         else:
             path = modules.module.get_module_icon(module.name)
         if path:
             with tools.file_open(path, 'rb') as image_file:
                 module.icon_image = base64.b64encode(image_file.read())
Ejemplo n.º 5
0
def relaxng(view_type):
    """ Return a validator for the given view type, or None. """
    if view_type not in _relaxng_cache:
        with tools.file_open(
                os.path.join('base', 'rng',
                             '%s_view.rng' % view_type)) as frng:
            try:
                relaxng_doc = etree.parse(frng)
                _relaxng_cache[view_type] = etree.RelaxNG(relaxng_doc)
            except Exception:
                _logger.exception(
                    'Failed to load RelaxNG XML schema for views validation')
                _relaxng_cache[view_type] = None
    return _relaxng_cache[view_type]
Ejemplo n.º 6
0
 def get_value_icon_lazy_load(self):
     if self.is_lazy_load == False:
         img_path = get_resource_path('theme_clarico_vega',
                                      'static/src/img/Lazyload.gif')
         with tools.file_open(img_path, 'rb') as f:
             self.lazy_load_image = base64.b64encode(f.read())
Ejemplo n.º 7
0
 def _default_favicon(self):
     img_path = get_resource_path('web', 'static/src/img/favicon.png')
     with tools.file_open(img_path, 'rb') as f:
         return base64.b64encode(f.read())
Ejemplo n.º 8
0
 def _default_logo(self):
     image_path = get_resource_path('website', 'static/src/img',
                                    'website_logo.png')
     with tools.file_open(image_path, 'rb') as f:
         return base64.b64encode(f.read())
Ejemplo n.º 9
0
def load_information_from_description_file(module, mod_path=None):
    """
    :param module: The name of the module (sale, purchase, ...)
    :param mod_path: Physical path of module, if not providedThe name of the module (sale, purchase, ...)
    """
    if not mod_path:
        mod_path = get_module_path(module, downloaded=True)
    manifest_file = module_manifest(mod_path)
    if manifest_file:
        # default values for descriptor
        info = {
            'application': False,
            'author': 'Harpiya Software Technologies',
            'auto_install': False,
            'category': 'Uncategorized',
            'depends': [],
            'description': '',
            'icon': get_module_icon(module),
            'installable': True,
            'license': 'LGPL-3',
            'post_load': None,
            'version': '1.0',
            'web': False,
            'sequence': 100,
            'summary': '',
            'website': '',
        }
        info.update(
            zip('depends data demo test init_xml update_xml demo_xml'.split(),
                iter(list, None)))

        f = tools.file_open(manifest_file, mode='rb')
        try:
            info.update(ast.literal_eval(pycompat.to_text(f.read())))
        finally:
            f.close()

        if not info.get('description'):
            readme_path = [
                opj(mod_path, x) for x in README
                if os.path.isfile(opj(mod_path, x))
            ]
            if readme_path:
                with tools.file_open(readme_path[0]) as fd:
                    info['description'] = fd.read()

        # auto_install is set to `False` if disabled, and a set of
        # auto_install dependencies otherwise. That way, we can set
        # auto_install: [] to always auto_install a module regardless of its
        # dependencies
        auto_install = info.get('auto_install', info.get('active', False))
        if isinstance(auto_install, collections.Iterable):
            info['auto_install'] = set(auto_install)
            non_dependencies = info['auto_install'].difference(info['depends'])
            assert not non_dependencies,\
                "auto_install triggers must be dependencies, found " \
                "non-dependencies [%s] for module %s" % (
                    ', '.join(non_dependencies), module
                )
        elif auto_install:
            info['auto_install'] = set(info['depends'])
        else:
            info['auto_install'] = False

        info['version'] = adapt_version(info['version'])
        return info

    _logger.debug('module %s: no manifest file found %s', module,
                  MANIFEST_NAMES)
    return {}