예제 #1
0
    def get_web(self, cr, uid, names, context=None):
        """Returns the web content of all the named addons.
        
        get_web(cr, uid, [module_name], context) -> [{name, depends, content}]

        The toplevel directory of the zipped content is called 'web',
        its final naming has to be managed by the client
        """
        mod_ids = self.search(cr, uid, [('name', 'in', names)], context=context)
        # TODO: browse_search
        if not mod_ids:
            return []
        res = []
        for module in self.browse(cr, uid, mod_ids, context=context):
            web_dir = addons.get_module_resource(module.name, 'web')
            if not web_dir:
                continue
            web_data = addons.zip_directory(web_dir, False)
            if self._translations_subdir(module):
                web_data = self._add_translations(module, web_data)
            res.append({
                'name': module.name,
                'version': module.installed_version,
                'depends': list(self._web_dependencies(
                            cr, uid, module, context=context)),
                'content': base64.encodestring(web_data)
            })
            
        self.__logger.debug('Sending web content of modules %s to web client',    
                    [ r['name'] for r in res])
        return res
예제 #2
0
    def get_web(self, cr, uid, names, context=None):
        """ 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)
        if not modules: return []
        self.__logger.info('Sending web content of modules %s '
                           'to web client', names)

        modules_data = []
        for module in modules:
            web_data = addons.zip_directory(
                addons.get_module_resource(module.name, 'web'), False)
            if self._translations_subdir(module):
                web_data = self._add_translations(module, web_data)
            modules_data.append({
                'name': module.name,
                'version': module.installed_version,
                'depends': list(self._web_dependencies(
                    cr, uid, module, context=context)),
                'content': base64.encodestring(web_data)
            })
        return modules_data
예제 #3
0
    def _add_translations(self, module, web_data):
        """ Adds translation data to a zipped web module

        :param module: a module descriptor
        :type module: browse(ir.module.module)
        :param web_data: zipped data of a web module
        :type web_data: bytes
        """
        # cStringIO.StringIO is either read or write, not r/w
        web_zip = StringIO.StringIO(web_data)
        web_archive = zipfile.ZipFile(web_zip, 'a')

        # get the contents of the i18n or po folder and move them to the
        # po/messages subdirectory of the web module.
        # The POT file will be incorrectly named, but that should not
        # matter since the web client is not going to use it, only the PO
        # files.
        translations_file = cStringIO.StringIO(
            addons.zip_directory(self._translations_subdir(module), False))
        translations_archive = zipfile.ZipFile(translations_file)

        for path in translations_archive.namelist():
            web_path = os.path.join('web', 'po', 'messages',
                                    os.path.basename(path))
            web_archive.writestr(web_path, translations_archive.read(path))

        translations_archive.close()
        translations_file.close()

        web_archive.close()
        try:
            return web_zip.getvalue()
        finally:
            web_zip.close()
예제 #4
0
    def _add_translations(self, module, web_data):
        """ Adds translation data to a zipped web module

        :param module: a module descriptor
        :type module: browse(ir.module.module)
        :param web_data: zipped data of a web module
        :type web_data: bytes
        """
        # cStringIO.StringIO is either read or write, not r/w
        web_zip = StringIO.StringIO(web_data)
        web_archive = zipfile.ZipFile(web_zip, 'a')

        # get the contents of the i18n or po folder and move them to the
        # po/messages subdirectory of the web module.
        # The POT file will be incorrectly named, but that should not
        # matter since the web client is not going to use it, only the PO
        # files.
        translations_file = cStringIO.StringIO(
            addons.zip_directory(self._translations_subdir(module), False))
        translations_archive = zipfile.ZipFile(translations_file)

        for path in translations_archive.namelist():
            web_path = os.path.join(
                'web', 'po', 'messages', os.path.basename(path))
            web_archive.writestr(
                web_path,
                translations_archive.read(path))

        translations_archive.close()
        translations_file.close()

        web_archive.close()
        try:
            return web_zip.getvalue()
        finally:
            web_zip.close()
예제 #5
0
    def get_web(self, cr, uid, names, context=None):
        """ 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)
        if not modules: return []
        self.__logger.info(
            'Sending web content of modules %s '
            'to web client', names)

        modules_data = []
        for module in modules:
            web_data = addons.zip_directory(
                addons.get_module_resource(module.name, 'web'), False)
            if self._translations_subdir(module):
                web_data = self._add_translations(module, web_data)
            modules_data.append({
                'name':
                module.name,
                'version':
                module.installed_version,
                'depends':
                list(self._web_dependencies(cr, uid, module, context=context)),
                'content':
                base64.encodestring(web_data)
            })
        return modules_data