From 117e3f7c15cc60fbdcf5a7651d99f539c5afd255 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 11 Oct 2024 10:59:31 +1000 Subject: [PATCH] tools/clean_svg: allow passing in a .tablet file If the svg file passed in is a .tablet file, extract the layout and tablet name from there. This allows us to run the tool on the existing tablet files to check for any differences. Add this into the CI so we ensure that script doesn't crash on our SVG files. --- .github/workflows/main.yml | 17 +++++++++++++++++ tools/clean_svg.py | 23 +++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3cee415a..d287eea4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -194,6 +194,23 @@ jobs: test $(libwacom-list-devices --format=yaml | yq -r '.devices[] | select(.bus == "usb") | select(.vid == "0x056a") | select(.pid == "0x0358") | .name' | wc -l) -eq 1 test $(libwacom-list-devices --format=yaml | yq -r '.devices[] | select(.bus == "usb") | select(.vid == "0x056a") | select(.pid == "0x032a") | .name' | wc -l) -eq 1 + #### + # make sure clean_svg.py works on our layout files + clean-svg-check: + needs: build-and-dist + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + # install python so we get pip for meson + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: run clean-svg on all .tablet files + run: | + for tabletfile in data/*.tablet; do + ./tools/clean_svg.py --ignore-missing "$tabletfile" "" + done + ### # # tarball verification diff --git a/tools/clean_svg.py b/tools/clean_svg.py index a5558058..b84a48ec 100755 --- a/tools/clean_svg.py +++ b/tools/clean_svg.py @@ -19,6 +19,7 @@ # import sys +from pathlib import Path from argparse import ArgumentParser from xml.etree import ElementTree as ET @@ -301,6 +302,9 @@ def clean_svg(root, tabletname): if __name__ == "__main__": parser = ArgumentParser(description="Clean SVG files for libwacom") + parser.add_argument( + "--ignore-missing", action="store_true", default=False, help="Ignore .tablet files without a Layout" + ) parser.add_argument( "filename", type=str, help="SVG file to clean", metavar="FILE" ) @@ -312,12 +316,27 @@ def clean_svg(root, tabletname): ) args = parser.parse_args() + svgfile = args.filename + tabletname = args.tabletname + if args.filename.endswith(".tablet"): + import configparser + config = configparser.ConfigParser() + config.read(args.filename) + try: + svgname = config["Device"]["Layout"] + except KeyError: + print(f"{args.filename} does not specify a layout, skipping", file=sys.stderr) + sys.exit(0 if args.ignore_missing else 77) + svgfile = Path(args.filename).parent / "layouts" / svgname + tabletname = config["Device"]["Name"] + + ET.register_namespace("", NAMESPACE) try: - tree = ET.parse(args.filename) + tree = ET.parse(svgfile) except Exception as e: sys.stderr.write(str(e) + "\n") sys.exit(1) root = tree.getroot() - clean_svg(root, args.tabletname) + clean_svg(root, tabletname) print(to_string(root))