version_utils.rpm module¶
rpm module for version_utils
Contains RPM parsing and comparison operations for version_utils. Public methods include:
compare_packages: compare two RPM package strings, e.g.gcc-4.4.7-16.el6.x86_64andgcc-4.4.7-17.el6.x86_64compare_versions: compare two RPM version strings (the bit between the dashes in an RPM package string)package: parse an RPM package string to get name, epoch, version, release, and architecture information. Returns as acommon.Packageobject.
-
version_utils.rpm._check_leading(*char_lists)[source]¶ Remove any non-alphanumeric or non-~ leading characters
Checks the beginning of any provided lists for non-alphanumeric or non-~ (tilde) leading characters and removes them if found. Operates on (and possibly alters) the passed list.
Parameters: char_list (list) – a list or lists of characters Returns: None Return type: None
-
version_utils.rpm._compare_blocks(block_a, block_b)[source]¶ Compare two blocks of characters
Compares two blocks of characters of the form returned by either the
_pop_digitsor_pop_lettersfunction. Blocks should be character lists containing only digits or only letters. Both blocks should contain the same character type (digits or letters).The method of comparison mirrors the method used by RPM. If the blocks are digit blocks, any leading zeros are trimmed, and whichever block is longer is assumed to be larger. If the resultant blocks are the same length, or if the blocks are non-numeric, they are checked for string equality and considered equal if the string equality comparison returns True. If not, whichever evaluates as greater than the other (again in string comparison) is assumed to be larger.
Parameters: Returns: 1 (if
ais newer), 0 (if versions are equal) or -1 (ifbis newer)Return type:
-
version_utils.rpm._get_block_result(chars_a, chars_b)[source]¶ Get the first block from two character lists and compare
If character list
abegins with a digit, the_pop_digitfunction is called on both lists to get blocks of all consecutive digits at the start of each list. If the length of the block returned when popping digits forbis zero (bstarted with a letter),ais newer. Ifbis of nonzero length, the blocks are compared using_compare_blocks.If character list
abegins with a letter, the_pop_letterfunction is called on both lists to get blocks of all consecutive letters at the start of each list. If the length of the block returned when popping letters forbis zero (bstarted with a digit),bis newer. Ifbis of nonzero length, blocksaandbare compared using_compare_blocks.Parameters: Returns: 1 (if
ais newer), 0 (if versions are equal), or -1 (ifbis newer)Return type:
-
version_utils.rpm._pop_arch(char_list)[source]¶ Pop the architecture from a version string and return it
Returns any portion of a string following the final period. In rpm version strings, this corresponds to the package architecture.
Parameters: char_list (list) – an rpm version string in character list form Returns: the parsed architecture as a string Return type: str
-
version_utils.rpm._pop_digits(char_list)[source]¶ Pop consecutive digits from the front of list and return them
Pops any and all consecutive digits from the start of the provided character list and returns them as a list of string digits. Operates on (and possibly alters) the passed list.
Parameters: char_list (list) – a list of characters Returns: a list of string digits Return type: list
-
version_utils.rpm._pop_letters(char_list)[source]¶ Pop consecutive letters from the front of a list and return them
Pops any and all consecutive letters from the start of the provided character list and returns them as a list of characters. Operates on (and possibly alters) the passed list
Parameters: char_list (list) – a list of characters Returns: a list of characters Return type: list
-
version_utils.rpm._trim_zeros(*char_lists)[source]¶ Trim any zeros from provided character lists
Checks the beginning of any provided lists for ‘0’s and removes any such leading zeros. Operates on (and possibly) alters the passed list
Parameters: char_lists (list) – a list or lists of characters Returns: None Return type: None
-
version_utils.rpm.compare_evrs(evr_a, evr_b)[source]¶ Compare two EVR tuples to determine which is newer
This method compares the epoch, version, and release of the provided package strings, assuming that epoch is 0 if not provided. Comparison is performed on the epoch, then the version, and then the release. If at any point a non-equality is found, the result is returned without any remaining comparisons being performed (e.g. if the epochs of the packages differ, the versions are releases are not compared).
Parameters:
-
version_utils.rpm.compare_packages(rpm_str_a, rpm_str_b, arch_provided=True)[source]¶ Compare two RPM strings to determine which is newer
Parses version information out of RPM package strings of the form returned by the
rpm -qcommand and compares their versions to determine which is newer. Provided strings do not require an architecture at the end, although if providing strings without architecture, thearch_providedparameter should be set to False.Note that the packages do not have to be the same package (i.e. they do not require the same name or architecture).
Parameters: Returns: 1 (
ais newer), 0 (versions are equivalent), or -1 (bis newer)Return type:
-
version_utils.rpm.compare_versions(version_a, version_b)[source]¶ Compare two RPM version strings
Compares two RPM version strings and returns an integer indicating the result of the comparison. The method of comparison mirrors that used by RPM, so results should be the same for any standard RPM package.
To perform the comparison, the strings are first checked for equality. If they are equal, the versions are equal. Otherwise, each string is converted to a character list, and a comparison loop is started using these lists.
In the comparison loop, first any non-alphanumeric, non-~ characters are trimmed from the front of the list. Then if the first character from both
aandbis a ~ (tilde), it is trimmed. The ~ (tilde) character indicates that a given package or version should be considered older (even if it is numerically larger), so ifabegins with a tilde,bis newer, and vice-versa. At this point, if the length of either list has been reduced to 0, the loop is exited. If characters remain in the list, the_get_block_resultfunction is used to pop consecutive digits or letters from the front of hte list and compare them. The result of the block comparison is returned if the blocks are not equal. The loop then begins again.If the loop exits without returning a value, the lengths of the remaining character lists are compared. If they have the same length (usually 0, since all characters have been popped), they are considered to be equal. Otherwise, whichever is longer is considered to be newer. Generally, unequal length will be due to one character list having been completely consumed while some characters remain on the other, for example when comparing 1.05b to 1.05.
Parameters: Returns: 1 (if
ais newer), 0 (if versions are equal), or -1 (ifbis newer)Return type: Raises: RpmError – if an a type is passed that cannot be converted to a list
-
version_utils.rpm.labelCompare(evr_a, evr_b)[source]¶ Convenience function to provide the same behaviour as labelCompare from rpm-python.
To be used as a drop-in replacement for labelCompare, thus the utilization of the non-standard camelCase variable name.
To use the version_utils version and fall back to rpm:
- try:
- from version_utils.rpm import labelCompare
- except ImportError:
- from rpm import labelCompare
Parameters:
-
version_utils.rpm.package(package_string, arch_included=True)[source]¶ Parse an RPM version string
Parses most (all tested) RPM version strings to get their name, epoch, version, release, and architecture information. Epoch (also called serial) is an optional component for RPM versions, and it is also optional when providing a version string to this function. RPM assumes the epoch to be 0 if it is not provided, so that behavior is mirrored here.
Parameters: Returns: A
common.Packageobject containing all parsed informationReturn type:
-
version_utils.rpm.parse_package(package_string, arch_included=True)[source]¶ Parse an RPM version string to get name, version, and arch
Splits most (all tested) RPM version strings into name, epoch, version, release, and architecture. Epoch (also called serial) is an optional component of RPM versioning and is also optional in version strings provided to this function. RPM assumes the epoch to be 0 if it is not provided, so that behavior is mirrored here.
Deprecated since version 0.2.0. Use
rpm.packageinstead.Parameters: Returns: a dictionary with all parsed package information
Return type: