From f3c80bc01e5e7f6f882eb5d78f9e8e780211a0f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 8 Oct 2019 14:21:26 +0200 Subject: [PATCH 1/3] parse_hwdb: bail with an error if no matches or groups are detected pyparsing sometimes changes behaviour and stops giving matches. This should allow us to detect such scenario. With this change, parse_hwdb fails with pyparsing 2.4 on F31. --- hwdb.d/parse_hwdb.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hwdb.d/parse_hwdb.py b/hwdb.d/parse_hwdb.py index da0bca5c5d..78c7f9bd56 100755 --- a/hwdb.d/parse_hwdb.py +++ b/hwdb.d/parse_hwdb.py @@ -224,11 +224,13 @@ def check_properties(groups): check_one_keycode(prop, parsed.VALUE) def print_summary(fname, groups): + n_matches = sum(len(matches) for matches, props in groups) + n_props = sum(len(props) for matches, props in groups) print('{}: {} match groups, {} matches, {} properties' - .format(fname, - len(groups), - sum(len(matches) for matches, props in groups), - sum(len(props) for matches, props in groups))) + .format(fname, len(groups), n_matches, n_props)) + + if n_matches == 0 or n_props == 0: + error('{}: no matches or props'.format(fname)) if __name__ == '__main__': args = sys.argv[1:] or glob.glob(os.path.dirname(sys.argv[0]) + '/[67]0-*.hwdb') From b32ae3aa7b63bad3cd9d412701d66c5cd8499160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 8 Oct 2019 14:22:17 +0200 Subject: [PATCH 2/3] parse_hwdb: process files in order Also, make the pattern more general. There are some plans to add more files there, let's make sure we don't miss them. --- hwdb.d/parse_hwdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hwdb.d/parse_hwdb.py b/hwdb.d/parse_hwdb.py index 78c7f9bd56..1bd36b8aba 100755 --- a/hwdb.d/parse_hwdb.py +++ b/hwdb.d/parse_hwdb.py @@ -233,7 +233,7 @@ def print_summary(fname, groups): error('{}: no matches or props'.format(fname)) if __name__ == '__main__': - args = sys.argv[1:] or glob.glob(os.path.dirname(sys.argv[0]) + '/[67]0-*.hwdb') + args = sys.argv[1:] or sorted(glob.glob(os.path.dirname(sys.argv[0]) + '/[67][0-9]-*.hwdb')) for fname in args: groups = parse(fname) From 2382a2e32b6076fa4603c958f84b46d5a5b13dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 8 Oct 2019 14:44:35 +0200 Subject: [PATCH 3/3] parse_hwdb: fix compatibility with pyparsing 2.4.* pyparsing 2.3.1/2.4.0 had some changes to grouping of And matches, and as a result we'd report 0 properties and 0 matches, and not really do any checks. With this change we get identical behaviour for pyparsing 2.3.1, 2.4.0, 2.4.2: $ hwdb/parse_hwdb.py hwdb/60-evdev.hwdb: 72 match groups, 94 matches, 262 properties hwdb/60-input-id.hwdb: 3 match groups, 3 matches, 4 properties hwdb/60-keyboard.hwdb: 173 match groups, 256 matches, 872 properties Keycode KBD_LCD_MENU1 unknown Keycode KBD_LCD_MENU4 unknown Keycode KBD_LCD_MENU2 unknown Keycode KBD_LCD_MENU3 unknown hwdb/60-sensor.hwdb: 101 match groups, 120 matches, 105 properties hwdb/70-joystick.hwdb: 2 match groups, 3 matches, 2 properties hwdb/70-mouse.hwdb: 104 match groups, 119 matches, 123 properties hwdb/70-pointingstick.hwdb: 8 match groups, 30 matches, 11 properties hwdb/70-touchpad.hwdb: 6 match groups, 9 matches, 6 properties --- hwdb.d/parse_hwdb.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hwdb.d/parse_hwdb.py b/hwdb.d/parse_hwdb.py index 1bd36b8aba..c558687edc 100755 --- a/hwdb.d/parse_hwdb.py +++ b/hwdb.d/parse_hwdb.py @@ -85,7 +85,7 @@ def hwdb_grammar(): (EMPTYLINE ^ stringEnd()).suppress()) commentgroup = OneOrMore(COMMENTLINE).suppress() - EMPTYLINE.suppress() - grammar = OneOrMore(group('GROUPS*') ^ commentgroup) + stringEnd() + grammar = OneOrMore(Group(group)('GROUPS*') ^ commentgroup) + stringEnd() return grammar @@ -221,7 +221,8 @@ def check_properties(groups): elif parsed.NAME == 'ACCEL_MOUNT_MATRIX': check_one_mount_matrix(prop, parsed.VALUE) elif parsed.NAME.startswith('KEYBOARD_KEY_'): - check_one_keycode(prop, parsed.VALUE) + val = parsed.VALUE if isinstance(parsed.VALUE, str) else parsed.VALUE[0] + check_one_keycode(prop, val) def print_summary(fname, groups): n_matches = sum(len(matches) for matches, props in groups)