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)
| 37 | |
| 38 | |
| 39 | def 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 | |
| 65 | def collect_rpms(text): |