#! /usr/bin/python -tt # Copyright 2007 Red Hat # Author: James Antill import os import sys import yum from yum.update_md import UpdateMetadata def current_updates(): y = yum.YumBase() y.localPackages = [] y.updates = [] y.doConfigSetup(init_plugins=False) return y.doPackageLists('updates') ygh = current_updates() sec_only = False if len(sys.argv) == 2: if sys.argv[1] == "security": sec_only = True needsReboot = False repos = [] if sec_only: upmd = UpdateMetadata() for i in ygh.updates: if i.repo not in repos: repos.append(i.repo) for r in repos: try: # attempt to grab the updateinfo.xml.gz from the repodata upmd.add(r) except yum.Errors.RepoMDError: pass # No metadata found for this repo # Walk our list of updates trying to do them one at a time my_updates = ygh.updates[:] pkg = None while my_updates: if pkg in ygh.updates: print >>sys.stderr, " Error: Failed to update:", pkg pkg = my_updates.pop(0) if pkg not in ygh.updates: pkg = None continue md = True if sec_only: md = upmd.get_notice((pkg.name, pkg.ver, pkg.rel)) if md: if sec_only: md = md.get_metadata() if md['type'] != 'security': pkg = None continue print "Updating:", pkg os.system("yum update -d 0 -y %s" % pkg.name) ygh = current_updates()