naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
8d419f
From 72d3b0c995403293f65ee9a47043ebd2fdafc1cd Mon Sep 17 00:00:00 2001
8d419f
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
8d419f
Date: Tue, 29 Mar 2022 12:17:51 +0200
8d419f
Subject: [PATCH] hwdb: fix parser to work with newer pyparsing
8d419f
8d419f
The handling of whitespace in pyparsing is a bother. There's some
8d419f
global state, and per-element state, and it's hard to get a handle on
8d419f
things. With python3-pyparsing-2.4.7-10.fc36.noarch the grammar would
8d419f
not match. After handling of tabs was fixed to not accept duplicate tabs,
8d419f
the grammar passes.
8d419f
8d419f
It seems that the entry for usb:v8087p8087*
8d419f
was generated incorrectly because we treated the interface line
8d419f
(with two TABs) as a device line (with one TAB).
8d419f
8d419f
(cherry picked from commit f73d6895872cb9caffc523e1eddc53c9b98cfdec)
8d419f
8d419f
Related: #2087778
8d419f
---
8d419f
 hwdb.d/20-usb-vendor-model.hwdb |  3 ---
8d419f
 hwdb.d/ids_parser.py            | 10 ++++++++--
8d419f
 2 files changed, 8 insertions(+), 5 deletions(-)
8d419f
8d419f
diff --git a/hwdb.d/20-usb-vendor-model.hwdb b/hwdb.d/20-usb-vendor-model.hwdb
8d419f
index f40a3947c7..9f457d9f65 100644
8d419f
--- a/hwdb.d/20-usb-vendor-model.hwdb
8d419f
+++ b/hwdb.d/20-usb-vendor-model.hwdb
8d419f
@@ -69815,9 +69815,6 @@ usb:v8087p8008*
8d419f
 usb:v8087p800A*
8d419f
  ID_MODEL_FROM_DATABASE=Hub
8d419f
 
8d419f
-usb:v8087p8087*
8d419f
- ID_MODEL_FROM_DATABASE=07da  Centrino Advanced-N 6235
8d419f
-
8d419f
 usb:v80EE*
8d419f
  ID_VENDOR_FROM_DATABASE=VirtualBox
8d419f
 
8d419f
diff --git a/hwdb.d/ids_parser.py b/hwdb.d/ids_parser.py
8d419f
index 0ce79cd97e..811c12559b 100755
8d419f
--- a/hwdb.d/ids_parser.py
8d419f
+++ b/hwdb.d/ids_parser.py
8d419f
@@ -6,7 +6,7 @@ import sys
8d419f
 from pyparsing import (Word, White, Literal, Regex,
8d419f
                        LineEnd, SkipTo,
8d419f
                        ZeroOrMore, OneOrMore, Combine, Optional, Suppress,
8d419f
-                       Group,
8d419f
+                       Group, ParserElement,
8d419f
                        stringEnd, pythonStyleComment)
8d419f
 
8d419f
 EOL = LineEnd().suppress()
8d419f
@@ -20,6 +20,8 @@ COMMENTLINE = pythonStyleComment + EOL
8d419f
 EMPTYLINE = LineEnd()
8d419f
 text_eol = lambda name: Regex(r'[^\n]+')(name) + EOL
8d419f
 
8d419f
+ParserElement.set_default_whitespace_chars(' \n')
8d419f
+
8d419f
 def klass_grammar():
8d419f
     klass_line = Literal('C ').suppress() + NUM2('klass') + text_eol('text')
8d419f
     subclass_line = TAB + NUM2('subclass') + text_eol('text')
8d419f
@@ -35,8 +37,12 @@ def klass_grammar():
8d419f
 def usb_ids_grammar():
8d419f
     vendor_line = NUM4('vendor') + text_eol('text')
8d419f
     device_line = TAB + NUM4('device') + text_eol('text')
8d419f
+    interface_line = TAB + TAB + NUM4('interface') + NUM4('interface2') + text_eol('text')
8d419f
+    device = (device_line +
8d419f
+              ZeroOrMore(Group(interface_line)
8d419f
+                         ^ COMMENTLINE.suppress()))
8d419f
     vendor = (vendor_line('VENDOR') +
8d419f
-              ZeroOrMore(Group(device_line)('VENDOR_DEV*') ^ COMMENTLINE.suppress()))
8d419f
+              ZeroOrMore(Group(device)('VENDOR_DEV*') ^ COMMENTLINE.suppress()))
8d419f
 
8d419f
     klass = klass_grammar()
8d419f