On 02/17/2011 04:21 PM, James Antill wrote:
On Thu, 2011-02-17 at 12:15 +0200, Panu Matilainen wrote:
At least hasattr() calls for _cache_prco_names_* and _prco_lookup
were causing headers to be loaded when not wanted at all, causing
headers for all to-be updated packages to be kept in memory throughout
the entire transaction.
It'd probably make sense to only ever load the header if the requested
attribute is a valid rpm tag, but leaving that for another patch...
---
yum/rpmsack.py | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/yum/rpmsack.py b/yum/rpmsack.py
index 227ed89..e0798ce 100644
--- a/yum/rpmsack.py
+++ b/yum/rpmsack.py
@@ -67,13 +67,18 @@ class RPMInstalledPackage(YumInstalledPackage):
raise Errors.PackageSackError, 'Rpmdb changed underneath us'
def __getattr__(self, varname):
- self.hdr = val = self._get_hdr()
- self._has_hdr = True
# If these existed, then we wouldn't get here ... and nothing in the
DB
# starts and ends with __'s. So these are missing.
if varname.startswith('__') and varname.endswith('__'):
raise AttributeError, "%s has no attribute %s" % (self, varname)
-
+
+ # At least _cache_prco_names and _prco_lookup need the real attribute
+ if varname.startswith('_'):
+ return object.__getattr__(self, varname)
Given that we got here, isn't this just the same as raising directly?
If so it's probably easier to understand to just raise directly.
Yeah, you're right... I was somehow under the (wrong) impression that
__getattr__() overrides /all/ attribute access, and was a bit baffled by
the "if these existed" comments but shrugged it off as "that's probably
got something to do with the special _foo attribute tricks :)
Should it simply be changed to this then?
- # starts and ends with __'s. So these are missing.
- if varname.startswith('__') and varname.endswith('__'):
+ # starts with _'s. So these are missing.
+ if varname.startswith('_'):
- Panu -
_______________________________________________
Yum-devel mailing list
[email protected]
http://lists.baseurl.org/mailman/listinfo/yum-devel