test: xkeyboard-config: use argparse for the path and the tool selection 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
diff --git a/test/xkeyboard-config-test.py.in b/test/xkeyboard-config-test.py.in
index 345ebd5..9516b2c 100755
--- a/test/xkeyboard-config-test.py.in
+++ b/test/xkeyboard-config-test.py.in
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+import argparse
import sys
import subprocess
import os
@@ -89,7 +90,7 @@ def xkbcomp(r='evdev', m='pc105', l='us', v='', o=''):
print(err.output.decode('utf-8'))
-def parse(root):
+def parse(root, tool):
layouts = root.findall('layoutList/layout')
options = [
@@ -97,10 +98,6 @@ def parse(root):
for e in root.findall('optionList/group/option/configItem/name')
]
- # Switch this to xkbcomp if needed.
- tool = xkbcommontool
- # tool = xkbcomp
-
for l in progress_bar(layouts, 'layout '):
layout = l.find('configItem/name').text
tool(l=layout)
@@ -115,14 +112,28 @@ def parse(root):
def main(args):
- try:
- path = args[1]
- except IndexError:
- path = DEFAULT_RULES_XML
-
- with open(path) as f:
+ tools = {
+ 'libxkbcommon': xkbcommontool,
+ 'xkbcomp': xkbcomp,
+ }
+
+ parser = argparse.ArgumentParser(
+ description='Tool to test all layout/variant/option combinations.'
+ )
+ parser.add_argument('path', metavar='/path/to/evdev.xml',
+ nargs='?', type=str,
+ default=DEFAULT_RULES_XML,
+ help='Path to xkeyboard-config\'s evdev.xml')
+ parser.add_argument('--tool', choices=tools.keys(),
+ type=str, default='libxkbcommon',
+ help='parsing tool to use')
+ args = parser.parse_args()
+
+ tool = tools[args.tool]
+
+ with open(args.path) as f:
root = ET.fromstring(f.read())
- parse(root)
+ parse(root, tool)
if __name__ == '__main__':