1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#!/usr/bin/env python3
#
# Find all software components which have a modalias in the
# AppStream database and prints them to stdout.
#
# WARNING: This is pure example code, which does no error
# checking at all!
import gi
gi.require_version('AppStream', '1.0')
from gi.repository import AppStream
import re
pool = AppStream.Pool()
pool.load()
try:
cpts = pool.get_components().as_array()
except AttributeError:
# Handle old API too (before version 1.0)
cpts = pool.get_components()
ma_cpts = list()
fwr_cpts = list()
fwf_cpts = list()
for cpt in cpts:
modalias = cpt.get_provided_for_kind(AppStream.ProvidedKind.MODALIAS)
fwruntime = cpt.get_provided_for_kind(AppStream.ProvidedKind.FIRMWARE_RUNTIME)
fwflashed = cpt.get_provided_for_kind(AppStream.ProvidedKind.FIRMWARE_FLASHED)
if modalias:
ma_cpts.append(cpt)
if fwruntime:
fwr_cpts.append(cpt)
if fwflashed:
fwf_cpts.append(cpt)
# we got all components providing modaliases
pkgaliases = {}
for cpt in ma_cpts:
for pkg in sorted(cpt.get_pkgnames()):
if pkg not in pkgaliases:
pkgaliases[pkg] = {}
aliases = pkgaliases[pkg]
prov = cpt.get_provided_for_kind(AppStream.ProvidedKind.MODALIAS)
for item in prov.get_items():
m = re.match(r'usb:v([0-9a-fA-F]{4})p([0-9a-fA-F]{4})d\*', item)
if m:
item = "usb:v%sp%sd*" % (
m.group(1).upper(), m.group(2).upper()
)
aliases[str(item)] = 1
if False:
for cpt in fwr_cpts:
for pkg in sorted(cpt.get_pkgnames()):
if pkg not in pkgaliases:
pkgaliases[pkg] = {}
aliases = pkgaliases[pkg]
prov = cpt.get_provided_for_kind(AppStream.ProvidedKind.FIRMWARE_RUNTIME)
for item in prov.get_items():
aliases["firmware:%s" % str(item)] = 1
for pkg in sorted(pkgaliases.keys()):
print("Package: %s" % pkg)
print("Modaliases: unused(%s)" % ", ".join(sorted(pkgaliases[pkg].keys())))
print()
|