Example #1
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': 'Eagle ERP',
            '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(
            pycompat.izip(
                '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_native(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:
                readme_text = tools.file_open(readme_path[0]).read()
                info['description'] = readme_text

        if 'active' in info:
            # 'active' has been renamed 'auto_install'
            info['auto_install'] = info['active']

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

    _logger.debug('module %s: no manifest file found %s', module,
                  MANIFEST_NAMES)
    return {}
Example #2
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)
Example #3
0
 def _get_default_favicon(self, original=False):
     img_path = get_resource_path('web', 'static/src/img/favicon.ico')
     with tools.file_open(img_path, 'rb') as f:
         if original:
             return base64.b64encode(f.read())
         # Modify the source image to add a colored bar on the bottom
         # This could seem overkill to modify the pixels 1 by 1, but
         # Pillow doesn't provide an easy way to do it, and this
         # is acceptable for a 16x16 image.
         color = (randrange(32, 224,
                            24), randrange(32, 224,
                                           24), randrange(32, 224, 24))
         original = Image.open(f)
         new_image = Image.new('RGBA', original.size)
         height = original.size[1]
         width = original.size[0]
         bar_size = 1
         for y in range(height):
             for x in range(width):
                 pixel = original.getpixel((x, y))
                 if height - bar_size <= y + 1 <= height:
                     new_image.putpixel((x, y),
                                        (color[0], color[1], color[2], 255))
                 else:
                     new_image.putpixel(
                         (x, y), (pixel[0], pixel[1], pixel[2], pixel[3]))
         stream = io.BytesIO()
         new_image.save(stream, format="ICO")
         return base64.b64encode(stream.getvalue())
Example #4
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]
Example #5
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
Example #6
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())
Example #7
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]
Example #8
0
    def load_script(path, module_name):
        fp, fname = tools.file_open(path, pathinfo=True)
        fp2 = None

        # pylint: disable=file-builtin,undefined-variable
        if not isinstance(fp, file):
            # imp.load_source need a real file object, so we create
            # one from the file-like object we get from file_open
            fp2 = os.tmpfile()
            fp2.write(fp.read())
            fp2.seek(0)

        try:
            return imp.load_source(module_name, fname, fp2 or fp)
        finally:
            if fp:
                fp.close()
            if fp2:
                fp2.close()
Example #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': 'Eagle ERP',
            '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 {}
Example #10
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())
Example #11
0
 def _default_favicon(self):
     img_path = get_resource_path('web', 'static/src/img/favicon.ico')
     with tools.file_open(img_path, 'rb') as f:
         return base64.b64encode(f.read())