Author: waldi
Date: Fri Mar 14 19:47:00 2008
New Revision: 10863

Log:
lib/kconfigeditor/kconfig/package/files.py: Support per-option comments.


Modified:
   people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/package/files.py

Modified: 
people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/package/files.py
==============================================================================
--- 
people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/package/files.py    
    (original)
+++ 
people/waldi/utils/kconfigeditor2/lib/kconfigeditor/kconfig/package/files.py    
    Fri Mar 14 19:47:00 2008
@@ -134,7 +134,7 @@
                 ignored.add(i.name)
                 return []
         processed.add(i.name)
-        return [e]
+        return e.dump()
 
     def _dump_file(self, processed, ignored, have_prompt, f):
         ret = []
@@ -206,46 +206,68 @@
             fd.write(str(i) + "\n")
 
     def read(self, f):
+        comments = []
+
         for line in iter(f.readlines()):
             line = line.strip()
+
             if line.startswith("CONFIG_"):
                 i = line.find('=')
                 option = line[7:i]
                 value = line[i+1:]
                 if value in ('y', 'm', 'n'):
-                    entry = FileEntryTristate(option, value)
+                    entry = FileEntryTristate(option, value, comments)
                 else:
-                    entry = FileEntryString(option, value)
+                    entry = FileEntryString(option, value, comments)
                 self[option] = entry
+                comments = []
+
             elif line.startswith("# CONFIG_"):
                 option = line[9:-11]
-                self[option] = FileEntryTristate(option)
+                self[option] = FileEntryTristate(option, 'n', comments)
+                comments = []
+
+            elif line.startswith("#. "):
+                comments.append(line[3:])
+
             elif line.startswith("#") or not line:
                 pass
+
             else:
                 raise RuntimeError, "Can't recognize %s" % line
 
+class FileEntry(object):
+    __slots__ = "name", "comments"
+
+    def __init__(self, name, comments):
+        self.name, self.comments = name, comments
+
+    def dump(self):
+        ret = ["#. %s" % i for i in self.comments]
+        ret.append(str(self))
+        return ret
+
 # TODO
-class FileEntryString(object):
-    __slots__ = "name", "value"
+class FileEntryString(FileEntry):
+    __slots__ = "value"
 
-    def __init__(self, name, value):
-        self.name = name
+    def __init__(self, name, value, comments):
+        super(FileEntryString, self).__init__(name, comments)
         self.value = value
 
     def __str__(self):
         return "CONFIG_%s=%s" % (self.name, self.value)
 
 # TODO
-class FileEntryTristate(object):
-    __slots__ = "name", "value"
+class FileEntryTristate(FileEntry):
+    __slots__ = "name", "value", "comments"
 
     VALUE_NO = 0
     VALUE_YES = 1
     VALUE_MOD = 2
 
-    def __init__(self, name, value = None):
-        self.name = name
+    def __init__(self, name, value, comments):
+        super(FileEntryTristate, self).__init__(name, comments)
         if value == 'n' or value is None:
             self.value = self.VALUE_NO
         elif value == 'y':

_______________________________________________
Kernel-svn-changes mailing list
Kernel-svn-changes@lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/kernel-svn-changes

Reply via email to