MCPcopy Create free account
hub / github.com/aboutcode-org/vulnerablecode / rpm_to_purl

Function rpm_to_purl

vulnerabilities/rpm_utils.py:77–105  ·  view source on GitHub ↗
(rpm_string, namespace)

Source from the content-addressed store, hash-verified

75
76
77def rpm_to_purl(rpm_string, namespace):
78 # FIXME: there is code in scancode to handle RPM conversion AND this should
79 # be all be part of the packageurl library
80
81 # FIXME: the comment below is not correct, this is the Epoch in the RPM version and not redhat specific
82 # Red Hat uses `-:0` instead of just `-` to separate
83 # package name and version
84
85 # https://github.com/nexB/scancode-toolkit/blob/16ae20a343c5332114edac34c7b6fcf2fb6bca74/src/packagedcode/rpm.py#L310
86
87 envra = from_name(rpm_string)
88
89 if not envra:
90 logger.error(f"Invalid RPM name can't get envra: {rpm_string}")
91 return None
92 sepoch, sname, sversion, srel, sarch = envra
93
94 evr = EVR(sversion, srel, sepoch)
95 if not evr:
96 logger.error(f"Invalid RPM name can't get evr: {rpm_string}")
97 return None
98 src_evr = evr.to_string()
99 src_qualifiers = {}
100 if sarch:
101 src_qualifiers["arch"] = sarch
102
103 return PackageURL(
104 type="rpm", namespace=namespace, name=sname, version=src_evr, qualifiers=src_qualifiers
105 )

Callers 1

to_advisoryFunction · 0.90

Calls 3

to_stringMethod · 0.95
from_nameFunction · 0.85
EVRClass · 0.85

Tested by

no test coverage detected