def get_filename(self, source): """Return cache filename for @source""" # make sure we take the source name into account # so that we get a "break" when locale changes source_id = "%s%s%s" % (repr(source), str(source), source.version) hash_str = hashlib.md5(source_id.encode("utf-8")).hexdigest() filename = self.name_template % (hash_str, self.format_version) return os.path.join(config.get_cache_home(), filename)
def get_filename(self, source): """Return cache filename for @source""" # make sure we take the source name into account # so that we get a "break" when locale changes source_id = "%s%s%s" % (repr(source), str(source), source.version) bytes = hashlib.md5(source_id).digest() hashstr = bytes.encode("base64").rstrip("\n=").replace("/", "-") filename = self.name_template % (hashstr, self.pickle_version) return os.path.join(config.get_cache_home(), filename)
def rm_old_cachefiles(self): """Checks if there are old cachefiles from last version, and deletes those """ for dpath, dirs, files in os.walk(config.get_cache_home()): # Look for files matching beginning and end of # name_template, with the previous file version chead, ctail = self.name_template.split("%s") ctail = ctail % ((self.pickle_version -1),) obsolete_files = [] for cfile in files: if cfile.startswith(chead) and cfile.endswith(ctail): cfullpath = os.path.join(dpath, cfile) obsolete_files.append(cfullpath) if obsolete_files: self.output_info("Removing obsolete cache files:", sep="\n", *obsolete_files) for fpath in obsolete_files: # be overly careful assert fpath.startswith(config.get_cache_home()) assert "kupfer" in fpath os.unlink(fpath)
def cache_filename(): return os.path.join(config.get_cache_home(), __name__)
def _get_filename(self): version = 1 return os.path.join(config.get_cache_home(), "application_identification_v%d.pickle" % version)
def _get_filename(self): # Version 1: Up to incl v203 # Version 2: Do not track terminals version = 2 return os.path.join(config.get_cache_home(), "application_identification_v%d.pickle" % version)