Viewing file: up2dateBatch.py (9.51 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/python import sys import gpgUtils import up2date import up2dateErrors import up2dateAuth import up2dateUtils import packageList import config import rhnPackageInfo import wrapperUtils from rhpl.translate import _, N_
# later... # FIXME: I'm not sure where I should be plugging in all # the differences for tui batch/action batch/ etc # maybe a base class and an inherited version for # each, with wrapper.batchRun picking the best version...? # or just dig and add the approrite bits to pick based # on an attribute... might need to sleep on that a bit
class BatchRun: def __init__(self): self.cfg = config.initUp2dateConfig() self.fromDaemon = None # the packages we need to update self.availableUpdates = [] self.onlyList = None self.actionPkgs = None #? self.fullUpdate = None self.depPackages = [] self.conflicts = None self.printCallback = None self.percentCallback = None self.packagesToInstall = None # the list of packages available from the server self.availablePackages = None # the packages specified via commandline self.listOfPkgNames = [] self.listOfComps = [] self.listOfGlobs = [] self.kernelsToInstall = None self.skippedPackages = [] self.obsoletedPackages = [] self.packagesNotFound = [] self.dryRunFlag = None self.noMatchesForGlobs = 0 self.noMatchesForComps = 0
if self.cfg['useRhn']: self.__maybeUpdateVersion()
# make sure everything is kosher with gpg now gpgUtils.checkGPGSanity()
# fix bz #152523, move the package list calc to a seperate # method we can run before installing packages. This way we # can detect if we need to up2date up2date before running a transaction def init(self): if self.actionPkgs: self.addActionPkgs(self.actionPkgs) self.__findPackagesToUpdate() self.__selectPackagesToInstall()
def run(self): # might as well show this for all packages wrapperUtils.printVerboseList(self.packagesToInstall)
# maybe print out a summary of package size and whatnot? if self.onlyList: return 0
if len(self.packagesToInstall): self.__dryRun() else: return 0 if self.dryRunFlag: wrapperUtils.printVerboseList(self.packagesToInstall) return 0 self.__testForSpace() if self.cfg["noDownload"]: return 0 self.__getPackages() if self.cfg["retrieveOnly"]: return 0 self.__installPackages() if self.cfg["keepAfterInstall"]: return 0 self.__deletePackages()
def __findPackagesToUpdate(self): # if someone set the list of availablePackages
plist = packageList.PackageList() plist.addForcePackages(self.listOfPkgNames) plist.addGlobs(self.listOfGlobs) plist.addComps(self.listOfComps) plist.msgCallback = self.printCallback plist.progressCallback = self.percentCallback plist.run()
fpHash = plist.getForcedPackages() # update this to include packages added via globs and comps self.listOfPkgNames = fpHash.keys()
self.availableUpdates = plist.getPackagesToInstall() # print "self.availableUpdates: %s" % self.availableUpdates # FIXME: should this be done at __init__? # should packageList:: export this instead? self.availablePackages = rhnPackageInfo.availablePackageList() self.skippedPackages = plist.getSkippedPackages() self.applicableSkippedPackages = self.__trimSkippedPackages(self.skippedPackages, self.listOfPkgNames) self.obsoletedPackages = plist.getObsoletedPackages() self.installedObsoletingPackages = plist.getInstalledObsoletingPackages() self.noMatchesForGlobs = plist.noMatchesForGlobs self.noMatchesForComps = plist.noMatchesForComps
def __trimSkippedPackages(self, skippedPackages, listOfPkgNames): if not listOfPkgNames and not self.listOfGlobs: return skippedPackages applicableSkippedPackages = [] #skippedNames = map(lambda a: a[0], self.skippedPackages) for skippedPkg in skippedPackages: if skippedPkg[0][0] in listOfPkgNames: applicableSkippedPackages.append(skippedPkg) return applicableSkippedPackages
def __selectPackagesToInstall(self): selPackages = []
# need to know of packagelist didnt match any comps if self.listOfPkgNames: for pkg in self.availableUpdates: if pkg[0] in self.listOfPkgNames: selPackages.append(pkg) # account for the case of a comp or glob being specified, but nothing found elif (self.listOfComps != []) and (self.listOfGlobs != []): for pkg in self.availableUpdates: selPackages.append(pkg) else: selPackages = self.availableUpdates
self.packagesToInstall = selPackages names = map(lambda a: a[0], self.availablePackages) for pkgname in self.listOfPkgNames: if pkgname not in names: self.packagesNotFound.append(pkgname)
def __dryRun(self): # let all the exceptions bubble up #print "DEBUG:BatchRun.__dryRun: self.packagesToInstall: %s" % self.packagesToInstall (self.depPackages, self.packagesToInstall) = up2date.dryRun(self.packagesToInstall, self.printCallback, self.percentCallback)
def __getPackages(self): for pkg in self.packagesToInstall: # FIXME, should be getting these callbacks from somwhere else up2date.getPackage(pkg, wrapperUtils.printPkg, wrapperUtils.printRetrieveHash) self.__checkPackage( pkg)
def __installPackages(self): self.kernelsToInstall = [] # FIXME self.rpmCallback? self.kernelsToInstall = up2date.installPackages(self.packagesToInstall, self.rpmCallback)
def __deletePackages(self): for pkg in self.packagesToInstall: up2date.removePackage(pkg)
def totalSize(self): _totalSize = 0 for pkg in self.packagesToInstall: # We ignore already downloaded packages, since they # count against available diskspace if not up2date.isPackageCached(pkg): _totalSize = _totalSize + int(pkg[5]) return _totalSize
def __testForSpace(self): ts = self.totalSize() fds = up2dateUtils.freeDiskSpace() #print "ts: %s" % ts #print "fds: %s" % fds if ts > fds: raise up2dateErrors.OutOfSpaceError(ts/1024, fds/1024)
def addActionPkgs(self, actionPkgs): remotePackages = rhnPackageInfo.availablePackageList()
updList = []
# FIXME: this could probabaly use some optimization # should probably iterate over remotePackageNames once # using a counter, and use that to index into remotePackages for pkg in actionPkgs: # for tmppkg in filter(lambda a,b=pkg: a[0]==b[0], remotePackages): updList.append(tmppkg[0])
if len(updList): for pkg in updList: self.listOfPkgNames.append(pkg)
def __checkPackage(self, pkg): # FIXME: cleanup the error handling somehow # do signature checking only if GPG installation checks out, # and GPG checking is enabled.
# FIXME: need to make sure that everything is valid in GPG land # before we do this, maybe a up2date.checkGPGSanity() that gets called # from BatchRun.init() ? if self.cfg["useGPG"]: try: res = up2date.hasBadSignature(pkg) except up2dateErrors.RpmError, e: print e sys.exit(1) if res == 1: print _("The package %s is not signed with a GPG signature. Aborting...") % up2dateUtils.pkgToString(pkg) raise up2dateErrors.GPGVerificationUnsignedPackageError("%s" % up2dateUtils.pkgToString(pkg)) if res == 2: print _("The package %s does not have a valid GPG signature.\nIt has been tampered with or corrupted. Aborting...") % up2dateUtils.pkgToString(pkg) raise up2dateErrors.GPGVerificationError("%s" % up2dateUtils.pkgToString(pkg)) if res == 3: print _("The package %s is signed with a untrusted GPG signature. Aborting...") % up2dateUtils.pkgToString(pkg) raise up2dateErrors.GPGVerificationUntrustedKeyError("%s" % up2dateUtils.pkgToString(pkg)) if res == 4: print _("The package %s is signed, but with an unknown GPG key. Aborting...") % up2dateUtils.pkgToString(pkg) raise up2dateErrors.GPGVerificationUnknownKeyError("%s" % up2dateUtils.pkgToString(pkg))
def __maybeUpdateVersion(self): try: up2dateAuth.maybeUpdateVersion() except up2dateErrors.RpmError, e: print _("There was a fatal RPM error. The message was:\n") + e.errmsg return 1 except up2dateErrors.CommunicationError, e: print _("There was a fatal error communicating with the server. The message was:\n") + e.errmsg return 1
|