diff options
author | Martin Pitt <martin@piware.de> | 2024-07-28 14:29:54 +0200 |
---|---|---|
committer | Martin Pitt <martin@piware.de> | 2024-07-28 14:32:17 +0200 |
commit | 46ff6de913f30ffce36b951753800c13c8a42a9c (patch) | |
tree | 3e005efbc1dfa55601a4941786a750f6aa5a14d0 | |
parent | d3ae462052d47743499532284d7025c9b41f6db7 (diff) |
Generate AppStream metainfo file
This allow isenkram to propose this package when the hardware is present.
Thanks to Petter Reinholdtsen for the idea and initial implementation!
https://bugs.debian.org/1076991
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | Makefile.am | 12 | ||||
-rwxr-xr-x | tools/mpi2appstream.py | 74 |
3 files changed, 87 insertions, 4 deletions
@@ -7,6 +7,7 @@ config.log config.status configure install-sh -media-players/*.rules -media-players/*.hwdb +*.hwdb +*.metainfo.xml +*.rules missing diff --git a/Makefile.am b/Makefile.am index fc208f0..2f49fb8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,11 +16,19 @@ nodist_udevhwdb_DATA = 20-usb-media-players.hwdb 20-usb-media-players.hwdb: $(dist_mpi_DATA) $(top_srcdir)/tools/mpi2hwdb.py $(PYTHON) $(top_srcdir)/tools/mpi2hwdb.py $(dist_mpi_DATA) > 20-usb-media-players.hwdb +org.freedesktop.media_player_info.metainfo.xml: $(top_srcdir)/tools/mpi2appstream.py + $(PYTHON) $(top_srcdir)/tools/mpi2appstream.py $(dist_mpi_DATA) > org.freedesktop.media_player_info.metainfo.xml + +metainfodir = $(datarootdir)/metainfo +nodist_metainfo_DATA = org.freedesktop.media_player_info.metainfo.xml + + clean-local: - rm -f 40-usb-media-players.rules 20-usb-media-players.hwdb + rm -f 40-usb-media-players.rules 20-usb-media-players.hwdb org.freedesktop.media_player_info.metainfo.xml EXTRA_DIST = \ tools/COPYING \ - tools/mpi2udev.py \ + tools/mpi2appstream.py \ tools/mpi2hwdb.py \ + tools/mpi2udev.py \ tools/udev-syntax-check.py diff --git a/tools/mpi2appstream.py b/tools/mpi2appstream.py new file mode 100755 index 0000000..f43eace --- /dev/null +++ b/tools/mpi2appstream.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# Generate AppStream metainfo file from music player identification (.mpi) files +# +# (C) 2024 Martin Pitt <mpitt@debian.org> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +import configparser +import sys + + +def parse_mpi(mpi: str, modaliases: set[str]): + """Collect DeviceMatches from MPI file and format as modalias""" + + cp = configparser.RawConfigParser() + assert cp.read(mpi, encoding='UTF-8') + + try: + matches = cp.get('Device', 'devicematch') + except configparser.NoOptionError: + return + + for match in matches.split(';'): + # AppStream format: usb:v1111pAAAAd* + try: + (subsystem, vid, pid) = match.split(':') + except ValueError: + continue + modaliases.add(f'usb:v{vid.upper()}p{pid.upper()}d*') + +# +# main +# + +modaliases: set[str] = set() +for f in sys.argv[1:]: + parse_mpi(f, modaliases) + +print("""<?xml version="1.0" encoding="UTF-8"?> +<component type="desktop"> + <id>org.freedesktop.media_player_info</id> + <metadata_license>MIT</metadata_license> + <name>media-player-info</name> + <summary>Media player identification files</summary> + <description> + <p>media-player-info is a repository of data files describing + media player (mostly USB Mass Storage ones) capabilities. These + files contain information about the directory layout to use to add + music to these devices, about the supported file formats, and so + on.</p> + + <p>The music player capabilities are now described in *.mpi files + (which are ini-like files), together with udev rules to identify + these devices.</p> + </description> + <url type="homepage">https://gitlab.freedesktop.org/media-player-info/media-player-info</url> + <provides>""") + +for match in sorted(modaliases): + print(f' <modalias>{match}</modalias>') + +print(""" </provides> +</component>""") |