Update of /cvsroot/freevo/freevo/src/skins/main
In directory sc8-pr-cvs1:/tmp/cvs-serv22234

Modified Files:
        main.py 
Log Message:
use pickle to cache parsed skin files

Index: main.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/skins/main/main.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** main.py     14 Dec 2003 17:39:52 -0000      1.27
--- main.py     1 Jan 2004 12:26:15 -0000       1.28
***************
*** 10,13 ****
--- 10,16 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.28  2004/01/01 12:26:15  dischi
+ # use pickle to cache parsed skin files
+ #
  # Revision 1.27  2003/12/14 17:39:52  dischi
  # Change TRUE and FALSE to True and False; vfs fixes
***************
*** 32,50 ****
  # o renamed some skin function names
  #
- # Revision 1.21  2003/11/29 11:27:41  dischi
- # move objectcache to util
- #
- # Revision 1.20  2003/11/28 20:08:58  dischi
- # renamed some config variables
- #
- # Revision 1.19  2003/11/22 20:34:23  dischi
- # use new vfs
- #
- # Revision 1.18  2003/11/22 12:02:11  dischi
- # make the skin blankscreen a real plugin area
- #
- # Revision 1.17  2003/10/31 17:00:20  dischi
- # splashscreen for bsd
- #
  # -----------------------------------------------------------------------
  # Freevo - A Home Theater PC framework
--- 35,38 ----
***************
*** 113,117 ****
          self.last_draw     = None, None, None
          self.screen        = screen.get_singleton()
-         self.xml_cache     = util.objectcache.ObjectCache(3, desc='xmlskin')
          self.areas         = {}
  
--- 101,104 ----
***************
*** 134,138 ****
              print "skin not found, using fallback skin"
              self.settings.load('blue.fxd')
!         
          for dir in config.cfgfilepath:
              local_skin = '%s/local_skin.fxd' % dir
--- 121,126 ----
              print "skin not found, using fallback skin"
              self.settings.load('blue.fxd')
!             config.SKIN_XML_FILE = 'blue.fxd'
!             
          for dir in config.cfgfilepath:
              local_skin = '%s/local_skin.fxd' % dir
***************
*** 143,146 ****
--- 131,181 ----
  
  
+     def save_cache(self, settings, filename):
+         """
+         cache the fxd skin settings in 'settings' to the OVERLAY_DIR cachfile
+         for filename and this resolution
+         """
+         cache = vfs.getoverlay('%s.skin-%sx%s' % (filename, osd.width, osd.height))
+         if cache:
+             # delete font object, because it can't be pickled
+             for f in settings.font:
+                 del settings.font[f].font
+             # save object and version information
+             util.save_pickle((xml_skin.FXD_FORMAT_VERSION, settings), cache)
+             # restore font object
+             for f in settings.font:
+                 settings.font[f].font = osd.getfont(settings.font[f].name,
+                                                     settings.font[f].size)
+             
+ 
+     def load_cache(self, filename):
+         """
+         load a skin cache file
+         """
+         cache = vfs.getoverlay('%s.skin-%sx%s' % (filename, osd.width, osd.height))
+         if not cache:
+             return None
+ 
+         if not os.path.isfile(cache):
+             return None
+         
+         version, settings = util.read_pickle(cache)
+         if not settings or version != xml_skin.FXD_FORMAT_VERSION:
+             return None
+ 
+         # check if all files used by the skin are not newer than
+         # the cache file
+         ftime = os.stat(cache)[stat.ST_MTIME]
+         for f in settings.fxd_files:
+             if os.stat(f)[stat.ST_MTIME] > ftime:
+                 return None
+ 
+         # restore the font objects
+         for f in settings.font:
+             settings.font[f].font = osd.getfont(settings.font[f].name,
+                                                 settings.font[f].size)
+         return settings
+ 
+         
      def register(self, type, areas):
          """
***************
*** 175,196 ****
              return None
  
          if copy_content:
!             cname = '%s%s%s' % (str(self.settings), filename,
!                                 os.stat(filename)[stat.ST_MTIME])
!             settings = self.xml_cache[cname]
!             if not settings:
!                 settings = copy.copy(self.settings)
!                 if not settings.load(filename, copy_content, clear=True):
!                     return None
!                 self.xml_cache[cname] = settings
          else:
!             cname = '%s%s' % (filename, os.stat(filename)[stat.ST_MTIME])
!             settings = self.xml_cache[cname]
!             if not settings:
!                 settings = xml_skin.XMLSkin()
!                 if not settings.load(filename, copy_content, clear=True):
!                     return None
!                 self.xml_cache[cname] = settings
  
          return settings
      
--- 210,225 ----
              return None
  
+         settings = self.load_cache(filename)
+         if settings:
+             return settings
+             
          if copy_content:
!             settings = copy.copy(self.settings)
          else:
!             settings = xml_skin.XMLSkin()
  
+         if not settings.load(filename, copy_content, clear=True):
+             return None
+         self.save_cache(settings, filename)
          return settings
      




-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to