MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / build_package

Function build_package

src/packagedcode/rpm_installed.py:137–167  ·  view source on GitHub ↗

Return a PackageData object from an ``rpm_tags`` iterable of (name, value_type, value) tuples.

(rpm_tags, datasource_id, package_type, package_namespace=None, package_only=False)

Source from the content-addressed store, hash-verified

135
136
137def build_package(rpm_tags, datasource_id, package_type, package_namespace=None, package_only=False):
138 """
139 Return a PackageData object from an ``rpm_tags`` iterable of (name,
140 value_type, value) tuples.
141 """
142
143 # mapping of real Package field name -> value converted to expected format
144 converted = {
145 'datasource_id': datasource_id,
146 'type': package_type,
147 'namespace': package_namespace
148 }
149
150 for name, _value_type, value in rpm_tags:
151 handler = RPM_TAG_HANDLER_BY_NAME.get(name)
152 # FIXME: we need to handle EVRA correctly
153 # TODO: add more fields
154 # TODO: merge with tag handling in rpm.py
155 if handler:
156 try:
157 handled = handler(value, **converted)
158 except Exception as e:
159 raise Exception(value, converted) from e
160 converted.update(handled)
161
162 current_filerefs = converted.get("current_filerefs", None)
163 if current_filerefs:
164 converted.pop("current_filerefs")
165
166 package_data = models.PackageData.from_data(converted, package_only)
167 return package_data
168
169################################################################################
170# Each handler function accepts a value and returns a {name: value} mapping

Callers 1

parse_rpm_xmlishFunction · 0.70

Calls 5

from_dataMethod · 0.80
handlerFunction · 0.70
getMethod · 0.65
updateMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected