#87 Utility to obtain N from N(E)VR
Opened 2 years ago by vondruch. Modified 2 years ago

It would be handy, if there was tool which could extract name from full NEVR. E.g. if there is some-package-1.0.0-1.fc35.noarch.rpm, this tool would return the some-package string


Just FTR, I was looking for such tool and I could find just this:

https://serverfault.com/questions/557350/parse-an-rpm-name-into-its-components

Apparently, there used to be from rpmUtils.miscutils import splitFilename in YUM, but this is not present in DNF:

https://github.com/rpm-software-management/dnf/commit/648c961ce145ede20c482ccd5d948cc665a340c1

I've implemented a NEVRA parser in different forms for various projects already ...

Would you like this to be an importable python module or a CLI program?

I've implemented a NEVRA parser in different forms for various projects already ...

And there is already one in rpmdevtools AFAIK:

https://pagure.io/rpmdevtools/blob/main/f/rpmdev-sort#_44

Would you like this to be an importable python module or a CLI program?

I am not Python user, so I had CLI on my mind. But I guess if it worked as Python module, others would not object.

Yeah. It would be nice to have a canonical implementation of this in a shared python module ... we could start putting other "utility" functions there too. Adding a small CLI wrapper that calls this function amounts to 5 lines of code so that's not a problem, I think :)

I am still surprised I was not able to find something like this in RPM itself. Not sure if I should not ask RPM upstream.

@pmatilai is there by a chance some functionality in RPM which could be used here? Thx a lot

I'm afraid not. Rpm has an API to parse EVR into components, but name is not part of that. OTOH, getting the name out of NEVR is simple:

>>> nevr = 'foo-bar-1.2-3'
>>> '-'.join(nevr.split('-')[:-2])
'foo-bar'

It's the version that is more complicated, and when you add arch and allow for arbitrary missing components...

Login to comment on this ticket.

Metadata