Search code examples
python-3.6rpmrhel

rpmUtils.miscutils in python3.6


I am refactoring code from python2(RHEL 7.6) to python3(RHEL 8.2) and I have problem with missing library in python3.6.

Problem:

from rpmUtils.miscutils import splitFilename ModuleNotFoundError: No module named 'rpmUtils'

I've tried to install python3-dnf and python3-rpm packages to RHEL8, but still not working. Is there any solution how to use this library in python3.6 and RHEL8 or should I write some custom function by myself?

Thank you for your answer.


Solution

  • This library was indeed removed, but you have several other options you can use.

    Please note that these other functions expect to receive a string in the NEVRA (name, epoch, version, release, architecture) format as an input, not a filename. Thus you must remove the '.rpm' extension of the filename, in order to get a NVRA string (epoch normally is not included in the filename of the RPM package).

    So basically you have 2 options:

    • to use dnf as suggested in i.e. https://bugzilla.redhat.com/show_bug.cgi?id=1364504

    • to use hawkey i.e. :

        import hawkey
      
        rpm_base_filename = os.path.basename(rpm_file)
        nevra = hawkey.split_nevra(rpm_base_filename[:-len(".rpm")])
        name = nevra.name
        version = nevra.version
        release = str(nevra.release)
        epoch = str(nevra.epoch)
        arch = nevra.arch
      

    For example here is a patch for such modification that I made for one of the tools we use as part of the oVirt release process:

    https://github.com/oVirt/releng-tools/commit/823405e6b261f7ff27ddbba0e8fa2b86dd2a8698