Allow looser lspci command syntax
authorStefan Hajnoczi <stefanha@gmail.com>
Sat, 29 Aug 2009 17:40:39 +0000 (18:40 +0100)
committerStefan Hajnoczi <stefanha@gmail.com>
Sat, 29 Aug 2009 17:40:39 +0000 (18:40 +0100)
cmds.py

diff --git a/cmds.py b/cmds.py
index b3d57e0..a7bd995 100644 (file)
--- a/cmds.py
+++ b/cmds.py
@@ -88,17 +88,21 @@ def errcode_command(who, _, replyto, words):
 commands['errcode'] = errcode_command
 commands['error'] = errcode_command
 
-PCI_ID_RE = re.compile(r'([0-9a-fA-F]{4}):([0-9a-fA-F]{4})')
-
 def lspci_command(who, _, replyto, words):
     '''Look up driver for PCI ID (lspci 10ec:8139)'''
-    if len(words) != 2:
+    ids = []
+    if len(words) == 2:
+        ids = words[1].split(':')
+    elif len(words) == 3:
+        ids = words[1:3]
+    if len(ids) != 2:
         return 'PRIVMSG', (replyto, 'Invalid arguments')
 
-    m = PCI_ID_RE.match(words[1])
-    if not m:
+    try:
+        vendor_id, device_id = [int(s, 16) for s in ids]
+    except ValueError:
         return 'PRIVMSG', (replyto, 'Invalid arguments')
-    pci_id = '%s,%s' % tuple(s.lower() for s in m.groups())
+    pci_id = '%04x,%04x' % (vendor_id, device_id)
 
     try:
         for line in open(config.NICFILE):