Hi all: In a nutshell, the attached patch moves most of the logic from localinstall in cli.py to yum/__init__.py's YumBase. I changed the name to not have it be confused with the old method, and made it take only one path at a time, or optionally the already instantiated package object (like the install/update/erase methods).
This should be useful for any applications that have thus far been carrying their own copy of the localinstall code. -James
From 0e218eb0d1233c961ebbd9b3c24d8c688f2c11c1 Mon Sep 17 00:00:00 2001
From: James Bowes <[EMAIL PROTECTED]>
Date: Tue, 18 Dec 2007 18:21:56 -0500
Subject: [PATCH] Add a method for installing local packages onto YumBase
This is just the method from cli.py, only taking one path at a time, and
optionally a package object instead of a path.
---
cli.py | 94 +++++--------------------------------------------------
yum/__init__.py | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 98 insertions(+), 86 deletions(-)
diff --git a/cli.py b/cli.py
index 36214d2..07d14f7 100644
--- a/cli.py
+++ b/cli.py
@@ -711,98 +711,20 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
# append it to self.localPackages
# check if it can be installed or updated based on nevra versus rpmdb
# don't import the repos until we absolutely need them for depsolving
-
- oldcount = len(self.tsInfo)
-
+
if len(filelist) == 0:
return 0, ['No Packages Provided']
-
- installpkgs = []
- updatepkgs = []
- donothingpkgs = []
-
- for pkg in filelist:
- try:
- po = YumLocalPackage(ts=self.rpmdb.readOnlyTS(), filename=pkg)
- except yum.Errors.MiscError:
- self.logger.critical('Cannot open file: %s. Skipping.', pkg)
- continue
- self.verbose_logger.log(yum.logginglevels.INFO_2,
- 'Examining %s: %s', po.localpath, po)
-
- # everything installed that matches the name
- installedByKey = self.rpmdb.searchNevra(name=po.name)
- # go through each package
- if len(installedByKey) == 0: # nothing installed by that name
- if updateonly:
- self.logger.warning('Package %s not installed, cannot
update it. Run yum install to install it instead.', po.name)
- else:
- installpkgs.append(po)
- continue
-
- for installed_pkg in installedByKey:
- if po.EVR > installed_pkg.EVR: # we're newer - this is an
update, pass to them
- if installed_pkg.name in self.conf.exactarchlist:
- if po.arch == installed_pkg.arch:
- updatepkgs.append((po, installed_pkg))
- continue
- else:
- donothingpkgs.append(po)
- continue
- else:
- updatepkgs.append((po, installed_pkg))
- continue
- elif po.EVR == installed_pkg.EVR:
- if po.arch != installed_pkg.arch and
(isMultiLibArch(po.arch) or
- isMultiLibArch(installed_pkg.arch)):
- installpkgs.append(po)
- continue
- else:
- donothingpkgs.append(po)
- continue
- else:
- donothingpkgs.append(po)
- continue
- # handle excludes for a localinstall
- toexc = []
- if len(self.conf.exclude) > 0:
- exactmatch, matched, unmatched = \
- parsePackages(installpkgs + map(lambda x: x[0], updatepkgs),
- self.conf.exclude, casematch=1)
- toexc = exactmatch + matched
-
- for po in installpkgs:
- if po in toexc:
- self.verbose_logger.debug('Excluding %s', po)
- continue
-
- self.verbose_logger.log(yum.logginglevels.INFO_2,
- 'Marking %s to be installed', po.localpath)
- self.localPackages.append(po)
- self.install(po=po)
-
- for (po, oldpo) in updatepkgs:
- if po in toexc:
- self.verbose_logger.debug('Excluding %s', po)
- continue
-
- self.verbose_logger.log(yum.logginglevels.INFO_2,
- 'Marking %s as an update to %s', po.localpath, oldpo)
- self.localPackages.append(po)
- self.tsInfo.addUpdate(po, oldpo)
-
- for po in donothingpkgs:
- self.verbose_logger.log(yum.logginglevels.INFO_2,
- '%s: does not update installed package.', po.localpath)
+ installing = False
+ for pkg in filelist:
+ txmbrs = self.installLocal(pkg, updateonly)
+ if txmbrs:
+ installing = True
- if len(self.tsInfo) > oldcount:
+ if installing:
return 2, ['Package(s) to install']
return 0, ['Nothing to do']
-
-
-
-
+
def returnPkgLists(self, extcmds):
"""Returns packages lists based on arguments on the cli.returns a
GenericHolder instance with the following lists defined:
diff --git a/yum/__init__.py b/yum/__init__.py
index 1f97f66..8ff038d 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -2212,6 +2212,96 @@ class YumBase(depsolve.Depsolve):
return tx_return
+ def installLocal(self, pkg, po=None, updateonly=False):
+ """
+ handles installs/updates of rpms provided on the filesystem in a
+ local dir (ie: not from a repo)
+
+ Return the added transaction members.
+
+ @param pkg: a path to an rpm file on disk.
+ @param po: A YumLocalPackage
+ @param updateonly: Whether or not true installs are valid.
+ """
+
+ # read in the package into a YumLocalPackage Object
+ # append it to self.localPackages
+ # check if it can be installed or updated based on nevra versus rpmdb
+ # don't import the repos until we absolutely need them for depsolving
+
+ tx_return = []
+ installpkgs = []
+ updatepkgs = []
+ donothingpkgs = []
+
+ if not po:
+ try:
+ po = YumLocalPackage(ts=self.rpmdb.readOnlyTS(), filename=pkg)
+ except yum.Errors.MiscError:
+ self.logger.critical('Cannot open file: %s. Skipping.', pkg)
+ return tx_return
+ self.verbose_logger.log(logginglevels.INFO_2,
+ 'Examining %s: %s', po.localpath, po)
+
+ # everything installed that matches the name
+ installedByKey = self.rpmdb.searchNevra(name=po.name)
+ # go through each package
+ if len(installedByKey) == 0: # nothing installed by that name
+ if updateonly:
+ self.logger.warning('Package %s not installed, cannot update
it. Run yum install to install it instead.', po.name)
+ return tx_return
+ else:
+ installpkgs.append(po)
+
+ for installed_pkg in installedByKey:
+ if po.EVR > installed_pkg.EVR: # we're newer - this is an update,
pass to them
+ if installed_pkg.name in self.conf.exactarchlist:
+ if po.arch == installed_pkg.arch:
+ updatepkgs.append((po, installed_pkg))
+ else:
+ donothingpkgs.append(po)
+ else:
+ updatepkgs.append((po, installed_pkg))
+ elif po.EVR == installed_pkg.EVR:
+ if po.arch != installed_pkg.arch and (isMultiLibArch(po.arch)
or
+ isMultiLibArch(installed_pkg.arch)):
+ installpkgs.append(po)
+ else:
+ donothingpkgs.append(po)
+ else:
+ donothingpkgs.append(po)
+
+ # handle excludes for a localinstall
+ toexc = []
+ if len(self.conf.exclude) > 0:
+ exactmatch, matched, unmatched = \
+ parsePackages(installpkgs + map(lambda x: x[0], updatepkgs),
+ self.conf.exclude, casematch=1)
+ toexc = exactmatch + matched
+
+ if po in toexc:
+ self.verbose_logger.debug('Excluding %s', po)
+ return tx_return
+
+ for po in installpkgs:
+ self.verbose_logger.log(logginglevels.INFO_2,
+ 'Marking %s to be installed', po.localpath)
+ self.localPackages.append(po)
+ tx_return.extend(self.install(po=po))
+
+ for (po, oldpo) in updatepkgs:
+ self.verbose_logger.log(logginglevels.INFO_2,
+ 'Marking %s as an update to %s', po.localpath, oldpo)
+ self.localPackages.append(po)
+ self.tsInfo.addUpdate(po, oldpo)
+ tx_return.append(txmbr)
+
+ for po in donothingpkgs:
+ self.verbose_logger.log(logginglevels.INFO_2,
+ '%s: does not update installed package.', po.localpath)
+
+ return tx_return
+
def _nevra_kwarg_parse(self, kwargs):
returndict = {}
--
1.5.4.rc0.1155.g12ed9
pgp6Zw4iJRwpd.pgp
Description: PGP signature
_______________________________________________ Yum-devel mailing list [email protected] https://lists.dulug.duke.edu/mailman/listinfo/yum-devel
