Assorted utility functions for yum.


Take a value and use the same value from the store, if the value isn’t in the store this one becomes the shared version.


Tests if a string is a shell wildcard.


Tests if a string could be a filename. We still get negated character classes wrong (are they supported), and ranges in character classes.


Tests if a filename string, can be matched against just primary. Note that this can produce false negatives (but not false positives). Note that this is a superset of re_primary_dirname().


Tests if a dirname string, can be matched against just primary. Note that this is a subset of re_primary_filename().


Tests if a string needs a full nevra match, instead of just name.


Tests if a string is a “remote” URL, http, https, ftp.


Return a list of the elements in s, but without duplicates.

For example, unique([1,2,3,1,2,3]) is some permutation of [1,2,3], unique(“abcabc”) some permutation of [“a”, “b”, “c”], and unique(([1, 2], [2, 3], [1, 2])) some permutation of [[2, 3], [1, 2]].

For best speed, all sequence elements should be hashable. Then unique() will usually work in linear time.

If not possible, the sequence elements should enjoy a total ordering, and if list(s).sort() doesn’t raise TypeError it’s assumed that they do enjoy a total ordering. Then unique() will usually work in O(N*log2(N)) time.

If that’s not possible either, the sequence elements must support equality-testing. Then unique() will usually work in quadratic time.


class yum.misc.Checksums(checksums=None, ignore_missing=False, ignore_none=False)

Generate checksum(s), on given pieces of data. Producing the Length and the result(s) when complete.


class yum.misc.AutoFileChecksums(fo, checksums, ignore_missing=False, ignore_none=False)

Generate checksum(s), on given file/fileobject. Pretending to be a file object (overrrides read).

yum.misc.checksum(sumtype, file, CHUNK=65536, datasize=None)

takes filename, hand back Checksum of it sumtype = md5 or sha/sha1/sha256/sha512 (note sha == sha1) filename = /path/to/file CHUNK=65536 by default

yum.misc.getFileList(path, ext, filelist)

Return all files in path matching ext, store them in filelist, recurse dirs return list object


class yum.misc.GenericHolder(iter=None)

Generic Holder class used to hold other objects of known types It exists purely to be able to do object.somestuff, object.someotherstuff or object[key] and pass object to another function that will understand it


Convert ASCII armoured GPG key to binary

yum.misc.getgpgkeyinfo(rawkey, multiple=False)

Return a dict of info for the given ASCII armoured key text

Returned dict will have the following keys: ‘userid’, ‘keyid’, ‘timestamp’

Will raise ValueError if there was a problem decoding the key.


Convert an integer representing a GPG key ID to the hex version string used by RPM

yum.misc.keyInstalled(ts, keyid, timestamp)

Return if the GPG key described by the given keyid and timestamp are installed in the rpmdb.

The keyid and timestamp should both be passed as integers. The ts is an rpm transaction set object

Return values:
  • -1

    key is not installed

  • 0 key with matching ID and timestamp is installed

  • 1 key with matching ID is installed but has a older timestamp

  • 2 key with matching ID is installed but has a newer timestamp

No effort is made to handle duplicates. The first matching keyid is used to calculate the return result.

yum.misc.import_key_to_pubring(rawkey, keyid, cachedir=None, gpgdir=None, make_ro_copy=True)
yum.misc.valid_detached_sig(sig_file, signed_file, gpghome=None)

takes signature , file that was signed and an optional gpghomedir

yum.misc.getCacheDir(tmpdir='/var/tmp', reuse=True, prefix='yum-')

return a path to a valid and safe cachedir - only used when not running as root or when –tempcache is set

yum.misc.sortPkgObj(pkg1, pkg2)

sorts a list of yum package objects by name


Return the newest in the list of packages.


Convert a tuple representing a package version to a string.

@param evrTuple: A 3-tuple of epoch, version, and release.

Return the string representation of evrTuple.


returns a text string of the prco from the tuple format


returns a prco tuple (name, flags, (e, v, r)) for a string


Takes a search string from the cli for Search or Provides and cleans it up so it doesn’t make us vomit

yum.misc.bunzipFile(source, dest)

Extract the bzipped contents of source to dest.


This takes the output of uname and figures out the pkgtup of the running kernel (name, arch, epoch, version, release).


This takes the output of uname and figures out the (version, release) tuple for the running kernel.


returns a list of the timestamps from the filenames of the unfinished transactions remaining in the yumlibpath specified.

yum.misc.find_ts_remaining(timestamp, yumlibpath='/var/lib/yum')

this function takes the timestamp of the transaction to look at and the path to the yum lib dir (defaults to /var/lib/yum) returns a list of tuples(action, pkgspec) for the unfinished transaction elements. Returns an empty list if none.

yum.misc.seq_max_split(seq, max_entries)

Given a seq, split into a list of lists of length max_entries each.

yum.misc.to_xml(item, attrib=False)

Call os.unlink, but don’t die if the file isn’t there. This is the main difference between “rm -f” and plain “rm”.

yum.misc.stat_f(filename, ignore_EACCES=False)

Call os.stat(), but don’t die if the file isn’t there. Returns None.


Get the audit-uid/login-uid, if available. None is returned if there was a problem. The value is cached, so you don’t have to save it.

yum.misc.setup_locale(override_codecs=True, override_time=False)

return list of running processids, excluding this one


returns files open from this pid


create, store and return a uuid. If a stored one exists, report that if it cannot be stored, return a random one

yum.misc.decompress(filename, dest=None, fn_only=False, check_timestamps=False)

take a filename and decompress it into the same relative location. if the file is not compressed just return the file

yum.misc.repo_gen_decompress(filename, generated_name, cached=False)

This is a wrapper around decompress, where we work out a cached generated name, and use check_timestamps. filename _must_ be from a repo. and generated_name is the type of the file.

yum.misc.read_in_items_from_dot_dir(thisglob, line_as_list=True)

takes a glob of a dir (like /etc/foo.d/*.foo) returns a list of all the lines in all the files matching that glob, ignores comments and blank lines, optional paramater ‘line_as_list tells whether to treat each line as a space or comma-separated list, defaults to True


Lazily load/run: cElementTree.iterparse


Lazily load/run: cElementTree.parse

Table Of Contents

Previous topic


Next topic


This Page