本文整理汇总了Python中augeas.Augeas.info方法的典型用法代码示例。如果您正苦于以下问题:Python Augeas.info方法的具体用法?Python Augeas.info怎么用?Python Augeas.info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类augeas.Augeas
的用法示例。
在下文中一共展示了Augeas.info方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_event
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import info [as 别名]
class AugeasEditor:
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def populate_tree_store(self, path, parent_iter):
iter = self.tree_store.append(parent_iter, [path, self.aug.get(path)])
if path == "/":
path = ""
try:
child_paths = self.aug.match(path+'/*')
except RuntimeError:
return
for path in child_paths:
self.populate_tree_store(path, iter),
def setup_tags(self, spec):
buf = self.textview.get_buffer()
tbl = buf.get_tag_table()
tag = tbl.lookup("value")
if not tag:
tag = gtk.TextTag("value")
tag.set_property("background-gdk", gtk.gdk.Color(65535,54400,42000,0))
tbl.add(tag)
tag = tbl.lookup("label")
if not tag:
tag = gtk.TextTag("label")
tag.set_property("background-gdk", gtk.gdk.Color(65535,42000,54400,1))
tbl.add(tag)
def __init__(self):
self.aug = Augeas()
self.cur_file = ""
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.tree_store = gtk.TreeStore(str, str)
self.populate_tree_store('/', None)
self.treeview = gtk.TreeView(self.tree_store)
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)
self.textview = gtk.TextView()
self.setup_tags(None)
hbox = gtk.HBox()
add_with_scrolling(hbox, self.treeview)
add_with_scrolling(hbox, self.textview)
self.window.add(hbox)
self.treeview.get_selection().connect('changed', self.on_selection_changed, self)
self.window.show_all()
def on_selection_changed(self, selection, foo):
(model, iter) = selection.get_selected()
if (iter == None):
return
path = model.get_value(iter, 0)
if not path.startswith('/files/'):
return
try:
res = self.aug.info(path)
except ValueError:
return
if os.path.isfile(res["filename"]) and res["filename"] != self.cur_file:
print "set content to %s" % (res["filename"])
content = open(res["filename"]).read()
buf = self.textview.get_buffer()
buf.set_text(content)
self.cur_file = res["filename"]
buf = self.textview.get_buffer()
tbl = buf.get_tag_table()
label_tag = tbl.lookup("label")
value_tag = tbl.lookup("value")
buf.remove_all_tags(buf.get_iter_at_offset(0), buf.get_iter_at_offset(buf.get_char_count()))
print "apply tag"
#.........这里部分代码省略.........