Update of /cvsroot/freevo/freevo/src/tv
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23067/src/tv

Modified Files:
        epg_xmltv.py 
Log Message:
Changes to stop two processes tripping over the creation of the epg pickle file.


Index: epg_xmltv.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/tv/epg_xmltv.py,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** epg_xmltv.py        13 Mar 2004 22:28:41 -0000      1.48
--- epg_xmltv.py        16 Mar 2004 01:04:18 -0000      1.49
***************
*** 10,13 ****
--- 10,16 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.49  2004/03/16 01:04:18  rshortt
+ # Changes to stop two processes tripping over the creation of the epg pickle file.
+ #
  # Revision 1.48  2004/03/13 22:28:41  dischi
  # better handling of bad programs
***************
*** 69,72 ****
--- 72,76 ----
  import traceback
  import calendar
+ import shutil
  
  import config
***************
*** 94,98 ****
  
  
! def get_guide(popup=None, verbose=True):
      """
      Get a TV guide from memory cache, file cache or raw XMLTV file.
--- 98,102 ----
  
  
! def get_guide(popup=None, verbose=True, XMLTV_FILE=None):
      """
      Get a TV guide from memory cache, file cache or raw XMLTV file.
***************
*** 102,109 ****
      global cached_guide
  
      # Can we use the cached version (if same as the file)?
      if (cached_guide == None or
!         (os.path.isfile(config.XMLTV_FILE) and 
!          cached_guide.timestamp != os.path.getmtime(config.XMLTV_FILE))):
  
          # No, is there a pickled version ("file cache") in a file?
--- 106,116 ----
      global cached_guide
  
+     if not XMLTV_FILE:
+         XMLTV_FILE = config.XMLTV_FILE
+ 
      # Can we use the cached version (if same as the file)?
      if (cached_guide == None or
!         (os.path.isfile(XMLTV_FILE) and 
!          cached_guide.timestamp != os.path.getmtime(XMLTV_FILE))):
  
          # No, is there a pickled version ("file cache") in a file?
***************
*** 111,117 ****
          
          got_cached_guide = False
!         if (os.path.isfile(config.XMLTV_FILE) and
              os.path.isfile(pname) and (os.path.getmtime(pname) >
!                                        os.path.getmtime(config.XMLTV_FILE))):
              if verbose:
                  _debug_('XMLTV, reading cached file (%s)' % pname)
--- 118,124 ----
          
          got_cached_guide = False
!         if (os.path.isfile(XMLTV_FILE) and
              os.path.isfile(pname) and (os.path.getmtime(pname) >
!                                        os.path.getmtime(XMLTV_FILE))):
              if verbose:
                  _debug_('XMLTV, reading cached file (%s)' % pname)
***************
*** 137,141 ****
                      _debug_('EPG version missmatch, must be reloaded')
  
!             elif cached_guide.timestamp != os.path.getmtime(config.XMLTV_FILE):
                  # Hmmm, weird, there is a pickled file newer than the TV.xml
                  # file, but the timestamp in it does not match the TV.xml
--- 144,148 ----
                      _debug_('EPG version missmatch, must be reloaded')
  
!             elif cached_guide.timestamp != os.path.getmtime(XMLTV_FILE):
                  # Hmmm, weird, there is a pickled file newer than the TV.xml
                  # file, but the timestamp in it does not match the TV.xml
***************
*** 156,162 ****
                  
              if verbose:
!                 _debug_('XMLTV, trying to read raw file (%s)' % config.XMLTV_FILE)
              try:    
!                 cached_guide = load_guide(verbose)
            except:
                # Don't violently crash on a incomplete or empty TV.xml please.
--- 163,169 ----
                  
              if verbose:
!                 _debug_('XMLTV, trying to read raw file (%s)' % XMLTV_FILE)
              try:    
!                 cached_guide = load_guide(verbose, XMLTV_FILE)
            except:
                # Don't violently crash on a incomplete or empty TV.xml please.
***************
*** 167,170 ****
--- 174,184 ----
                  traceback.print_exc()
              else:
+                 # Replace config.XMLTV_FILE before we save the pickle in order
+                 # to avoid timestamp confision.
+                 if XMLTV_FILE != config.XMLTV_FILE:
+                     shutil.copyfile(XMLTV_FILE, config.XMLTV_FILE)
+                     os.unlink(XMLTV_FILE)
+                     cached_guide.timestamp = os.path.getmtime(config.XMLTV_FILE)
+ 
                  # Dump a pickled version for later reads
                  util.save_pickle(cached_guide, pname)
***************
*** 180,197 ****
  
  
! def load_guide(verbose=True):
      """
      Load a guide from the raw XMLTV file using the xmltv.py support lib.
      Returns a TvGuide or None if an error occurred
      """
      # Create a new guide
      guide = epg_types.TvGuide()
  
      # Is there a file to read from?
!     if os.path.isfile(config.XMLTV_FILE):
          gotfile = 1
!         guide.timestamp = os.path.getmtime(config.XMLTV_FILE)
      else:
!         _debug_('XMLTV file (%s) missing!' % config.XMLTV_FILE)
          gotfile = 0
  
--- 194,214 ----
  
  
! def load_guide(verbose=True, XMLTV_FILE=None):
      """
      Load a guide from the raw XMLTV file using the xmltv.py support lib.
      Returns a TvGuide or None if an error occurred
      """
+     if not XMLTV_FILE:
+         XMLTV_FILE = config.XMLTV_FILE
+ 
      # Create a new guide
      guide = epg_types.TvGuide()
  
      # Is there a file to read from?
!     if os.path.isfile(XMLTV_FILE):
          gotfile = 1
!         guide.timestamp = os.path.getmtime(XMLTV_FILE)
      else:
!         _debug_('XMLTV file (%s) missing!' % XMLTV_FILE)
          gotfile = 0
  
***************
*** 223,227 ****
          if gotfile:
              # Don't read the channel info unless we have to, takes a long time!
!             xmltv_channels = xmltv.read_channels(util.gzopen(config.XMLTV_FILE))
          
          # Was the guide read successfully?
--- 240,244 ----
          if gotfile:
              # Don't read the channel info unless we have to, takes a long time!
!             xmltv_channels = xmltv.read_channels(util.gzopen(XMLTV_FILE))
          
          # Was the guide read successfully?
***************
*** 252,256 ****
          if verbose:
              _debug_('reading xmltv data')
!         f = util.gzopen(config.XMLTV_FILE)
          xmltv_programs = xmltv.read_programmes(f)
          f.close()
--- 269,273 ----
          if verbose:
              _debug_('reading xmltv data')
!         f = util.gzopen(XMLTV_FILE)
          xmltv_programs = xmltv.read_programmes(f)
          f.close()



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to