Handle difference in pickle protocol between python 2.x and 3.x
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 5 Jul 2012 08:44:55 +0000 (10:44 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 5 Jul 2012 08:44:55 +0000 (10:44 +0200)
src/caching_data.py

index 0610f7d..c3a614c 100644 (file)
@@ -42,16 +42,15 @@ class CachingData:
             cache_info = cache_info.split(' ')
             self.version = cache_info[0]
             if(self.version != CACHE_VERSION):
-                logging.warning("Cache file has version %s and the script version is %s. Deleting cache.",
-                                self.version, CACHE_VERSION)
-                raise IOError
+                raise IOError("Cache file has version %s and the script version is %s" % (self.version, CACHE_VERSION))
             self.fallback_to_date_header = cache_info[1]
             if(self.fallback_to_date_header != str(fallback_mode)):
-                logging.warning("Cache file date fallback mode setting is different than current settings. Deleting cache.")
-                raise IOError
+                raise IOError("Cache file date fallback mode setting is different than current settings")
             logging.info("Cache file %s loaded", CACHE_FILENAME)
-            logging.debug("%s users found.", len(self.data))
-        except IOError:
+            logging.info("%s users found.", len(self.data))
+        except (IOError, ValueError) as ex:
+            logging.warning("Couldn't load cache file %s: %s", CACHE_FILENAME, ex)
+            logging.warning("DELETING CACHE")
             self.version = CACHE_VERSION
             stored_cache_info = self.version + ' ' + str(fallback_mode)
             self.data = {}