Dashboard
PHP:
7.4.33
OS:
Linux
User:
sortthru
/
/
usr
/
share
/
oracle-cloud-agent
/
plugins
/
osms
/
osms
📤 Upload
📝 New File
📁 New Folder
Close
Editing: rpmutils.py
# Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. # Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.org/licenses/UPL. import os import sys import rpm sys.path.insert(0, '/usr/share/oracle-cloud-agent/plugins/osms') from osms import transaction from osms.i18n import sstr def installedHeaderByKeyword(**kwargs): """ just cause this is such a potentially useful looking method... """ _ts = transaction.initReadOnlyTransaction() mi = _ts.dbMatch() for keyword in kwargs.keys(): mi.pattern(keyword, rpm.RPMMIRE_GLOB, kwargs[keyword]) # we really shouldnt be getting multiples here, but what the heck headerList = [] for h in mi: headerList.append(h) return headerList def verify_packages(packages): """ given a list of package labels, run rpm -V on them and return a dict keyed off that data """ missing_packages = [] # data structure is keyed off package # label, with value being an array of each # line of the output from -V retlist = [] for package in packages: # we have to have at least name... # Note: we cant reliable match on epoch, so just # skip it... two packages that only diff by epoch is # way broken anyway keywords = {'name': package[0], 'version': package[1], 'release': package[2], # we left our epoch 'arch': package[4] } for key in (keywords.keys()): if (keywords[key] == None) or (keywords[key] == ""): del(keywords[key]) headers = installedHeaderByKeyword(**keywords) if len(headers) == 0: missing_packages.append(package) for header in headers: epoch = header['epoch'] if epoch == None: epoch = "" # gpg-pubkey "packages" can have an arch of None, see bz #162701 arch = header["arch"] if arch == None: arch = "" pkg = (header['name'], header['version'], header['release'], epoch, arch) # dont include arch in the label if it's a None arch, #162701 if header["arch"] == "": packageLabel = "%s-%s-%s" % (pkg[0], pkg[1], pkg[2]) else: packageLabel = "%s-%s-%s.%s" % (pkg[0], pkg[1], pkg[2], pkg[4]) verifystring = "/usr/bin/rpmverify -V %s" % packageLabel fd = os.popen(verifystring) res = fd.readlines() fd.close() reslist = [] for line in res: reslist.append(line.strip()) retlist.append([pkg, reslist]) return retlist, missing_packages def get_installed_package_list(): pkg_list = [] _ts = transaction.initReadOnlyTransaction() for h in _ts.dbMatch(): if h == None: break for h in _ts.dbMatch(): if h == None: break package = { 'name': sstr(h['name']), 'epoch': h['epoch'], 'version': sstr(h['version']), 'release': sstr(h['release']), 'installtime': h['installtime'] } if package['epoch'] == None: package['epoch'] = "" else: # convert it to string package['epoch'] = "%s" % package['epoch'] package['arch'] = h['arch'] # the arch on gpg-pubkeys is "None"... if package['arch']: package['arch'] = sstr(package['arch']) pkg_list.append(package) pkg_list.sort(key=lambda x: (x['name'], x['epoch'], x['version'], x['release'])) return pkg_list
Save
Cancel