[yum-commits] Branch 'yum-3_2_X' - 3 commits - output.py yum/rpmsack.py
James Antill
james at osuosl.org
Tue Mar 31 22:19:32 UTC 2009
output.py | 4 ++++
yum/rpmsack.py | 44 +++++++++++++++++++++++++++-----------------
2 files changed, 31 insertions(+), 17 deletions(-)
New commits:
commit e837824db7590a80b5c30becf0fc7ced0f6cf87a
Author: James Antill <james at and.org>
Date: Tue Mar 31 18:17:26 2009 -0400
Speed up __iter__ and __contains__ etc. using self._read_cached_data
diff --git a/yum/rpmsack.py b/yum/rpmsack.py
index 8c499d3..aadb333 100644
--- a/yum/rpmsack.py
+++ b/yum/rpmsack.py
@@ -705,7 +705,8 @@ class RPMDBAdditionalDataPackage(object):
os.makedirs(self._mydir)
attr = _sanitize(attr)
- del self._read_cached_data[attr]
+ if attr in self._read_cached_data:
+ del self._read_cached_data[attr]
fn = self._mydir + '/' + attr
fn = os.path.normpath(fn)
fo = open(fn + '.tmp', 'w')
@@ -765,8 +766,13 @@ class RPMDBAdditionalDataPackage(object):
object.__delattr__(self, attr)
def __iter__(self):
- items = glob.glob(self._mydir + '/*')
- return [ item.replace(self._mydir + '/', '') for item in items].__iter__()
+ for item in self._read_cached_data:
+ yield item
+ for item in glob.glob(self._mydir + '/*'):
+ item = item[(len(self._mydir) + 1):]
+ if item in self._read_cached_data:
+ continue
+ yield item
# def __dir__(self): # for 2.6 and beyond, apparently
# return list(self.__iter__()) + self.__dict__.keys()
commit 5244411b61a1603ddea2b1dd9e5c9fb5d5ad186b
Author: James Antill <james at and.org>
Date: Tue Mar 31 18:08:07 2009 -0400
Minor changes to yumdb:
. Add _read_cached_data, so we don't hit the FS for each access.
. Add _sanitize, and _sanitize pkg.name for dir.
. complain if get_package() doesn't get any args.
. Remove sync_with_rpmdb from old plan where data would be in rpmdb
diff --git a/yum/rpmsack.py b/yum/rpmsack.py
index ae5bef1..8c499d3 100644
--- a/yum/rpmsack.py
+++ b/yum/rpmsack.py
@@ -635,6 +635,8 @@ class RPMDBPackageSack(PackageSackBase):
# XXX deprecate?
return [po.pkgtup for po in self.getRequires(name, flags, version)]
+def _sanitize(path):
+ return path.replace('/', '').replace('~', '')
class RPMDBAdditionalData(object):
@@ -673,6 +675,7 @@ class RPMDBAdditionalData(object):
if pkgid in self._packages:
return self._packages[pkgid]
(n, a, e, v,r) = pkgtup
+ n = _sanitize(n) # Please die in a fire rpmbuild
thisdir = '%s/%s/%s-%s-%s-%s-%s' % (self.conf.db_path,
n[0], pkgid, n, v, r, a)
self._packages[pkgid] = thisdir
@@ -684,30 +687,28 @@ class RPMDBAdditionalData(object):
thisdir = self._get_dir_name(po.pkgtup, po.pkgid)
elif pkgtup and pkgid:
thisdir = self._get_dir_name(pkgtup, pkgid)
+ else:
+ raise ValueError,"Pass something to RPMDBAdditionalData.get_package"
return RPMDBAdditionalDataPackage(self.conf, thisdir)
- def sync_with_rpmdb(self, rpmdbobj):
- """populate out the dirs and remove all the items no longer in the rpmdb
- and/or populate various bits to the currently installed version"""
- pass
-
class RPMDBAdditionalDataPackage(object):
def __init__(self, conf, pkgdir):
self._conf = conf
self._mydir = pkgdir
# FIXME needs some intelligent caching beyond the FS cache
+ self._read_cached_data = {}
def _write(self, attr, value):
# check for self._conf.writable before going on?
if not os.path.exists(self._mydir):
os.makedirs(self._mydir)
-
- attr = attr.replace('/', '')
- attr = attr.replace('~', '')
+
+ attr = _sanitize(attr)
+ del self._read_cached_data[attr]
fn = self._mydir + '/' + attr
fn = os.path.normpath(fn)
- fo = open(fn, 'w')
+ fo = open(fn + '.tmp', 'w')
try:
fo.write(value)
except (OSError, IOError), e:
@@ -716,21 +717,24 @@ class RPMDBAdditionalDataPackage(object):
fo.flush()
fo.close()
del fo
- del fn
+ os.rename(fn + '.tmp', fn) # even works on ext4 now!:o
+ self._read_cached_data[attr] = value
def _read(self, attr):
- attr = attr.replace('/', '')
- attr = attr.replace('~', '')
+ attr = _sanitize(attr)
+
+ if attr in self._read_cached_data:
+ return self._read_cached_data[attr]
+
fn = self._mydir + '/' + attr
if not os.path.exists(fn):
raise AttributeError, "%s has no attribute %s" % (self, attr)
fo = open(fn, 'r')
- res = fo.read()
+ self._read_cached_data[attr] = fo.read()
fo.close()
del fo
- del fn
- return res
+ return self._read_cached_data[attr]
def _delete(self, attr):
"""remove the attribute file"""
commit 1222984fb43d26bbe440532474b5f5907ff7468e
Author: James Antill <james at and.org>
Date: Tue Mar 31 16:19:43 2009 -0400
Add comment for translators
diff --git a/output.py b/output.py
index 669efce..b88bc27 100755
--- a/output.py
+++ b/output.py
@@ -1106,6 +1106,10 @@ Remove %5.5s Package(s)
if not self._last_interrupt:
hibeg = self.term.MODE['bold']
hiend = self.term.MODE['normal']
+ # For translators: This is output like:
+# Current download cancelled, interrupt (ctrl-c) again within two seconds
+# to exit.
+ # Where "interupt (ctrl-c) again" and "two" are highlighted.
msg = _("""
Current download cancelled, %sinterrupt (ctrl-c) again%s within %s%s%s seconds to exit.
""") % (hibeg, hiend, hibeg, delta_exit_str, hiend)
More information about the Yum-commits
mailing list