[yum-cvs] 2 commits - cli.py yum/__init__.py
James Bowes
jbowes at linux.duke.edu
Wed Dec 19 15:37:50 UTC 2007
cli.py | 94 ++++----------------------------------------------------
yum/__init__.py | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 98 insertions(+), 86 deletions(-)
New commits:
commit 54ebb47b90934ced67b2828d94190de076f02731
Merge: 2686d3a... 0e218eb...
Author: James Bowes <jbowes at redhat.com>
Date: Wed Dec 19 10:36:56 2007 -0500
Merge branch 'localinstall'
commit 0e218eb0d1233c961ebbd9b3c24d8c688f2c11c1
Author: James Bowes <jbowes at redhat.com>
Date: Tue Dec 18 18:21:56 2007 -0500
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.
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 = {}
More information about the Yum-cvs-commits
mailing list