[kernel] r5567 - in people/waldi/linux-2.6/debian: bin lib/python/debian_linux/kconfigeditor

Bastian Blank waldi at costa.debian.org
Sun Jan 22 20:28:39 UTC 2006


Author: waldi
Date: Sun Jan 22 20:28:38 2006
New Revision: 5567

Added:
   people/waldi/linux-2.6/debian/bin/kconfigeditor.py   (contents, props changed)
   people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/
   people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/__init__.py
   people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/editor.py
   people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/file.py
Log:
Add preliminary kconfig editor.

* debian/bin/kconfigeditor.py,
  debian/lib/python/debian_linux/kconfigeditor,
  debian/lib/python/debian_linux/kconfigeditor/editor.py,
  debian/lib/python/debian_linux/kconfigeditor/file.py,
  debian/lib/python/debian_linux/kconfigeditor/__init__.py: Add.


Added: people/waldi/linux-2.6/debian/bin/kconfigeditor.py
==============================================================================
--- (empty file)
+++ people/waldi/linux-2.6/debian/bin/kconfigeditor.py	Sun Jan 22 20:28:38 2006
@@ -0,0 +1,40 @@
+#!/usr/bin/env python2.4
+import sys
+sys.path.append("debian/lib/python")
+from debian_linux.config import config_reader
+from debian_linux.kconfigeditor.editor import editor
+
+import pygtk
+import gtk
+
+class editor(editor):
+    def __init__(self):
+        super(editor, self).__init__()
+
+        self.config = config_reader()
+
+        self.add_file("debian/arch/config")
+        for arch in iter(self.config['base',]['arches']):
+            if self.config['base', arch].get("available", "yes") != "yes":
+                continue
+            self.add_data(arch)
+            self.add_file("debian/arch/%s/config" % arch, arch)
+            for subarch in iter(self.config['base', arch]['subarches']):
+                if subarch == "none":
+                    self.add_data(arch, None)
+                else:
+                    self.add_data(arch, subarch)
+                    self.add_file("debian/arch/%s/%s/config" % (arch, subarch), arch, subarch)
+                for flavour in iter(self.config['base', arch, subarch]['flavours']):
+                    if subarch == "none":
+                        self.add_data(arch, None, flavour)
+                        self.add_file("debian/arch/%s/config.%s" % (arch, flavour), arch, None, flavour)
+                    else:
+                        self.add_data(arch, subarch, flavour)
+                        self.add_file("debian/arch/%s/%s/config.%s" % (arch, subarch, flavour), arch, subarch, flavour)
+
+        self.show()
+
+if __name__ == '__main__':
+    editor()
+    gtk.main()

Added: people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/__init__.py
==============================================================================

