### Installing version_utils Python Package Source: https://github.com/mplanchard/version_utils/blob/development/README.rst This snippet demonstrates the simple installation process for the `version_utils` library using pip. Since it has no external dependencies, a direct pip install command is sufficient to add it to your Python environment. ```Shell pip install version_utils ``` -------------------------------- ### Comparing RPM Package Versions in Python Source: https://github.com/mplanchard/version_utils/blob/development/README.rst This example illustrates how to compare a required package version against an installed system package version using `version_utils.rpm`. It first retrieves the installed package string using `subprocess`, then parses it to extract version information, and finally uses `rpm.compare_versions` to determine if the system package meets the requirement. ```Python from subprocess import PIPE, Popen from version_utils import rpm pkg_req = 1.07 # Get a package string for an installed package out, err = Popen(['rpm', '-q', 'foo'], stdout=PIPE, stderr=PIPE).communicate() sys_pkg_str = out # Get package information sys_package = rpm.package(sys_pkg_str) sys_pkg_name = sys_package.name sys_pkg_version = sys_package.version # Compare versions result = rpm.compare_versions(pkg_req, sys_pkg_version) if result < 0: # sys_pkg was newer print('System package {0} does not satisfy\n requirement!'.format(sys_pkg_name)) ``` -------------------------------- ### Extracting RPM Package Information with Python's Package Class Source: https://github.com/mplanchard/version_utils/blob/development/README.rst This example demonstrates how to use the `rpm.package()` factory function to create a `Package` object from an RPM package string. The `Package` object provides convenient attributes like `info`, `package`, `evr`, `name`, `epoch`, `version`, `release`, and `arch` to access parsed package details. ```Python from version_utils import rpm pkg_str = 'pkgconfig-0.23-9.1.el6.x86_64' pkg = rpm.package(pkg_str) # Get package name, epoch, version, release, and architecture as a tuple print(pkg.info) # Access the package string that was parsed to make the Package object print(pkg.package) # Access the epoch, version, and release information as a tuple print(pkg.evr) # Access name, epoch, version, release, and architecture independently print('Name: {0}, Epoch: {1}, Version: {2}, Release: {3}, Arch:\n {4}'.format(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch)) ``` -------------------------------- ### Directly Comparing RPM Package Strings in Python Source: https://github.com/mplanchard/version_utils/blob/development/README.rst This snippet demonstrates the `rpm.compare_packages` function, which allows direct comparison of two full RPM package strings. It uses the same logic as the package manager to determine which package is newer, returning a positive value if the first package is newer, negative if the second is newer, and zero if they are equivalent. ```Python from version_utils import rpm sys_pkg = 'perl-Compress-Raw-Zlib-2.021-136.el6_6.1.x86_64' repo_pkg = 'perl-Compress-Raw-Zlib-2.021-138.el6_6.1.x86_64' result = rpm.compare_packages(repo_pkg, sys_pkg) if result > 0: # repo_pkg is newer print('Repo package is newer') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.