From cd1733a975803c1c268612fc0dd7ab18a16c97c3 Mon Sep 17 00:00:00 2001 From: beville Date: Sun, 30 Dec 2012 23:32:37 +0000 Subject: [PATCH] Added a cache version file to manage clearing old one on upgrade git-svn-id: http://comictagger.googlecode.com/svn/trunk@291 6c5673fe-1810-88d6-992b-cd32ca31540c --- comicvinecacher.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/comicvinecacher.py b/comicvinecacher.py index 6e00eb3..41abbe7 100644 --- a/comicvinecacher.py +++ b/comicvinecacher.py @@ -25,6 +25,7 @@ import sys import os import datetime +import ctversion from settings import ComicTaggerSettings class ComicVineCacher: @@ -32,15 +33,38 @@ class ComicVineCacher: def __init__(self ): self.settings_folder = ComicTaggerSettings.getSettingsFolder() self.db_file = os.path.join( self.settings_folder, "cv_cache.db") + self.version_file = os.path.join( self.settings_folder, "cache_version.txt") + + #verify that cache is from same version as this one + data = "" + try: + with open( self.version_file, 'rb' ) as f: + data = f.read() + f.close() + except: + pass + if data != ctversion.version: + self.clearCache() if not os.path.exists( self.db_file ): self.create_cache_db() def clearCache( self ): - os.unlink( self.db_file ) + try: + os.unlink( self.db_file ) + except: + pass + try: + os.unlink( self.version_file ) + except: + pass def create_cache_db( self ): + #create the version file + with open( self.version_file, 'w' ) as f: + f.write( ctversion.version ) + # this will wipe out any existing version open( self.db_file, 'w').close()