From 566a4681a81b5ddba275c0953b5edc08fe7f472b Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Fri, 7 Jun 2019 14:48:59 -0400 Subject: support: Rework support check invocations SupportCache.check_support(SUPPORT_FOOBAR, args) becomes SupportCache.foobar(args) And SupportCache absorbs the caching infrastructure from VirtinstConnection. For now we add some hackery to hide the API change from callers, but this will be undone in the next patch --- virtinst/connection.py | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'virtinst/connection.py') diff --git a/virtinst/connection.py b/virtinst/connection.py index 558b6142..57d74ffa 100644 --- a/virtinst/connection.py +++ b/virtinst/connection.py @@ -57,7 +57,6 @@ class VirtinstConnection(object): self._uriobj = URI(self._uri) self._caps = None - self._support_cache = {} self._fetch_cache = {} # These let virt-manager register a callback which provides its @@ -68,7 +67,7 @@ class VirtinstConnection(object): self.cb_fetch_all_nodedevs = None self.cb_cache_new_pool = None - self.support = support.SupportCache() + self.support = support.SupportCache(weakref.proxy(self)) ############## @@ -79,6 +78,9 @@ class VirtinstConnection(object): if attr in self.__dict__: return self.__dict__[attr] + if attr.startswith("SUPPORT_"): + return getattr(self.support, attr.split("_", 1)[1].lower()) + # Proxy virConnect API calls libvirtconn = self.__dict__.get("_libvirtconn") return getattr(libvirtconn, attr) @@ -380,30 +382,13 @@ class VirtinstConnection(object): # Support check helpers # ######################### - for _supportname in [_supportname for _supportname in - dir(support.SupportCache) if - _supportname.startswith("SUPPORT_")]: - locals()[_supportname] = getattr(support.SupportCache, _supportname) - - def check_support(self, features, data=None): - def _check_support(key): - if key not in self._support_cache: - self._support_cache[key] = self.support.check_support( - self, key, data or self) - return self._support_cache[key] - for f in util.listify(features): # 'and' condition over the feature list - if not _check_support(f): + if not f(data): return False return True - def _check_version(self, version): - # Entry point for the test suite to do simple version checks, - # actual code should only use check_support - return self.support.check_version(self, version) - def support_remote_url_install(self): if self._magic_uri: return False -- cgit v1.2.1