summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-08-08 23:32:19 -0500
committerDan McGee <dan@archlinux.org>2011-08-09 15:36:05 -0500
commit9d3d647f0031edd31fc7442f9d2cd9729718e41c (patch)
treec730e1cb3631e849d6490113d0efe6054b4ba344
parent5f38660be12c898e6ddef0d09b973d259d80c763 (diff)
downloadpacman-9d3d647f0031edd31fc7442f9d2cd9729718e41c.tar.xz
pactest: improve speed of local DB dependent rules
We were doing some really silly stuff before and abusing the os.walk() call, having to walk the entire local database for every single PKG rule. We really only need top level directories, and we can cache any generated package since calls to db_read() are well-defined and only happen in one place. This speeds up the running of tests that may want to add 100 PKG_VERSION rules at once, where before we had to limit how many we used in order to not put a serious cramp in the speed of the test suite run. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--test/pacman/pmdb.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py
index 63a156ec..5195ec64 100644
--- a/test/pacman/pmdb.py
+++ b/test/pacman/pmdb.py
@@ -58,6 +58,8 @@ class pmdb(object):
self.dbdir = os.path.join(root, util.PM_DBPATH, treename)
self.dbfile = None
self.is_local = True
+ self.read_dircache = None
+ self.read_pkgcache = {}
else:
self.dbdir = None
self.dbfile = os.path.join(root, util.PM_SYNCDBPATH, treename + ".db")
@@ -81,20 +83,24 @@ class pmdb(object):
if not self.dbdir or not os.path.isdir(self.dbdir):
return None
- dbentry = ""
- for roots, dirs, files in os.walk(self.dbdir):
- for i in dirs:
- [pkgname, pkgver, pkgrel] = i.rsplit("-", 2)
- if pkgname == name:
- dbentry = i
- break
- if not dbentry:
+ dbentry = None
+ if self.read_dircache is None:
+ self.read_dircache = os.listdir(self.dbdir)
+ for entry in self.read_dircache:
+ [pkgname, pkgver, pkgrel] = entry.rsplit("-", 2)
+ if pkgname == name:
+ dbentry = entry
+ break
+ if dbentry is None:
return None
- path = os.path.join(self.dbdir, dbentry)
- [pkgname, pkgver, pkgrel] = dbentry.rsplit("-", 2)
+ if pkgname in self.read_pkgcache:
+ return self.read_pkgcache[pkgname]
+
pkg = pmpkg.pmpkg(pkgname, pkgver + "-" + pkgrel)
+ self.read_pkgcache[pkgname] = pkg
+ path = os.path.join(self.dbdir, dbentry)
# desc
filename = os.path.join(path, "desc")
if not os.path.isfile(filename):