Skip to content

Commit

Permalink
tools/clean_svg: allow passing in a .tablet file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
whot committed Oct 11, 2024
1 parent 9b87121 commit 117e3f7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions tools/clean_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#

import sys
from pathlib import Path
from argparse import ArgumentParser
from xml.etree import ElementTree as ET

Expand Down Expand Up @@ -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"
)
Expand All @@ -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))

0 comments on commit 117e3f7

Please sign in to comment.