Clean-up old cached entried.

This commit is contained in:
Lukáš Lalinský
2006-11-28 14:12:03 +01:00
parent 6b478a5bcd
commit bf75c321ef
2 changed files with 12 additions and 0 deletions

View File

@@ -169,6 +169,7 @@ class Tagger(QtGui.QApplication, ComponentManager, Component):
self.thread_assist.spawn(self._ofa.done, thread=self._analyze_thread)
self.thread_assist.stop()
self.browser_integration.stop()
CachedWebService.cleanup(self.cache_dir)
def run(self):
self.window.show()

View File

@@ -20,7 +20,9 @@
import os.path
import re
import sha
import time
from musicbrainz2.webservice import WebService
from stat import *
class CachedWebService(WebService):
"""This class provides a cached wrapper around ``WebService``."""
@@ -101,3 +103,12 @@ class CachedWebService(WebService):
if m:
filename += "." + m.group(1)
return os.path.join(self._cache_dir, filename)
@staticmethod
def cleanup(cachedir):
now = time.time()
for filename in os.listdir(cachedir):
filename = os.path.join(cachedir, filename)
mtime = os.stat(filename)[ST_MTIME]
if now - mtime > 60 * 60 * 24 * 10:
os.unlink(filename)