From a955dca3d5524f4e3a48c543753533743398c7a1 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 15 Apr 2021 11:07:33 +1000 Subject: test: print the compiled keymaps to a given directory With --keymap-output-dir, the given directory will contain a list of files named after the layout + variant ('us', 'us(euro)', ...) that contain the keymaps for each variant + option combination compiled. This is still a lot, but better to sift through hundreds of keymaps than tens of thousands. Signed-off-by: Peter Hutterer --- test/xkeyboard-config-test.py.in | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/xkeyboard-config-test.py.in b/test/xkeyboard-config-test.py.in index cc53da4..222f8c5 100755 --- a/test/xkeyboard-config-test.py.in +++ b/test/xkeyboard-config-test.py.in @@ -5,6 +5,7 @@ import sys import subprocess import os import xml.etree.ElementTree as ET +from pathlib import Path verbose = False @@ -195,7 +196,18 @@ def parse(path): return combos -def run(combos, tool, njobs): +def run(combos, tool, njobs, keymap_output_dir): + if keymap_output_dir: + keymap_output_dir = Path(keymap_output_dir) + try: + keymap_output_dir.mkdir() + except FileExistsError as e: + print(e, file=sys.stderr) + return False + + keymap_file = None + keymap_file_fd = None + failed = False with multiprocessing.Pool(njobs) as p: results = p.imap_unordered(tool, combos) @@ -209,6 +221,24 @@ def run(combos, tool, njobs): if target: print(invocation, file=target) + if keymap_output_dir: + # we're running through the layouts in a somewhat sorted manner, + # so let's keep the fd open until we switch layouts + layout = invocation.layout + if invocation.variant: + layout += f"({invocation.variant})" + fname = keymap_output_dir / layout + if fname != keymap_file: + keymap_file = fname + if keymap_file_fd: + keymap_file_fd.close() + keymap_file_fd = open(keymap_file, 'a') + + rmlvo = ', '.join([x or '' for x in invocation.rmlvo]) + print(f"// {rmlvo}", file=keymap_file_fd) + print(invocation.keymap, file=keymap_file_fd) + keymap_file_fd.flush() + return failed @@ -235,15 +265,18 @@ def main(args): default=os.cpu_count() * 4, help='number of processes to use') parser.add_argument('--verbose', '-v', default=False, action="store_true") + parser.add_argument('--keymap-output-dir', default=None, type=str, + help='Directory to print compiled keymaps to') args = parser.parse_args() verbose = args.verbose + keymapdir = args.keymap_output_dir progress_bar = create_progress_bar(verbose) tool = tools[args.tool] combos = parse(args.path) - failed = run(combos, tool, args.jobs) + failed = run(combos, tool, args.jobs, keymapdir) sys.exit(failed) -- cgit v1.2.1