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 <peter.hutterer@who-t.net>
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 66 67 68 69 70 71 72 73 74 75 76 77
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)