[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] Simple pyGTK Augeas viewer



I was playing around with the python augeas bindings.

Attached is a simple pygtk app that lets you browse the full Augeas
tree, in a two column Path/Value treeview.

It's very simplistic: it gathers data from the full tree on startup,
rather than trying to do it on demand, so it takes a few seconds to
start on my laptop.

Hope this is helpful
Dave

from augeas import Augeas
import pygtk
pygtk.require('2.0')
import gtk

class AugeasViewer:
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    def populate_tree_store(self, path, parent_iter):
        iter = self.treestore.append(parent_iter, [path, self.aug.get(path)])
        try:
            child_paths = self.aug.match(path+'/*')
        except RuntimeError:
            return
        for path in child_paths:
            self.populate_tree_store(path, iter),

    def __init__(self):
        self.aug = Augeas()

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Augeas viewer")

        self.window.set_size_request(500, 400)

        self.window.connect("delete_event", self.delete_event)

        self.treestore = gtk.TreeStore(str, str)
        self.populate_tree_store('/', None)

        self.treeview = gtk.TreeView(self.treestore)

        for (i, columnName) in enumerate(['Path', 'Value']):
            column = gtk.TreeViewColumn(columnName)

            self.treeview.append_column(column)

            cr = gtk.CellRendererText()
            column.pack_start(cr, True)

            column.add_attribute(cr, 'text', i)
            column.set_sort_column_id(i)

        self.treeview.set_search_column(0)            

        sw = gtk.ScrolledWindow()
        sw.add(self.treeview)
        self.window.add(sw)

        self.window.show_all()


if __name__ == "__main__":
   app = AugeasViewer()
   gtk.main()

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]