Hi!
While creating the new test frame work I came across several minor issues.
One problem is the existence of the RPMDBPackageSack.installed() method. It
is currently only supported by the RPMDBPackageSack class. This doesn't
allow to replace the rpmdb with an inmemory PackageSack. Seth already
rejected the idea of just moving the method to the base class as "installed"
doesn't make any sense for non RpmDB sacks.
As I really dislike inconsistent APIs I'd like to suggest to just remove the
usage of that method from the code. There are just 7 places in yum and one
place in yum-utils where it is used and it is nothing more than a tiny
convenience wrapper. In fact it can be replaced quite easily by
.searchNevra() - one of our work horse methods. The attached patches remove
the usage of the method and add an deprecation warning (feel free to ignore
that if we want to keep the method).
Florian
PS: The patch also fixes a small issue when running without repositories
which simplifies setting up the test cases.
>From 2b277ba1315f55806051b1157500079e4296c316 Mon Sep 17 00:00:00 2001
From: Florian Festi <[EMAIL PROTECTED]>
Date: Thu, 27 Sep 2007 10:28:59 +0200
Subject: [PATCH] remove usage of rpmdb.installed()
minor fix in costExcludePackages() for testcases that don't setup repositories
---
cli.py | 4 ++--
yum/__init__.py | 5 ++---
yum/depsolve.py | 12 ++++++------
3 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/cli.py b/cli.py
index 07a93c5..016c74b 100644
--- a/cli.py
+++ b/cli.py
@@ -498,7 +498,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
# we look through each returned possibility and rule out the
# ones that we obviously can't use
for pkg in installable:
- if self.rpmdb.installed(po=pkg):
+ if self.rpmdb.searchNevra(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch):
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Package %s is already installed.', pkg)
continue
@@ -1053,7 +1053,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
# we look through each returned possibility and rule out the
# ones that we obviously can't use
- if self.rpmdb.installed(po=pkg):
+ if self.rpmdb.searchNevra(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch):
self.verbose_logger.log(yum.logginglevels.DEBUG_3,
'Package %s is already installed, skipping', pkg)
return False
diff --git a/yum/__init__.py b/yum/__init__.py
index eeeb51e..0ca8c6a 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -610,7 +610,7 @@ class YumBase(depsolve.Depsolve):
for r in self.repos.listEnabled():
costs[r.cost] = 1
- if len(costs.keys()) == 1: # if all of our costs are the same then return
+ if len(costs.keys()) <= 1: # if all of our costs are the same then return
return
def _sort_by_cost(a, b):
@@ -1926,8 +1926,7 @@ class YumBase(depsolve.Depsolve):
continue
# make sure it's not already installed
- if self.rpmdb.installed(name=po.name, arch=po.arch, epoch=po.epoch,
- rel=po.release, ver=po.version):
+ if self.rpmdb.searchNevra(po.name, po.epoch, po.version, po.release, po.arch):
self.logger.warning('Package %s already installed and latest version', po)
continue
diff --git a/yum/depsolve.py b/yum/depsolve.py
index 4075116..1e0f681 100644
--- a/yum/depsolve.py
+++ b/yum/depsolve.py
@@ -276,7 +276,7 @@ class Depsolve(object):
cheater_tup = self.cheaterlookup[(needname, needflags, needversion)]
providers = [cheater_tup]
- elif self.rpmdb.installed(name=needname):
+ elif self.rpmdb.searchNevra(name=needname):
txmbrs = self.tsInfo.matchNaevr(name=needname)
for txmbr in txmbrs:
providers.append(txmbr.pkgtup)
@@ -303,8 +303,8 @@ class Depsolve(object):
if thismode is not None:
needmode = thismode
- if self.rpmdb.installed(name=i_n, arch=i_a, ver=i_v,
- epoch=i_e, rel=i_r):
+ if self.rpmdb.searchNevra(name=i_n, arch=i_a, ver=i_v,
+ epoch=i_e, rel=i_r):
needpo = self.rpmdb.searchPkgTuple(insttuple)[0]
else:
needpo = self.getPackageObject(insttuple)
@@ -531,7 +531,7 @@ class Depsolve(object):
best = newest[0]
- if self.rpmdb.installed(po=best): # is it already installed?
+ if self.rpmdb.searchNevra(po.name, po.epoch, po.version, po.release, po.arch): # is it already installed?
missingdep = 1
checkdeps = 0
msg = 'Missing Dependency: %s is needed by package %s' % (needname, name)
@@ -949,10 +949,10 @@ class Depsolve(object):
def isPackageInstalled(self, pkgname):
installed = False
- if self.rpmdb.installed(name = pkgname):
+ if self.rpmdb.searchNevra(name=pkgname):
installed = True
- lst = self.tsInfo.matchNaevr(name = pkgname)
+ lst = self.tsInfo.matchNaevr(name=pkgname)
for txmbr in lst:
if txmbr.output_state in TS_INSTALL_STATES:
return True
--
1.5.2.4
>From ee9a60cb2400367afe2963b5ebaf5930aeea37ba Mon Sep 17 00:00:00 2001
From: Florian Festi <[EMAIL PROTECTED]>
Date: Thu, 27 Sep 2007 10:40:26 +0200
Subject: [PATCH] Deprecate RPMDBPackageSack.installed()
---
yum/rpmsack.py | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/yum/rpmsack.py b/yum/rpmsack.py
index fb11b50..1b471b9 100644
--- a/yum/rpmsack.py
+++ b/yum/rpmsack.py
@@ -158,6 +158,9 @@ class RPMDBPackageSack(PackageSackBase):
return self.pkglist
def installed(self, name=None, arch=None, epoch=None, ver=None, rel=None, po=None):
+ warnings.warn('RPMDBPackageSack.installed() will go away in a future version of Yum.\n'
+ 'Use searchNevra instead.\n',
+ Errors.YumFutureDeprecationWarning, stacklevel=2)
if po:
name = po.name
arch = po.arch
--
1.5.2.4
>From b5827b3e1c241fa051add8d296fbad96c080334e Mon Sep 17 00:00:00 2001
From: Florian Festi <[EMAIL PROTECTED]>
Date: Thu, 27 Sep 2007 13:28:35 +0200
Subject: [PATCH] fix copy and paste error
---
yum/depsolve.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/yum/depsolve.py b/yum/depsolve.py
index 1e0f681..743761b 100644
--- a/yum/depsolve.py
+++ b/yum/depsolve.py
@@ -531,7 +531,7 @@ class Depsolve(object):
best = newest[0]
- if self.rpmdb.searchNevra(po.name, po.epoch, po.version, po.release, po.arch): # is it already installed?
+ if self.rpmdb.searchNevra(best.name, best.epoch, best.version, best.release, best.arch): # is it already installed?
missingdep = 1
checkdeps = 0
msg = 'Missing Dependency: %s is needed by package %s' % (needname, name)
--
1.5.2.4
>From 0e7917b1452cba00fbe2fc4fc60a176c9315cbc1 Mon Sep 17 00:00:00 2001
From: Florian Festi <[EMAIL PROTECTED]>
Date: Thu, 27 Sep 2007 10:42:38 +0200
Subject: [PATCH] remove usage of RPMDBPackageSack.installed()
---
yum-builddep.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/yum-builddep.py b/yum-builddep.py
index 6a06f2c..5b6a363 100755
--- a/yum-builddep.py
+++ b/yum-builddep.py
@@ -84,7 +84,7 @@ def main():
if dep.startswith("rpmlib("): continue
try:
pkg = base.returnPackageByDep(dep)
- if not base.rpmdb.installed(name=pkg.name):
+ if not base.rpmdb.searchNevra(name=pkg.name):
base.tsInfo.addInstall(pkg)
except yum.Errors.YumBaseError, e:
logger.error("Error: %s" % e)
--
1.5.2.4
_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel