mirror of
https://github.com/systemd/systemd.git
synced 2025-01-10 05:18:17 +03:00
Merge pull request #3933 from keszybz/hwdb-parser
Add hwdb parser to check for inconsistencies
This commit is contained in:
commit
ff0bb1ed93
@ -3872,7 +3872,8 @@ TESTS += \
|
|||||||
|
|
||||||
if HAVE_PYTHON
|
if HAVE_PYTHON
|
||||||
TESTS += \
|
TESTS += \
|
||||||
test/rule-syntax-check.py
|
test/rule-syntax-check.py \
|
||||||
|
hwdb/parse_hwdb.py
|
||||||
|
|
||||||
if HAVE_SYSV_COMPAT
|
if HAVE_SYSV_COMPAT
|
||||||
TESTS += \
|
TESTS += \
|
||||||
@ -3924,7 +3925,8 @@ EXTRA_DIST += \
|
|||||||
test/udev-test.pl \
|
test/udev-test.pl \
|
||||||
test/rule-syntax-check.py \
|
test/rule-syntax-check.py \
|
||||||
test/sysv-generator-test.py \
|
test/sysv-generator-test.py \
|
||||||
test/mocks/fsck
|
test/mocks/fsck \
|
||||||
|
hwdb/parse_hwdb.py
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
ata_id_SOURCES = \
|
ata_id_SOURCES = \
|
||||||
|
@ -213,7 +213,7 @@ evdev:atkbd:dmi:bvn*:bvr*:bd*:svnDell*:pn*
|
|||||||
KEYBOARD_KEY_8a=suspend # Fn+F1 hibernate
|
KEYBOARD_KEY_8a=suspend # Fn+F1 hibernate
|
||||||
KEYBOARD_KEY_8b=switchvideomode # Fn+F8 CRT/LCD (high keycode: "displaytoggle")
|
KEYBOARD_KEY_8b=switchvideomode # Fn+F8 CRT/LCD (high keycode: "displaytoggle")
|
||||||
KEYBOARD_KEY_8c=unknown # Fn+Right Auto Brightness
|
KEYBOARD_KEY_8c=unknown # Fn+Right Auto Brightness
|
||||||
KEYBOARD_KEY_8F=switchvideomode # Fn+F7 aspect ratio
|
KEYBOARD_KEY_8f=switchvideomode # Fn+F7 aspect ratio
|
||||||
KEYBOARD_KEY_90=previoussong # Front panel previous song
|
KEYBOARD_KEY_90=previoussong # Front panel previous song
|
||||||
KEYBOARD_KEY_91=prog1 # Wi-Fi Catcher (Dell-specific)
|
KEYBOARD_KEY_91=prog1 # Wi-Fi Catcher (Dell-specific)
|
||||||
KEYBOARD_KEY_92=media # MediaDirect button (house icon)
|
KEYBOARD_KEY_92=media # MediaDirect button (house icon)
|
||||||
@ -482,8 +482,7 @@ evdev:atkbd:dmi:bvn*:bvr*:bd*:svnHewlett-Packard*:pnFalco:pvr*
|
|||||||
KEYBOARD_KEY_43=volumedown
|
KEYBOARD_KEY_43=volumedown
|
||||||
KEYBOARD_KEY_44=volumeup
|
KEYBOARD_KEY_44=volumeup
|
||||||
KEYBOARD_KEY_db=search # Same position as caps lock key on most keyboards
|
KEYBOARD_KEY_db=search # Same position as caps lock key on most keyboards
|
||||||
# KEYBOARD_KEY_3e=fullscreen, no defined key sym
|
# KEYBOARD_KEY_3e=fullscreen, no defined key sym
|
||||||
|
|
||||||
|
|
||||||
# HP EliteBook 725 G2
|
# HP EliteBook 725 G2
|
||||||
evdev:atkbd:dmi:bvn*:bvr*:bd*:svnHewlett-Packard*:pnHPLicrice:pvr*
|
evdev:atkbd:dmi:bvn*:bvr*:bd*:svnHewlett-Packard*:pnHPLicrice:pvr*
|
||||||
@ -694,7 +693,7 @@ evdev:input:b0003v046DpC308*
|
|||||||
KEYBOARD_KEY_90003=finance # Finance
|
KEYBOARD_KEY_90003=finance # Finance
|
||||||
KEYBOARD_KEY_90004=prog1 # My Sites
|
KEYBOARD_KEY_90004=prog1 # My Sites
|
||||||
KEYBOARD_KEY_90005=prog2 # Community
|
KEYBOARD_KEY_90005=prog2 # Community
|
||||||
KEYBOARD_KEY_C0183=media # Media
|
KEYBOARD_KEY_c0183=media # Media
|
||||||
|
|
||||||
# Cordless Desktop S510
|
# Cordless Desktop S510
|
||||||
evdev:input:b0003v046DpC50C*
|
evdev:input:b0003v046DpC50C*
|
||||||
@ -763,18 +762,18 @@ evdev:input:b0003v046DpC309*
|
|||||||
KEYBOARD_KEY_90002=camera # webcam
|
KEYBOARD_KEY_90002=camera # webcam
|
||||||
KEYBOARD_KEY_90003=prog1 # iTouch
|
KEYBOARD_KEY_90003=prog1 # iTouch
|
||||||
KEYBOARD_KEY_90004=shop # Shopping
|
KEYBOARD_KEY_90004=shop # Shopping
|
||||||
KEYBOARD_KEY_C0201=new # New (F1)
|
KEYBOARD_KEY_c0201=new # New (F1)
|
||||||
KEYBOARD_KEY_C0289=reply # Reply mail (F2)
|
KEYBOARD_KEY_c0289=reply # Reply mail (F2)
|
||||||
KEYBOARD_KEY_C028B=forwardmail # Forward mail (F3)
|
KEYBOARD_KEY_c028b=forwardmail # Forward mail (F3)
|
||||||
KEYBOARD_KEY_C028C=send # Send (F4)
|
KEYBOARD_KEY_c028c=send # Send (F4)
|
||||||
KEYBOARD_KEY_C021A=undo # Undo (F5).
|
KEYBOARD_KEY_c021a=undo # Undo (F5).
|
||||||
KEYBOARD_KEY_C0279=redo # Redo (F6).
|
KEYBOARD_KEY_c0279=redo # Redo (F6).
|
||||||
KEYBOARD_KEY_C0208=print # Print (F7)
|
KEYBOARD_KEY_c0208=print # Print (F7)
|
||||||
KEYBOARD_KEY_C0207=save # Save (F8)
|
KEYBOARD_KEY_c0207=save # Save (F8)
|
||||||
KEYBOARD_KEY_C0194=file # My Computer (F9)
|
KEYBOARD_KEY_c0194=file # My Computer (F9)
|
||||||
KEYBOARD_KEY_C01A7=documents # My Documents (F10)
|
KEYBOARD_KEY_c01a7=documents # My Documents (F10)
|
||||||
KEYBOARD_KEY_C01B6=images # My Pictures (F11) ??
|
KEYBOARD_KEY_c01b6=images # My Pictures (F11) ??
|
||||||
KEYBOARD_KEY_C01B7=sound # My Music (F12) ??
|
KEYBOARD_KEY_c01b7=sound # My Music (F12) ??
|
||||||
|
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
@ -897,7 +896,7 @@ evdev:atkbd:dmi:bvn*:bvr*:bd*:svnOLPC:pnXO:*
|
|||||||
KEYBOARD_KEY_c2=f8
|
KEYBOARD_KEY_c2=f8
|
||||||
KEYBOARD_KEY_c3=f9
|
KEYBOARD_KEY_c3=f9
|
||||||
KEYBOARD_KEY_c4=f10
|
KEYBOARD_KEY_c4=f10
|
||||||
KEYBOARD_KEY_c7=f11
|
# KEYBOARD_KEY_c7=f11 # FIXME!
|
||||||
KEYBOARD_KEY_d8=f12
|
KEYBOARD_KEY_d8=f12
|
||||||
KEYBOARD_KEY_f7=f13
|
KEYBOARD_KEY_f7=f13
|
||||||
KEYBOARD_KEY_f6=f14
|
KEYBOARD_KEY_f6=f14
|
||||||
@ -917,7 +916,7 @@ evdev:atkbd:dmi:bvn*:bvr*:bd*:svnOLPC:pnXO:*
|
|||||||
KEYBOARD_KEY_c9=pageup
|
KEYBOARD_KEY_c9=pageup
|
||||||
KEYBOARD_KEY_d1=pagedown
|
KEYBOARD_KEY_d1=pagedown
|
||||||
KEYBOARD_KEY_c7=home
|
KEYBOARD_KEY_c7=home
|
||||||
KEYBOARD_KEY_cF=end
|
KEYBOARD_KEY_cf=end
|
||||||
KEYBOARD_KEY_73=hp
|
KEYBOARD_KEY_73=hp
|
||||||
KEYBOARD_KEY_7e=hp
|
KEYBOARD_KEY_7e=hp
|
||||||
KEYBOARD_KEY_db=leftmeta # left grab
|
KEYBOARD_KEY_db=leftmeta # left grab
|
||||||
|
@ -297,7 +297,7 @@ mouse:usb:v046dpc049:name:Logitech USB Gaming Mouse:
|
|||||||
mouse:usb:v046dpc24e:name:Logitech G500s Laser Gaming Mouse:
|
mouse:usb:v046dpc24e:name:Logitech G500s Laser Gaming Mouse:
|
||||||
MOUSE_DPI=400@500 *800@500 2000@500
|
MOUSE_DPI=400@500 *800@500 2000@500
|
||||||
|
|
||||||
# Logitech G9
|
# Logitech G9
|
||||||
mouse:usb:v046dpc048:name:Logitech G9 Laser Mouse:
|
mouse:usb:v046dpc048:name:Logitech G9 Laser Mouse:
|
||||||
MOUSE_DPI=400@1000 800@1000 *1600@1000
|
MOUSE_DPI=400@1000 800@1000 *1600@1000
|
||||||
|
|
||||||
@ -342,8 +342,6 @@ mouse:usb:v046dp402d:name:Logitech M560:
|
|||||||
mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:402d:
|
mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:402d:
|
||||||
MOUSE_DPI=1000@125
|
MOUSE_DPI=1000@125
|
||||||
|
|
||||||
# Logitech V220 Cordless Optical Mouse
|
|
||||||
mouse:usb:v046dpc51b:name:Logitech USB Receiver:
|
|
||||||
# Logitech Performance MX
|
# Logitech Performance MX
|
||||||
mouse:usb:v046dp101a:name:Logitech Performance MX:
|
mouse:usb:v046dp101a:name:Logitech Performance MX:
|
||||||
# Logitech MX Master
|
# Logitech MX Master
|
||||||
@ -373,11 +371,6 @@ mouse:usb:v046dp4027:name:Logitech T620:
|
|||||||
mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:4027:
|
mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:4027:
|
||||||
MOUSE_DPI=1200@250
|
MOUSE_DPI=1200@250
|
||||||
|
|
||||||
# Logitech LX8 Cordless Laser Mouse
|
|
||||||
mouse:usb:v046dpc51b:name:Logitech USB Receiver:
|
|
||||||
MOUSE_DPI=1300@125
|
|
||||||
MOUSE_WHEEL_CLICK_ANGLE=15
|
|
||||||
|
|
||||||
# Logitech ZoneTouch Mouse T400
|
# Logitech ZoneTouch Mouse T400
|
||||||
mouse:usb:v046dp4026:name:Logitech T400:
|
mouse:usb:v046dp4026:name:Logitech T400:
|
||||||
mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:4026:
|
mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:4026:
|
||||||
|
183
hwdb/parse_hwdb.py
Executable file
183
hwdb/parse_hwdb.py
Executable file
@ -0,0 +1,183 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
|
||||||
|
#
|
||||||
|
# This file is part of systemd.
|
||||||
|
#
|
||||||
|
# Copyright 2016 Zbigniew Jędrzejewski-Szmek
|
||||||
|
#
|
||||||
|
# systemd is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU Lesser General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# systemd is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import functools
|
||||||
|
import glob
|
||||||
|
import string
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
try:
|
||||||
|
from pyparsing import (Word, White, Literal, ParserElement, Regex,
|
||||||
|
LineStart, LineEnd,
|
||||||
|
ZeroOrMore, OneOrMore, Combine, Or, Optional, Suppress, Group,
|
||||||
|
nums, alphanums, printables,
|
||||||
|
stringEnd, pythonStyleComment,
|
||||||
|
ParseBaseException)
|
||||||
|
except ImportError:
|
||||||
|
print('pyparsing is not available')
|
||||||
|
sys.exit(77)
|
||||||
|
|
||||||
|
try:
|
||||||
|
from evdev.ecodes import ecodes
|
||||||
|
except ImportError:
|
||||||
|
ecodes = None
|
||||||
|
print('WARNING: evdev is not available')
|
||||||
|
|
||||||
|
EOL = LineEnd().suppress()
|
||||||
|
EMPTYLINE = LineStart() + LineEnd()
|
||||||
|
COMMENTLINE = pythonStyleComment + EOL
|
||||||
|
INTEGER = Word(nums)
|
||||||
|
REAL = Combine((INTEGER + Optional('.' + Optional(INTEGER))) ^ ('.' + INTEGER))
|
||||||
|
UDEV_TAG = Word(string.ascii_uppercase, alphanums + '_')
|
||||||
|
|
||||||
|
TYPES = {'mouse': ('usb', 'bluetooth', 'ps2', '*'),
|
||||||
|
'evdev': ('name', 'atkbd', 'input'),
|
||||||
|
'touchpad': ('i8042', 'rmi', 'bluetooth', 'usb'),
|
||||||
|
'keyboard': ('name', ),
|
||||||
|
}
|
||||||
|
|
||||||
|
@functools.lru_cache()
|
||||||
|
def hwdb_grammar():
|
||||||
|
ParserElement.setDefaultWhitespaceChars('')
|
||||||
|
|
||||||
|
prefix = Or(category + ':' + Or(conn) + ':'
|
||||||
|
for category, conn in TYPES.items())
|
||||||
|
matchline = Combine(prefix + Word(printables + ' ' + '®')) + EOL
|
||||||
|
propertyline = (White(' ', exact=1).suppress() +
|
||||||
|
Combine(UDEV_TAG - '=' - Word(alphanums + '_=:@*.! ') - Optional(pythonStyleComment)) +
|
||||||
|
EOL)
|
||||||
|
propertycomment = White(' ', exact=1) + pythonStyleComment + EOL
|
||||||
|
|
||||||
|
group = (OneOrMore(matchline('MATCHES*') ^ COMMENTLINE.suppress()) -
|
||||||
|
OneOrMore(propertyline('PROPERTIES*') ^ propertycomment.suppress()) -
|
||||||
|
(EMPTYLINE ^ stringEnd()).suppress() )
|
||||||
|
commentgroup = OneOrMore(COMMENTLINE).suppress() - EMPTYLINE.suppress()
|
||||||
|
|
||||||
|
grammar = OneOrMore(group('GROUPS*') ^ commentgroup) + stringEnd()
|
||||||
|
|
||||||
|
return grammar
|
||||||
|
|
||||||
|
@functools.lru_cache()
|
||||||
|
def property_grammar():
|
||||||
|
ParserElement.setDefaultWhitespaceChars(' ')
|
||||||
|
|
||||||
|
setting = Optional('*')('DEFAULT') + INTEGER('DPI') + Suppress('@') + INTEGER('HZ')
|
||||||
|
props = (('MOUSE_DPI', Group(OneOrMore(setting('SETTINGS*')))),
|
||||||
|
('MOUSE_WHEEL_CLICK_ANGLE', INTEGER),
|
||||||
|
('ID_INPUT_TRACKBALL', Literal('1')),
|
||||||
|
('POINTINGSTICK_SENSITIVITY', INTEGER),
|
||||||
|
('POINTINGSTICK_CONST_ACCEL', REAL),
|
||||||
|
('ID_INPUT_TOUCHPAD_INTEGRATION', Or(('internal', 'external'))),
|
||||||
|
)
|
||||||
|
fixed_props = [Literal(name)('NAME') - Suppress('=') - val('VALUE')
|
||||||
|
for name, val in props]
|
||||||
|
kbd_props = [Regex(r'KEYBOARD_KEY_[0-9a-f]+')('NAME')
|
||||||
|
- Suppress('=') -
|
||||||
|
('!' ^ (Optional('!') - Word(alphanums + '_')))('VALUE')
|
||||||
|
]
|
||||||
|
abs_props = [Regex(r'EVDEV_ABS_[0-9a-f]{2}')('NAME')
|
||||||
|
- Suppress('=') -
|
||||||
|
Word(nums + ':')('VALUE')
|
||||||
|
]
|
||||||
|
|
||||||
|
grammar = Or(fixed_props + kbd_props + abs_props)
|
||||||
|
|
||||||
|
return grammar
|
||||||
|
|
||||||
|
ERROR = False
|
||||||
|
def error(fmt, *args, **kwargs):
|
||||||
|
global ERROR
|
||||||
|
ERROR = True
|
||||||
|
print(fmt.format(*args, **kwargs))
|
||||||
|
|
||||||
|
def convert_properties(group):
|
||||||
|
matches = [m[0] for m in group.MATCHES]
|
||||||
|
props = [p[0] for p in group.PROPERTIES]
|
||||||
|
return matches, props
|
||||||
|
|
||||||
|
def parse(fname):
|
||||||
|
grammar = hwdb_grammar()
|
||||||
|
try:
|
||||||
|
parsed = grammar.parseFile(fname)
|
||||||
|
except ParseBaseException as e:
|
||||||
|
error('Cannot parse {}: {}', fname, e)
|
||||||
|
return []
|
||||||
|
return [convert_properties(g) for g in parsed.GROUPS]
|
||||||
|
|
||||||
|
def check_match_uniqueness(groups):
|
||||||
|
matches = sum((group[0] for group in groups), [])
|
||||||
|
matches.sort()
|
||||||
|
prev = None
|
||||||
|
for match in matches:
|
||||||
|
if match == prev:
|
||||||
|
error('Match {!r} is duplicated', match)
|
||||||
|
prev = match
|
||||||
|
|
||||||
|
def check_one_default(prop, settings):
|
||||||
|
defaults = [s for s in settings if s.DEFAULT]
|
||||||
|
if len(defaults) > 1:
|
||||||
|
error('More than one star entry: {!r}', prop)
|
||||||
|
|
||||||
|
def check_one_keycode(prop, value):
|
||||||
|
if value != '!' and ecodes is not None:
|
||||||
|
key = 'KEY_' + value.upper()
|
||||||
|
if key not in ecodes:
|
||||||
|
error('Keycode {} unknown', key)
|
||||||
|
|
||||||
|
def check_properties(groups):
|
||||||
|
grammar = property_grammar()
|
||||||
|
for matches, props in groups:
|
||||||
|
prop_names = set()
|
||||||
|
for prop in props:
|
||||||
|
# print('--', prop)
|
||||||
|
prop = prop.partition('#')[0].rstrip()
|
||||||
|
try:
|
||||||
|
parsed = grammar.parseString(prop)
|
||||||
|
except ParseBaseException as e:
|
||||||
|
error('Failed to parse: {!r}', prop)
|
||||||
|
continue
|
||||||
|
# print('{!r}'.format(parsed))
|
||||||
|
if parsed.NAME in prop_names:
|
||||||
|
error('Property {} is duplicated', parsed.NAME)
|
||||||
|
prop_names.add(parsed.NAME)
|
||||||
|
if parsed.NAME == 'MOUSE_DPI':
|
||||||
|
check_one_default(prop, parsed.VALUE.SETTINGS)
|
||||||
|
elif parsed.NAME.startswith('KEYBOARD_KEY_'):
|
||||||
|
check_one_keycode(prop, parsed.VALUE)
|
||||||
|
|
||||||
|
def print_summary(fname, 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),
|
||||||
|
))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
args = sys.argv[1:] or glob.glob(os.path.dirname(sys.argv[0]) + '/[67]0-*.hwdb')
|
||||||
|
|
||||||
|
for fname in args:
|
||||||
|
groups = parse(fname)
|
||||||
|
print_summary(fname, groups)
|
||||||
|
check_match_uniqueness(groups)
|
||||||
|
check_properties(groups)
|
||||||
|
|
||||||
|
sys.exit(ERROR)
|
Loading…
Reference in New Issue
Block a user