From 2e715f41a5fe9d95fae59b8ca49ffb5a3e49feaa Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Mon, 6 Apr 2009 21:33:50 +0200 Subject: [PATCH] entropy.client.interfaces.cache.Cache: move clear_dump_cache and repository_move_clear_cache to entropy.core.SystemSettings entropy.client.interfaces.Client: create SystemSettings plugin to push Entropy Client-only metadata into SystemSettings and keep it agnostic entropy.core.SystemSettings: now Entropy-free, it's agnostic! other minor fixes --- libraries/entropy/client/interfaces/cache.py | 33 +---- libraries/entropy/client/interfaces/client.py | 48 +++++++- libraries/entropy/core.py | 115 ++++++++---------- 3 files changed, 97 insertions(+), 99 deletions(-) diff --git a/libraries/entropy/client/interfaces/cache.py b/libraries/entropy/client/interfaces/cache.py index 04a8dcf13..1c76253a4 100644 --- a/libraries/entropy/client/interfaces/cache.py +++ b/libraries/entropy/client/interfaces/cache.py @@ -125,28 +125,7 @@ class Cache: def clear_dump_cache(self, dump_name, skip = []): self.Cacher.sync(wait = True) - dump_path = os.path.join(etpConst['dumpstoragedir'],dump_name) - dump_dir = os.path.dirname(dump_path) - #dump_file = os.path.basename(dump_path) - for currentdir, subdirs, files in os.walk(dump_dir): - path = os.path.join(dump_dir,currentdir) - if skip: - found = False - for myskip in skip: - if path.find(myskip) != -1: - found = True - break - if found: continue - for item in files: - if item.endswith(etpConst['cachedumpext']): - item = os.path.join(path,item) - try: os.remove(item) - except OSError: pass - try: - if not os.listdir(path): - os.rmdir(path) - except OSError: - pass + self.SystemSettings._clear_dump_cache(dump_name, skip = skip) def update_ugc_cache(self, repository): if not self.UGC.is_repository_eapi3_aware(repository): @@ -167,15 +146,7 @@ class Cache: return status def repository_move_clear_cache(self, repoid = None): - self.clear_dump_cache(etpCache['world_available']) - self.clear_dump_cache(etpCache['world_update']) - self.clear_dump_cache(etpCache['check_package_update']) - self.clear_dump_cache(etpCache['filter_satisfied_deps']) - self.clear_dump_cache(self.atomMatchCacheKey) - self.clear_dump_cache(etpCache['dep_tree']) - if repoid != None: - self.clear_dump_cache("%s/%s%s/" % (etpCache['dbMatch'],etpConst['dbnamerepoprefix'],repoid,)) - self.clear_dump_cache("%s/%s%s/" % (etpCache['dbSearch'],etpConst['dbnamerepoprefix'],repoid,)) + return self.SystemSettings._clear_repository_cache(repoid = repoid) def get_available_packages_chash(self, branch): # client digest not needed, cache is kept updated diff --git a/libraries/entropy/client/interfaces/client.py b/libraries/entropy/client/interfaces/client.py index 6d7ee5d71..2b3c58f74 100644 --- a/libraries/entropy/client/interfaces/client.py +++ b/libraries/entropy/client/interfaces/client.py @@ -32,6 +32,43 @@ from entropy.client.interfaces.methods import Repository as CRepository, Misc, M from entropy.client.interfaces.fetch import Fetchers from entropy.client.interfaces.metadata import Extractors from entropy.const import etpConst, etpCache +from entropy.core import SystemSettings, SystemSettingsPlugin + +class ClientSystemSettingsPlugin(SystemSettingsPlugin): + + import entropy.tools as entropyTools + + def system_mask_parser(self, system_settings_instance): + + # match installed packages of system_mask + mask_installed = [] + mask_installed_keys = {} + while (self._helper.clientDbconn != None): + try: + self._helper.clientDbconn.validateDatabase() + except SystemDatabaseError: + break + mc_cache = set() + m_list = system_settings_instance['repos_system_mask'] + \ + system_settings_instance['system_mask'] + for atom in m_list: + m_ids, m_r = self._helper.clientDbconn.atomMatch(atom, + multiMatch = True) + if m_r != 0: + continue + mykey = self.entropyTools.dep_getkey(atom) + if mykey not in mask_installed_keys: + mask_installed_keys[mykey] = set() + for m_id in m_ids: + if m_id in mc_cache: + continue + mc_cache.add(m_id) + mask_installed.append(m_id) + mask_installed_keys[mykey].add(m_id) + break + + system_settings_instance['repos_system_mask_installed'] = mask_installed + system_settings_instance['repos_system_mask_installed_keys'] = mask_installed_keys class Client(Singleton, TextInterface, Loaders, Cache, Calculators, \ CRepository, Misc, Match, Fetchers, Extractors): @@ -58,7 +95,6 @@ class Client(Singleton, TextInterface, Loaders, Cache, Calculators, \ self.noclientdb = False self.openclientdb = True - from entropy.core import SystemSettings # setup package settings (masking and other stuff) self.SystemSettings = SystemSettings() @@ -130,8 +166,14 @@ class Client(Singleton, TextInterface, Loaders, Cache, Calculators, \ if self.openclientdb: self.open_client_repository() - # Make sure we connect Entropy AFTER client db init - self.SystemSettings.connect_entropy(self) + # create our SystemSettings plugin + self.sys_settings_mask_plugin = ClientSystemSettingsPlugin(self) + self.sys_settings_mask_plugin_id = str(self) + self.sys_settings_mask_plugin.add_parser( + self.sys_settings_mask_plugin.system_mask_parser) + # Make sure we connect Entropy Client plugin AFTER client db init + self.SystemSettings.add_plugin( + self.sys_settings_mask_plugin_id, self.sys_settings_mask_plugin) # needs to be started here otherwise repository cache will be # always dropped diff --git a/libraries/entropy/core.py b/libraries/entropy/core.py index 54fdbdf6c..6b1a0a09b 100644 --- a/libraries/entropy/core.py +++ b/libraries/entropy/core.py @@ -26,7 +26,7 @@ from entropy.exceptions import IncorrectParameter, SystemDatabaseError from entropy.const import etpConst, etpSys, const_setup_perms, etpRepositories,\ etpRepositoriesOrder, const_secure_config_file, const_set_nice_level, \ const_extract_srv_repo_params, etpRepositories, etpRepositoriesExcluded, \ - const_extract_cli_repo_params + const_extract_cli_repo_params, etpCache from entropy.i18n import _ class Singleton(object): @@ -79,12 +79,12 @@ class SystemSettingsPlugin: """ SystemSettingsPlugin constructor. - @param handler_interface -- any Python instance that could + @param helper_interface -- any Python instance that could be of help to your parsers @type handler_instance instance """ self.__parsers = [] - self.__plugin_interface = helper_interface + self._helper = helper_interface def add_parser(self, callable_function): """ @@ -132,7 +132,6 @@ class SystemSettings(Singleton): self.__data = {} self.__is_destroyed = False - self.Entropy = None self.__plugins = {} self.__setting_files_order = [] @@ -219,33 +218,6 @@ class SystemSettings(Singleton): del self.__plugins[plugin_id] self.clear() - def connect_entropy(self, entropy_instance): - """ - Connect an Entropy (client/server) instance to - this Singleton. Be warned, it could be very dangerous - if you don't know what you are doing. - - Valid instances are: - entropy.client.interfaces.Client - entropy.server.interfaces.Server - """ - - from entropy.client.interfaces import Client - from entropy.server.interfaces import Server - if not isinstance(entropy_instance,(Client,Server,)): - mytxt = _("A valid Client/Server interface instance is needed") - raise IncorrectParameter("IncorrectParameter: %s" % (mytxt,)) - self.Entropy = entropy_instance - self.__scan() # do this again to re-fill settings - - def disconnect_entropy(self): - """ - Remove an Entropy (client/server) instance to - this Singleton. - """ - self.Entropy = None - self.__scan() - def __setup_const(self): """ @@ -341,35 +313,7 @@ class SystemSettings(Singleton): for plugin_id in sorted(self.__plugins): self.__plugins[plugin_id].parse(self) - # match installed packages of system_mask - mask_installed = [] - mask_installed_keys = {} - if self.Entropy != None: - while (self.Entropy.clientDbconn != None): - try: - self.Entropy.clientDbconn.validateDatabase() - except SystemDatabaseError: - break - mc_cache = set() - m_list = self.__data['repos_system_mask'] + \ - self.__data['system_mask'] - for atom in m_list: - m_ids, m_r = self.Entropy.clientDbconn.atomMatch(atom, - multiMatch = True) - if m_r != 0: - continue - mykey = self.entropyTools.dep_getkey(atom) - if mykey not in mask_installed_keys: - mask_installed_keys[mykey] = set() - for m_id in m_ids: - if m_id in mc_cache: - continue - mc_cache.add(m_id) - mask_installed.append(m_id) - mask_installed_keys[mykey].add(m_id) - break - self.__data['repos_system_mask_installed'] = mask_installed - self.__data['repos_system_mask_installed_keys'] = mask_installed_keys + print self.__data.get('repos_system_mask_installed_keys') # merge persistent settings back self.__data.update(self.__persistent_settings) @@ -1498,6 +1442,48 @@ class SystemSettings(Singleton): return data + def _clear_repository_cache(self, repoid = None): + """ + Internal method, go away! + """ + self._clear_dump_cache(etpCache['world_available']) + self._clear_dump_cache(etpCache['world_update']) + self._clear_dump_cache(etpCache['check_package_update']) + self._clear_dump_cache(etpCache['filter_satisfied_deps']) + self._clear_dump_cache(etpCache['atomMatch']) + self._clear_dump_cache(etpCache['dep_tree']) + if repoid != None: + self._clear_dump_cache("%s/%s%s/" % ( + etpCache['dbMatch'],etpConst['dbnamerepoprefix'],repoid,)) + self._clear_dump_cache("%s/%s%s/" % ( + etpCache['dbSearch'],etpConst['dbnamerepoprefix'],repoid,)) + + def _clear_dump_cache(self, dump_name, skip = []): + """ + Internal method, go away! + """ + dump_path = os.path.join(etpConst['dumpstoragedir'],dump_name) + dump_dir = os.path.dirname(dump_path) + #dump_file = os.path.basename(dump_path) + for currentdir, subdirs, files in os.walk(dump_dir): + path = os.path.join(dump_dir,currentdir) + if skip: + found = False + for myskip in skip: + if path.find(myskip) != -1: + found = True + break + if found: continue + for item in files: + if item.endswith(etpConst['cachedumpext']): + item = os.path.join(path,item) + try: os.remove(item) + except OSError: pass + try: + if not os.listdir(path): + os.rmdir(path) + except OSError: + pass def __generic_parser(self, filepath): """ @@ -1530,12 +1516,11 @@ class SystemSettings(Singleton): @return None """ if os.path.isdir(etpConst['dumpstoragedir']): - if repoid and (self.Entropy != None): - self.Entropy.repository_move_clear_cache(repoid) + if repoid: + self._clear_repository_cache(repoid = repoid) return - if self.Entropy != None: - for repoid in self['repositories']['order']: - self.Entropy.repository_move_clear_cache(repoid) + for repoid in self['repositories']['order']: + self._clear_repository_cache(repoid = repoid) else: os.makedirs(etpConst['dumpstoragedir'])