[kernel-team] 85/86: kconfigeditor/kconfig/config.py: Use regex to parse kconfig files.

debian-kernel at lists.debian.org debian-kernel at lists.debian.org
Mon Dec 21 00:35:02 UTC 2015


This is an automated email from the git hooks/post-receive script.

benh pushed a commit to branch benh/kconfigeditor2
in repository kernel-team.

commit 4d01794357df7d36d48558123f3e92e280ed385e
Author: Bastian Blank <waldi at debian.org>
Date:   Mon Sep 23 22:08:43 2013 +0000

    kconfigeditor/kconfig/config.py: Use regex to parse kconfig files.
    
    svn path=/people/waldi/utils/kconfigeditor2/; revision=20671
---
 .../kconfigeditor2/kconfigeditor/kconfig/config.py | 40 ++++++++++++++--------
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/utils/kconfigeditor2/kconfigeditor/kconfig/config.py b/utils/kconfigeditor2/kconfigeditor/kconfig/config.py
index 73f50ad..814b3a6 100644
--- a/utils/kconfigeditor2/kconfigeditor/kconfig/config.py
+++ b/utils/kconfigeditor2/kconfigeditor/kconfig/config.py
@@ -1,6 +1,7 @@
 from __future__ import absolute_import
 
 import os
+import re
 
 from .menu import MenuEntryChoice, MenuEntryConfig
 
@@ -118,29 +119,40 @@ class FileReader(object):
             self.reset()
             return ret
 
+    rules = r'''
+        ^
+        (
+            CONFIG_(?P<name>[^=]+)=(?P<value>.*)
+            |
+            \#\ CONFIG_(?P<name_disabled>[^ ]+)\ is\ not\ set
+            |
+            \#\.\ (?P<comment>.*)
+            |
+            \#\#.*
+            |
+        )
+        $
+    '''
+    _re = re.compile(rules, re.X)
 
     @classmethod
     def read(cls, f):
         state = cls.State()
 
         for line in iter(f.readlines()):
-            line = line.strip()
+            match = cls._re.match(line.strip())
 
-            if line.startswith("CONFIG_"):
-                i = line.find('=')
-                state.name = line[7:i]
-                state.value = line[i+1:]
-                yield state.entry_reset()
+            if match:
+                name = match.group('name') or match.group('name_disabled')
+                comment = match.group('comment')
 
-            elif line.startswith("# CONFIG_"):
-                state.name = line[9:-11]
-                yield state.entry_reset()
+                if name:
+                    state.name = name
+                    state.value = match.group('value')
+                    yield state.entry_reset()
 
-            elif line.startswith("#. "):
-                state.comments.append(line[3:])
-
-            elif line.startswith("#") or not line:
-                pass
+                elif comment:
+                    state.comments.append(comment)
 
             else:
                 raise RuntimeError("Can't recognize %s" % line)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/kernel/kernel-team.git



More information about the Kernel-svn-changes mailing list