Skip to content

Instantly share code, notes, and snippets.

@ab5w
Created July 17, 2020 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ab5w/51918a9314237cf9d2a990c6a9fa7ab4 to your computer and use it in GitHub Desktop.
Save ab5w/51918a9314237cf9d2a990c6a9fa7ab4 to your computer and use it in GitHub Desktop.
Modified yumhelper for centos8
# Python helper script to query for the packages that have
# pending updates. Called by the yum package provider
#
# (C) 2007 Red Hat Inc.
# David Lutterkort <dlutter @redhat.com>
#
# cparker modified to work with python 3 on centos 8
import sys
import string
import re
# this maintains compatibility with really old platforms with python 1.x
from os import popen, WEXITSTATUS
# Try to use the yum libraries by default, but shell out to the yum executable
# if they are not present (i.e. yum <= 2.0). This is only required for RHEL3
# and earlier that do not support later versions of Yum. Once RHEL3 is EOL,
# shell_out() and related code can be removed.
###
# (Interestingly, the shell_out stuff is what makes it work with RHEL8)
OVERRIDE_OPTS = {
'debuglevel': 0,
'errorlevel': 0,
'logfile': '/dev/null'
}
enable = []
disable = []
args = list(sys.argv)
while len(args) > 0:
a = args.pop(0)
if a == "-d":
next = args.pop(0)
disable.extend( next.split(",") )
if a == "-e":
next = args.pop(0)
enable.extend( next.split(",") )
def shell_out():
try:
repostring = ""
if disable:
repostring += " '--disablerepo=%s'" % ",".join(disable)
if enable:
repostring += " '--disablerepo=%s'" % ",".join(enable)
p = popen("/usr/bin/env yum%s check-update 2>&1" % repostring)
output = p.readlines()
rc = p.close()
if rc is not None:
# None represents exit code of 0, otherwise the exit code is in the
# format returned by wait(). Exit code of 100 from yum represents
# updates available.
if WEXITSTATUS(rc) != 100:
return WEXITSTATUS(rc)
else:
# Exit code is None (0), no updates waiting so don't both parsing output
return 0
# Yum prints a line of hyphens (old versions) or a blank line between
# headers and package data, so skip everything before them
skipheaders = 0
for line in output:
if not skipheaders:
if re.compile("^((-){80}|)$").search(line):
skipheaders = 1
continue
# Skip any blank lines
if re.compile("^[ \t]*$").search(line):
continue
#ignore everything after Obsoleting
if re.compile("^Obsoleting").search(line):
return 0
# Format is:
# Yum 1.x: name arch (epoch:)?version
# Yum 2.0: name arch (epoch:)?version repo
# epoch is optional if 0
p = str.split(line)
na = p[0]
pevr = p[1]
p = str.split(na,'.')
pname = p[0]
parch = p[1]
# Separate out epoch:version-release
evr_re = re.compile("^(\d:)?(\S+)-(\S+)$")
evr = evr_re.match(pevr)
pepoch = ""
if evr.group(1) is None:
pepoch = "0"
else:
pepoch = evr.group(1).replace(":", "")
pversion = evr.group(2)
prelease = evr.group(3)
print("_pkg", pname, pepoch, pversion, prelease, parch)
return 0
except:
print (sys.exc_info()[0])
return 1
rc = shell_out()
sys.exit(rc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment