mirror of
https://github.com/systemd/systemd.git
synced 2025-08-03 08:22:21 +03:00
hwdb: make ids_parser.py compatible with pyparsing-2.3.0+
https://github.com/pyparsing/pyparsing/blob/master/CHANGES#L175 says something about fixing erroneously created levels in the hierarchy. I don't have the faintest idea what this means, but with the change in this patch we generate output that is unchanged from pre-2.3.0 versions. Tested with python3-pyparsing-2.3.1-1.fc30.noarch and python3-pyparsing-2.2.0-3.fc29.noarch. Fixes #12021.
This commit is contained in:
committed by
Lennart Poettering
parent
e947830460
commit
2615de9d79
@ -5,6 +5,7 @@ import sys
|
|||||||
from pyparsing import (Word, White, Literal, Regex,
|
from pyparsing import (Word, White, Literal, Regex,
|
||||||
LineEnd, SkipTo,
|
LineEnd, SkipTo,
|
||||||
ZeroOrMore, OneOrMore, Combine, Optional, Suppress,
|
ZeroOrMore, OneOrMore, Combine, Optional, Suppress,
|
||||||
|
Group,
|
||||||
stringEnd, pythonStyleComment)
|
stringEnd, pythonStyleComment)
|
||||||
|
|
||||||
EOL = LineEnd().suppress()
|
EOL = LineEnd().suppress()
|
||||||
@ -23,10 +24,10 @@ def klass_grammar():
|
|||||||
subclass_line = TAB + NUM2('subclass') + text_eol('text')
|
subclass_line = TAB + NUM2('subclass') + text_eol('text')
|
||||||
protocol_line = TAB + TAB + NUM2('protocol') + text_eol('name')
|
protocol_line = TAB + TAB + NUM2('protocol') + text_eol('name')
|
||||||
subclass = (subclass_line('SUBCLASS') -
|
subclass = (subclass_line('SUBCLASS') -
|
||||||
ZeroOrMore(protocol_line('PROTOCOLS*')
|
ZeroOrMore(Group(protocol_line)('PROTOCOLS*')
|
||||||
^ COMMENTLINE.suppress()))
|
^ COMMENTLINE.suppress()))
|
||||||
klass = (klass_line('KLASS') -
|
klass = (klass_line('KLASS') -
|
||||||
ZeroOrMore(subclass('SUBCLASSES*')
|
ZeroOrMore(Group(subclass)('SUBCLASSES*')
|
||||||
^ COMMENTLINE.suppress()))
|
^ COMMENTLINE.suppress()))
|
||||||
return klass
|
return klass
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ def usb_ids_grammar():
|
|||||||
vendor_line = NUM4('vendor') + text_eol('text')
|
vendor_line = NUM4('vendor') + text_eol('text')
|
||||||
device_line = TAB + NUM4('device') + text_eol('text')
|
device_line = TAB + NUM4('device') + text_eol('text')
|
||||||
vendor = (vendor_line('VENDOR') +
|
vendor = (vendor_line('VENDOR') +
|
||||||
ZeroOrMore(device_line('VENDOR_DEV*') ^ COMMENTLINE.suppress()))
|
ZeroOrMore(Group(device_line)('VENDOR_DEV*') ^ COMMENTLINE.suppress()))
|
||||||
|
|
||||||
klass = klass_grammar()
|
klass = klass_grammar()
|
||||||
|
|
||||||
@ -44,7 +45,8 @@ def usb_ids_grammar():
|
|||||||
other_group = (other_line - ZeroOrMore(TAB + text_eol('text')))
|
other_group = (other_line - ZeroOrMore(TAB + text_eol('text')))
|
||||||
|
|
||||||
commentgroup = OneOrMore(COMMENTLINE).suppress() ^ EMPTYLINE.suppress()
|
commentgroup = OneOrMore(COMMENTLINE).suppress() ^ EMPTYLINE.suppress()
|
||||||
grammar = OneOrMore(vendor('VENDORS*') ^ klass('CLASSES*')
|
grammar = OneOrMore(Group(vendor)('VENDORS*')
|
||||||
|
^ Group(klass)('CLASSES*')
|
||||||
^ other_group.suppress() ^ commentgroup) + stringEnd()
|
^ other_group.suppress() ^ commentgroup) + stringEnd()
|
||||||
|
|
||||||
grammar.parseWithTabs()
|
grammar.parseWithTabs()
|
||||||
@ -56,14 +58,15 @@ def pci_ids_grammar():
|
|||||||
subvendor_line = TAB + TAB + NUM4('a') + White(' ') + NUM4('b') + text_eol('name')
|
subvendor_line = TAB + TAB + NUM4('a') + White(' ') + NUM4('b') + text_eol('name')
|
||||||
|
|
||||||
device = (device_line('DEVICE') +
|
device = (device_line('DEVICE') +
|
||||||
ZeroOrMore(subvendor_line('SUBVENDORS*') ^ COMMENTLINE.suppress()))
|
ZeroOrMore(Group(subvendor_line)('SUBVENDORS*') ^ COMMENTLINE.suppress()))
|
||||||
vendor = (vendor_line('VENDOR') +
|
vendor = (vendor_line('VENDOR') +
|
||||||
ZeroOrMore(device('DEVICES*') ^ COMMENTLINE.suppress()))
|
ZeroOrMore(Group(device)('DEVICES*') ^ COMMENTLINE.suppress()))
|
||||||
|
|
||||||
klass = klass_grammar()
|
klass = klass_grammar()
|
||||||
|
|
||||||
commentgroup = OneOrMore(COMMENTLINE).suppress() ^ EMPTYLINE.suppress()
|
commentgroup = OneOrMore(COMMENTLINE).suppress() ^ EMPTYLINE.suppress()
|
||||||
grammar = OneOrMore(vendor('VENDORS*') ^ klass('CLASSES*')
|
grammar = OneOrMore(Group(vendor)('VENDORS*')
|
||||||
|
^ Group(klass)('CLASSES*')
|
||||||
^ commentgroup) + stringEnd()
|
^ commentgroup) + stringEnd()
|
||||||
|
|
||||||
grammar.parseWithTabs()
|
grammar.parseWithTabs()
|
||||||
@ -73,12 +76,14 @@ def sdio_ids_grammar():
|
|||||||
vendor_line = NUM4('vendor') + text_eol('text')
|
vendor_line = NUM4('vendor') + text_eol('text')
|
||||||
device_line = TAB + NUM4('device') + text_eol('text')
|
device_line = TAB + NUM4('device') + text_eol('text')
|
||||||
vendor = (vendor_line('VENDOR') +
|
vendor = (vendor_line('VENDOR') +
|
||||||
ZeroOrMore(device_line('DEVICES*') ^ COMMENTLINE.suppress()))
|
ZeroOrMore(Group(device_line)('DEVICES*') ^ COMMENTLINE.suppress()))
|
||||||
|
|
||||||
klass = klass_grammar()
|
klass = klass_grammar()
|
||||||
|
|
||||||
commentgroup = OneOrMore(COMMENTLINE).suppress() ^ EMPTYLINE.suppress()
|
commentgroup = OneOrMore(COMMENTLINE).suppress() ^ EMPTYLINE.suppress()
|
||||||
grammar = OneOrMore(vendor('VENDORS*') ^ klass('CLASSES*') ^ commentgroup) + stringEnd()
|
grammar = OneOrMore(Group(vendor)('VENDORS*')
|
||||||
|
^ Group(klass)('CLASSES*')
|
||||||
|
^ commentgroup) + stringEnd()
|
||||||
|
|
||||||
grammar.parseWithTabs()
|
grammar.parseWithTabs()
|
||||||
return grammar
|
return grammar
|
||||||
@ -102,7 +107,7 @@ def oui_grammar(type):
|
|||||||
|
|
||||||
grammar = (Literal('OUI') + text_eol('header')
|
grammar = (Literal('OUI') + text_eol('header')
|
||||||
+ text_eol('header') + text_eol('header') + EMPTYLINE
|
+ text_eol('header') + text_eol('header') + EMPTYLINE
|
||||||
+ OneOrMore(vendor('VENDORS*')) + stringEnd())
|
+ OneOrMore(Group(vendor)('VENDORS*')) + stringEnd())
|
||||||
|
|
||||||
grammar.parseWithTabs()
|
grammar.parseWithTabs()
|
||||||
return grammar
|
return grammar
|
||||||
@ -126,8 +131,8 @@ def usb_vendor_model(p):
|
|||||||
items = {}
|
items = {}
|
||||||
|
|
||||||
for vendor_group in p.VENDORS:
|
for vendor_group in p.VENDORS:
|
||||||
vendor = vendor_group.VENDOR.vendor.upper()
|
vendor = vendor_group.vendor.upper()
|
||||||
text = vendor_group.VENDOR.text.strip()
|
text = vendor_group.text.strip()
|
||||||
add_item(items, (vendor,), text)
|
add_item(items, (vendor,), text)
|
||||||
|
|
||||||
for vendor_dev in vendor_group.VENDOR_DEV:
|
for vendor_dev in vendor_group.VENDOR_DEV:
|
||||||
@ -152,8 +157,8 @@ def usb_classes(p):
|
|||||||
items = {}
|
items = {}
|
||||||
|
|
||||||
for klass_group in p.CLASSES:
|
for klass_group in p.CLASSES:
|
||||||
klass = klass_group.KLASS.klass.upper()
|
klass = klass_group.klass.upper()
|
||||||
text = klass_group.KLASS.text.strip()
|
text = klass_group.text.strip()
|
||||||
|
|
||||||
if klass != '00' and not re.match(r'(\?|None|Unused)\s*$', text):
|
if klass != '00' and not re.match(r'(\?|None|Unused)\s*$', text):
|
||||||
add_item(items, (klass,), text)
|
add_item(items, (klass,), text)
|
||||||
@ -189,8 +194,8 @@ def pci_vendor_model(p):
|
|||||||
items = {}
|
items = {}
|
||||||
|
|
||||||
for vendor_group in p.VENDORS:
|
for vendor_group in p.VENDORS:
|
||||||
vendor = vendor_group.VENDOR.vendor.upper()
|
vendor = vendor_group.vendor.upper()
|
||||||
text = vendor_group.VENDOR.text.strip()
|
text = vendor_group.text.strip()
|
||||||
add_item(items, (vendor,), text)
|
add_item(items, (vendor,), text)
|
||||||
|
|
||||||
for device_group in vendor_group.DEVICES:
|
for device_group in vendor_group.DEVICES:
|
||||||
@ -227,8 +232,8 @@ def pci_classes(p):
|
|||||||
items = {}
|
items = {}
|
||||||
|
|
||||||
for klass_group in p.CLASSES:
|
for klass_group in p.CLASSES:
|
||||||
klass = klass_group.KLASS.klass.upper()
|
klass = klass_group.klass.upper()
|
||||||
text = klass_group.KLASS.text.strip()
|
text = klass_group.text.strip()
|
||||||
add_item(items, (klass,), text)
|
add_item(items, (klass,), text)
|
||||||
|
|
||||||
for subclass_group in klass_group.SUBCLASSES:
|
for subclass_group in klass_group.SUBCLASSES:
|
||||||
@ -260,8 +265,8 @@ def sdio_vendor_model(p):
|
|||||||
items = {}
|
items = {}
|
||||||
|
|
||||||
for vendor_group in p.VENDORS:
|
for vendor_group in p.VENDORS:
|
||||||
vendor = vendor_group.VENDOR.vendor.upper()
|
vendor = vendor_group.vendor.upper()
|
||||||
text = vendor_group.VENDOR.text.strip()
|
text = vendor_group.text.strip()
|
||||||
add_item(items, (vendor,), text)
|
add_item(items, (vendor,), text)
|
||||||
|
|
||||||
for device_group in vendor_group.DEVICES:
|
for device_group in vendor_group.DEVICES:
|
||||||
@ -286,8 +291,8 @@ def sdio_classes(p):
|
|||||||
items = {}
|
items = {}
|
||||||
|
|
||||||
for klass_group in p.CLASSES:
|
for klass_group in p.CLASSES:
|
||||||
klass = klass_group.KLASS.klass.upper()
|
klass = klass_group.klass.upper()
|
||||||
text = klass_group.KLASS.text.strip()
|
text = klass_group.text.strip()
|
||||||
add_item(items, klass, text)
|
add_item(items, klass, text)
|
||||||
|
|
||||||
with open('20-sdio-classes.hwdb', 'wt') as out:
|
with open('20-sdio-classes.hwdb', 'wt') as out:
|
||||||
|
Reference in New Issue
Block a user