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

Function parse_rpm_xmlish

src/packagedcode/rpm_installed.py:39–62  ·  view source on GitHub ↗

Yield PackageData built from an RPM XML'ish file at ``location``. This is a file created with the rpm CLI with the xml query option.

(location, datasource_id, package_type, package_only=False)

Source from the content-addressed store, hash-verified

37
38
39def parse_rpm_xmlish(location, datasource_id, package_type, package_only=False):
40 """
41 Yield PackageData built from an RPM XML'ish file at ``location``. This is a file
42 created with the rpm CLI with the xml query option.
43 """
44 if not location or not os.path.exists(location):
45 return
46
47 # there are smetimes weird encodings. We avoid issues there
48 with open(location, 'rb') as f:
49 rpms = as_unicode(f.read())
50
51 # The XML'ish format is in fact multiple XML documents, one for each package
52 # wrapped in an <rpmHeader> root element. So we add a global root element
53 # to make this a valid XML document.
54
55 for rpm_raw_tags in collect_rpms(rpms):
56 tags = collect_tags(rpm_raw_tags)
57 yield build_package(
58 rpm_tags=tags,
59 datasource_id=datasource_id,
60 package_type=package_type,
61 package_only=package_only,
62 )
63
64
65def collect_rpms(text):

Calls 6

as_unicodeFunction · 0.90
collect_rpmsFunction · 0.85
collect_tagsFunction · 0.85
build_packageFunction · 0.70
existsMethod · 0.45
readMethod · 0.45