From d461ffa02ff07c41cd8b627d7e872f9be94ce267 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Fri, 27 Dec 2013 17:22:49 +0100 Subject: [PATCH] [entropy.core.settings.base] introduce packages_configuration_hash() This method serves the purpose of returning a hash of the current packages configuration (masking, unmasking, keywording, etc). This will be used by upper layers as part of cache keys generation. --- lib/entropy/core/settings/base.py | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/entropy/core/settings/base.py b/lib/entropy/core/settings/base.py index 32c5f0f7f..a930c2e9b 100644 --- a/lib/entropy/core/settings/base.py +++ b/lib/entropy/core/settings/base.py @@ -19,6 +19,7 @@ """ import codecs import errno +import hashlib import os import sys import threading @@ -1064,6 +1065,41 @@ class SystemSettings(Singleton, EntropyPluginStore): """ return self.__setting_dirs.copy() + def packages_configuration_hash(self): + """ + Return a SHA1 hash of the current packages configuration. + This includes masking, unmasking, keywording, system masking + settings. + """ + cache_key = "__packages_configuration_hash__" + cached = self.get(cache_key) + if cached is not None: + return cached + + sha = hashlib.sha1() + + configs = ( + ("mask", self['mask']), + ("unmask", self['unmask']), + ("keyword_mask", self['keywords']), + ("license_mask", self['license_mask']), + ("live_unmask", self['live_packagemasking']['unmask_matches']), + ("live_mask", self['live_packagemasking']['mask_matches']), + ) + + sha.update(const_convert_to_rawstring("-begin-")) + for name, config in configs: + cache_s = "%s:{%s}|" % ( + name, ",".join(sorted(config)), + ) + sha.update(const_convert_to_rawstring(cache_s)) + + sha.update(const_convert_to_rawstring("-end-")) + + outcome = sha.hexdigest() + self[cache_key] = outcome + return outcome + def _keywords_parser(self): """ Parser returning package keyword masking metadata