def _scan_disk(self, cr, uid, context=None):
        """Scan the file system and register the result in database"""
        found_fonts = []
        for font_path in customfonts.list_all_sysfonts():
            try:
                font = ttfonts.TTFontFile(font_path)
                _logger.debug("Found font %s at %s", font.name, font_path)
                found_fonts.append((font.familyName, font.name, font_path, font.styleName))
            except ttfonts.TTFError:
                _logger.warning("Could not register Font %s", font_path)

        for family, name, path, mode in found_fonts:
            if not self.search(cr, uid, [('family', '=', family), ('name', '=', name)], context=context):
                self.create(cr, uid, {
                    'family': family, 'name': name,
                    'path': path, 'mode': mode,
                }, context=context)

        # remove fonts not present on the disk anymore
        existing_font_names = [name for (family, name, path, mode) in found_fonts]
        inexistant_fonts = self.search(cr, uid, [('name', 'not in', existing_font_names), ('path', '!=', '/dev/null')], context=context)
        if inexistant_fonts:
            self.unlink(cr, uid, inexistant_fonts, context=context)

        RegistryManager.signal_caches_change(cr.dbname)
        self._sync(cr, uid, context=context)
        return True
Ejemplo n.º 2
0
 def _scan_disk(self, cr, uid, context=None):
     """Scan the file system and register the result in database"""
     found_fonts = []
     for font_path in customfonts.list_all_sysfonts():
         try:
             font = ttfonts.TTFontFile(font_path)
             _logger.debug("Found font %s at %s", font.name, font_path)
             found_fonts.append((font.familyName, font.name, font_path, font.styleName))
         except Exception, ex:
             _logger.warning("Could not register Font %s: %s", font_path, ex)
Ejemplo n.º 3
0
 def _scan_disk(self, cr, uid, context=None):
     """Scan the file system and register the result in database"""
     found_fonts = []
     for font_path in customfonts.list_all_sysfonts():
         try:
             font = ttfonts.TTFontFile(font_path)
             _logger.debug("Found font %s at %s", font.name, font_path)
             found_fonts.append(
                 (font.familyName, font.name, font_path, font.styleName))
         except Exception, ex:
             _logger.warning("Could not register Font %s: %s", font_path,
                             ex)
Ejemplo n.º 4
0
 def _scan_disk(self, cr, uid, context=None):
     """Scan the file system and register the result in database"""
     found_fonts = []
     for font_path in customfonts.list_all_sysfonts():
         try:
             font = ttfonts.TTFontFile(font_path)
             _logger.debug("Found font %s at %s", font.name, font_path)
             found_fonts.append((font.familyName, font.name, font_path, font.styleName))
         except KeyError, ex:
             if ex.args and ex.args[0] == 'head':
                 # Sometimes, the system can have a lot of Bitmap fonts, and
                 # in this case, Reportlab can't load the 'head' table from
                 # the structure of the TTF file (ex: NISC18030.ttf)
                 # In this case, we have to bypass the loading of this font!
                 _logger.warning("Could not register Fond %s (Old Bitmap font)", font_path)
             else:
                 raise
         except ttfonts.TTFError:
             _logger.warning("Could not register Font %s", font_path)
Ejemplo n.º 5
0
    def _scan_disk(self, cr, uid, context=None):
        """Scan the file system and register the result in database"""
        found_fonts = []
        for font_path in customfonts.list_all_sysfonts():
            try:
                font = ttfonts.TTFontFile(font_path)
                _logger.debug("Found font %s at %s", font.name, font_path)
                found_fonts.append(
                    (font.familyName, font.name, font_path, font.styleName))
            except Exception as ex:
                _logger.warning("Could not register Font %s: %s", font_path,
                                ex)

        for family, name, path, mode in found_fonts:
            if not self.search(cr,
                               uid, [('family', '=', family),
                                     ('name', '=', name)],
                               context=context):
                self.create(cr,
                            uid, {
                                'family': family,
                                'name': name,
                                'path': path,
                                'mode': mode,
                            },
                            context=context)

        # remove fonts not present on the disk anymore
        existing_font_names = [
            name for (family, name, path, mode) in found_fonts
        ]
        inexistant_fonts = self.search(
            cr,
            uid, [('name', 'not in', existing_font_names),
                  ('path', '!=', '/dev/null')],
            context=context)
        if inexistant_fonts:
            self.unlink(cr, uid, inexistant_fonts, context=context)

        RegistryManager.signal_caches_change(cr.dbname)
        self._sync(cr, uid, context=context)
        return True
Ejemplo n.º 6
0
 def _scan_disk(self, cr, uid, context=None):
     """Scan the file system and register the result in database"""
     found_fonts = []
     for font_path in customfonts.list_all_sysfonts():
         try:
             font = ttfonts.TTFontFile(font_path)
             _logger.debug("Found font %s at %s", font.name, font_path)
             found_fonts.append(
                 (font.familyName, font.name, font_path, font.styleName))
         except KeyError, ex:
             if ex.args and ex.args[0] == 'head':
                 # Sometimes, the system can have a lot of Bitmap fonts, and
                 # in this case, Reportlab can't load the 'head' table from
                 # the structure of the TTF file (ex: NISC18030.ttf)
                 # In this case, we have to bypass the loading of this font!
                 _logger.warning(
                     "Could not register Fond %s (Old Bitmap font)",
                     font_path)
             else:
                 raise
         except ttfonts.TTFError:
             _logger.warning("Could not register Font %s", font_path)