Added: people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/editor.py
==============================================================================
--- (empty file)
+++ people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/editor.py	Sun Jan 22 20:28:38 2006
@@ -0,0 +1,135 @@
+from file import kconfigfile
+
+import pygtk
+import gtk
+
+_marker = object()
+
+class items_real(kconfigfile):
+    def __getitem__(self, key):
+        return self.get(key)
+
+    def get(self, key, default = _marker):
+        value = super(items_real, self).get(key, _marker)
+        if value is _marker:
+            if default is not _marker:
+                return default
+            raise KeyError()
+        if value in ('y', 'm', 'n'):
+            return value
+        return "x"
+
+class items_ghost(object):
+    def __init__(self, real):
+        self.real = real
+
+    def get(self, key, default = _marker):
+        value = self.real.get(key, _marker)
+        if value is _marker:
+            if default is not _marker:
+                return default
+            raise KeyError()
+        return '[%s]' % value
+
+class editor(object):
+    def __init__(self):
+        self.cells = {}
+        self.columns = {}
+        self.file_inodes = {}
+        self.items = {}
+
+        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+        self.window.set_size_request(200, 200)
+        self.window.set_title("KConfig editor")
+        self.window.connect("delete_event", self.delete_event)
+        self.window.connect("destroy", self.destroy)
+
+        self.treestore = gtk.TreeStore(str)
+
+        self.treeview = gtk.TreeView(self.treestore)
+        tvoption = gtk.TreeViewColumn('Option')
+        self.treeview.append_column(tvoption)
+        cell = gtk.CellRendererText()
+        tvoption.pack_start(cell, True)
+        tvoption.add_attribute(cell, 'text', 0)
+
+        scrolledwindow = gtk.ScrolledWindow()
+        scrolledwindow.add(self.treeview)
+        self.window.add(scrolledwindow)
+
+        col = gtk.TreeViewColumn('Global')
+        self.treeview.append_column(col)
+        cell = gtk.CellRendererText()
+        col.pack_start(cell, False)
+        col.set_cell_data_func(cell, self.cell_data, (None, None, None))
+        self.cells[(None, None, None)] = cell
+        self.columns[None] = col
+
+    def add_data(self, arch, subarch = None, flavour = None):
+        if not self.columns.has_key(arch):
+            col = gtk.TreeViewColumn(arch)
+            self.treeview.append_column(col)
+            cell = gtk.CellRendererText()
+            col.pack_start(cell, False)
+            col.set_cell_data_func(cell, self.cell_data, (arch, None, None))
+            self.cells[(arch, None, None)] = cell
+            self.columns[arch] = col
+        if subarch is not None and not self.cells.has_key((arch, subarch, None)):
+            cell = gtk.CellRendererText()
+            self.columns[arch].pack_start(cell, False)
+            self.columns[arch].set_cell_data_func(cell, self.cell_data, (arch, subarch, None))
+            self.cells[(arch, subarch, None)] = cell
+        if flavour is not None and not self.cells.has_key((arch, subarch, flavour)):
+            cell = gtk.CellRendererText()
+            self.columns[arch].pack_start(cell, False)
+            self.columns[arch].set_cell_data_func(cell, self.cell_data, (arch, subarch, flavour))
+            self.cells[(arch, subarch, flavour)] = cell
+
+    def add_file(self, file, arch = None, subarch = None, flavour = None):
+        import os, stat
+        inode = os.stat(file)[stat.ST_INO]
+        if inode in self.file_inodes:
+            f = items_ghost(self.file_inodes[inode])
+        else:
+            f = items_real(file)
+            self.file_inodes[inode] = f
+        self.items[(arch, subarch, flavour)] = f
+
+    def cell_data(self, column, cell, model, iter, data):
+        key = model.get_value(iter, 0)
+        value = self.items[data].get(key, None)
+        text = ""
+        if value is not None:
+#            if data[2] is not None:
+#                if data[1] is None:
+#                    text = "%s: " % data[2]
+#                else:
+#                    text = "%s %s: " % data[1:]
+            text += str(value)
+        else:
+            text = "-"
+        cell.set_property('text', text)
+
+    def delete_event(self, widget, event, data = None):
+        return False
+
+    def destroy(self, widget, data = None):
+        gtk.main_quit()
+
+    def show(self):
+        tmp = {}
+        for i in self.items.itervalues():
+            tmp.update(i)
+        keys = tmp.keys()
+        keys.sort()
+        for key in keys:
+            self.treestore.append(None, [key])
+        self.window.show_all()
+
+if __name__ == '__main__':
+    e = editor()
+    from file import kconfigfile
+    import sys
+    e.add_file(kconfigfile(sys.argv[1]))
+    e.add_file(kconfigfile(sys.argv[1]))
+    gtk.main()

Added: people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/file.py
==============================================================================
--- (empty file)
+++ people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/file.py	Sun Jan 22 20:28:38 2006
@@ -0,0 +1,26 @@
+from debian_linux.utils import sorted_dict
+
+class kconfigfile(sorted_dict):
+    def __init__(self, filename):
+        super(kconfigfile, self).__init__()
+        f = file(filename)
+        for line in iter(f.readlines()):
+            line = line.strip()
+            if not line:
+                pass
+            elif line.startswith("CONFIG_"):
+                i = line.find('=')
+                option = line[7:i]
+                value = line[i+1:]
+                self[option] = value
+            elif line.startswith("# CONFIG_"):
+                option = line[9:-11]
+                self[option] = 'n'
+            elif line.startswith("#"):
+                pass
+            else:
+                raise RuntimeError, "Can't recognize %s" % line
+
+if __name__ == '__main__':
+    import sys
+    print kconfigfile(sys.argv[1])



More information about the Kernel-svn-changes mailing list