[kernel] r5951 - people/waldi/utils/kconfigeditor/kconfigeditor

Bastian Blank waldi at costa.debian.org
Tue Feb 21 11:26:09 UTC 2006


Author: waldi
Date: Tue Feb 21 11:26:08 2006
New Revision: 5951

Modified:
   people/waldi/utils/kconfigeditor/kconfigeditor/file.py
Log:
kconfigeditor/file.py: Retain comments.


Modified: people/waldi/utils/kconfigeditor/kconfigeditor/file.py
==============================================================================
--- people/waldi/utils/kconfigeditor/kconfigeditor/file.py	(original)
+++ people/waldi/utils/kconfigeditor/kconfigeditor/file.py	Tue Feb 21 11:26:08 2006
@@ -2,38 +2,61 @@
 from debian_linux.utils import sorted_dict
 
 class kconfigfile(sorted_dict):
+    __slots__ = '_list_comments',
+
     def __init__(self, filename):
         super(kconfigfile, self).__init__()
         self.filename = filename
+        self._list_comments = []
         f = file(filename)
         for line in iter(f.readlines()):
             line = line.strip()
             if not line:
-                pass
+                self._list_comments.append((False, line))
             elif line.startswith("CONFIG_"):
                 i = line.find('=')
                 option = line[7:i]
                 value = line[i+1:]
                 self[option] = value
+                if (True, option) not in self._list_comments:
+                    raise
             elif line.startswith("# CONFIG_"):
                 option = line[9:-11]
                 self[option] = 'n'
             elif line.startswith("#"):
-                pass
+                self._list_comments.append((False, line))
             else:
                 raise RuntimeError, "Can't recognize %s" % line
 
+    def __delitem__(self, key):
+        super(kconfigfile, self).__delitem__(key)
+        self._list_comments.remove((True, key))
+
+    def __setitem__(self, key, value):
+        super(kconfigfile, self).__setitem__(key, value)
+        real_key = True, key
+        if real_key not in self._list_comments:
+            self._list_comments.append(real_key)
+
+    def str_iter(self):
+        for item, key in iter(self._list_comments):
+            if item:
+                value = self[key]
+                if value == 'n':
+                    yield "# CONFIG_%s is not set\n" % key
+                else:
+                    yield "CONFIG_%s=%s\n" % (key, value)
+            else:
+                yield key + '\n'
+
     def write(self):
         try:
             os.unlink(self.filename + "~")
         except OSError: pass
         os.link(self.filename, self.filename + "~")
         f = file(self.filename, "w")
-        for key, value in self.iteritems():
-            if value == 'n':
-                f.write("# CONFIG_%s is not set\n" % key)
-            else:
-                f.write("CONFIG_%s=%s\n" % (key, value))
+        for str in self.str_iter():
+            f.write(str)
 
 if __name__ == '__main__':
     import sys



More information about the Kernel-svn-changes mailing list