1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-09-23 17:45:21 +03:00

Merge pull request #25073 from mrc0mmand/parse-hwdb-tweaks

test: make parse-hwdb compatible with older pyparsing versions
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-10-20 10:02:04 +02:00
committed by GitHub

View File

@@ -1,4 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# pylint: disable=line-too-long,invalid-name,global-statement,redefined-outer-name
# pylint: disable=missing-function-docstring,missing-class-docstring,missing-module-docstring
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# #
# This file is distributed under the MIT license, see below. # This file is distributed under the MIT license, see below.
@@ -33,11 +35,22 @@ try:
OneOrMore, Combine, Or, Optional, Suppress, Group, OneOrMore, Combine, Or, Optional, Suppress, Group,
nums, alphanums, printables, nums, alphanums, printables,
stringEnd, pythonStyleComment, stringEnd, pythonStyleComment,
ParseBaseException, __diag__) ParseBaseException)
except ImportError: except ImportError:
print('pyparsing is not available') print('pyparsing is not available')
sys.exit(77) sys.exit(77)
try:
from pyparsing import __diag__
__diag__.warn_multiple_tokens_in_named_alternation = True
__diag__.warn_ungrouped_named_tokens_in_collection = True
__diag__.warn_name_set_on_empty_Forward = True
__diag__.warn_on_multiple_string_args_to_oneof = True
__diag__.enable_debug_on_named_expressions = True
except ImportError:
pass
try: try:
from evdev.ecodes import ecodes from evdev.ecodes import ecodes
except ImportError: except ImportError:
@@ -50,12 +63,6 @@ except ImportError:
# don't do caching on old python # don't do caching on old python
lru_cache = lambda: (lambda f: f) lru_cache = lambda: (lambda f: f)
__diag__.warn_multiple_tokens_in_named_alternation = True
__diag__.warn_ungrouped_named_tokens_in_collection = True
__diag__.warn_name_set_on_empty_Forward = True
__diag__.warn_on_multiple_string_args_to_oneof = True
__diag__.enable_debug_on_named_expressions = True
EOL = LineEnd().suppress() EOL = LineEnd().suppress()
EMPTYLINE = LineEnd() EMPTYLINE = LineEnd()
COMMENTLINE = pythonStyleComment + EOL COMMENTLINE = pythonStyleComment + EOL
@@ -272,7 +279,7 @@ def check_one_mount_matrix(prop, value):
'x' if bad_x else ('y' if bad_y else 'z'), 'x' if bad_x else ('y' if bad_y else 'z'),
prop) prop)
def check_one_keycode(prop, value): def check_one_keycode(value):
if value != '!' and ecodes is not None: if value != '!' and ecodes is not None:
key = 'KEY_' + value.upper() key = 'KEY_' + value.upper()
if not (key in ecodes or if not (key in ecodes or
@@ -292,14 +299,14 @@ def check_wheel_clicks(properties):
def check_properties(groups): def check_properties(groups):
grammar = property_grammar() grammar = property_grammar()
for matches, props in groups: for _, props in groups:
seen_props = {} seen_props = {}
for prop in props: for prop in props:
# print('--', prop) # print('--', prop)
prop = prop.partition('#')[0].rstrip() prop = prop.partition('#')[0].rstrip()
try: try:
parsed = grammar.parseString(prop) parsed = grammar.parseString(prop)
except ParseBaseException as e: except ParseBaseException:
error('Failed to parse: {!r}', prop) error('Failed to parse: {!r}', prop)
continue continue
# print('{!r}'.format(parsed)) # print('{!r}'.format(parsed))
@@ -312,18 +319,17 @@ def check_properties(groups):
check_one_mount_matrix(prop, parsed.VALUE) check_one_mount_matrix(prop, parsed.VALUE)
elif parsed.NAME.startswith('KEYBOARD_KEY_'): elif parsed.NAME.startswith('KEYBOARD_KEY_'):
val = parsed.VALUE if isinstance(parsed.VALUE, str) else parsed.VALUE[0] val = parsed.VALUE if isinstance(parsed.VALUE, str) else parsed.VALUE[0]
check_one_keycode(prop, val) check_one_keycode(val)
check_wheel_clicks(seen_props) check_wheel_clicks(seen_props)
def print_summary(fname, groups): def print_summary(fname, groups):
n_matches = sum(len(matches) for matches, props in groups) n_matches = sum(len(matches) for matches, props in groups)
n_props = sum(len(props) for matches, props in groups) n_props = sum(len(props) for matches, props in groups)
print('{}: {} match groups, {} matches, {} properties' print(f'{fname}: {len(groups)} match groups, {n_matches} matches, {n_props} properties')
.format(fname, len(groups), n_matches, n_props))
if n_matches == 0 or n_props == 0: if n_matches == 0 or n_props == 0:
error('{}: no matches or props'.format(fname)) error(f'{fname}: no matches or props')
if __name__ == '__main__': if __name__ == '__main__':
args = sys.argv[1:] or sorted(glob.glob(os.path.dirname(sys.argv[0]) + '/[678][0-9]-*.hwdb')) args = sys.argv[1:] or sorted(glob.glob(os.path.dirname(sys.argv[0]) + '/[678][0-9]-*.hwdb'))