コード例 #1
0
ファイル: picture.py プロジェクト: sudo-dirk/pygal
 def _create_citem(self, size, force=False):
     this_method_version = '.0.1.0'
     if self._citem_info is None:
         try:
             with open(self.prop_citem_path(), 'r') as fh:
                 self._citem_info = json.loads(fh.read())
         except:
             self._citem_info = dict()
     VERSION = '__module_version_citem_creation_%d__' % size
     if force or not os.path.exists(self._cimage_item_path(size)) or self._citem_info.get(VERSION) != __version__ + this_method_version:
         logger.info('creating citem (%d) for %s', size, self.name())
         try:
             p = picture_edit(self.raw_path())
             p.resize(size)
             p.rotate(self.orientation())
         except IOError:
             logger.error('error creating citem (%d) for %s', size, self.name())
         else:
             try:
                 p.save(self._cimage_item_path(size))
             except IOError:
                 logger.error('error creating citem (%d) for %s', size, self.name())
             else:
                 self._citem_info[VERSION] = __version__ + this_method_version
                 try:
                     with open(self.prop_citem_path(), 'w') as fh:
                         fh.write(json.dumps(self._citem_info, sort_keys=True, indent=4))
                 except IOError:
                     logger.warning('Error while writing cache file (%s)', self._cache_filename)
コード例 #2
0
ファイル: video.py プロジェクト: sudo-dirk/pygal
 def _create_citem(self, size, force=False):
     this_method_version = '0.1.0'
     if self._citem_info is None:
         try:
             with open(self.prop_citem_path(), 'r') as fh:
                 self._citem_info = json.loads(fh.read())
         except:
             self._citem_info = dict()
     VERSION = '__module_version_citem_creation_%d__' % size
     WATERMARK = '__watermark_uid_citem_creation_%d__' % size
     watermark_path = os.path.join(os.path.join(os.path.dirname(__file__), '..'), 'theme', 'static', 'common', 'img', 'thumbnail_movie.png')
     if force or not os.path.exists(self._cimage_item_path(size)) or self._citem_info.get(VERSION) != __version__ + this_method_version or self._citem_info.get(WATERMARK) != fstools.uid(watermark_path):
         logger.info('creating citem (%d) for %s', size, self.name())
         try:
             p = video_picture_edit(self.raw_path(), logger=logger)
             p.resize(size)
             movie_icon = picture_edit(watermark_path)
             p.join(movie_icon, p.JOIN_TOP_RIGHT, 0.75)
         except IOError:
             logger.error('error creating citem (%d) for %s', size, self.name())
         else:
             try:
                 p.save(self._cimage_item_path(size))
             except IOError:
                 logger.error('error creating citem (%d) for %s', size, self.name())
             else:
                 self._citem_info[VERSION] = __version__ + this_method_version
                 self._citem_info[WATERMARK] = fstools.uid(watermark_path)
                 try:
                     with open(self.prop_citem_path(), 'w') as fh:
                         fh.write(json.dumps(self._citem_info, sort_keys=True, indent=4))
                 except IOError:
                     logger.warning('Error while writing cache file (%s)', self._cache_filename)