ia64/xen-unstable

changeset 16069:56b543dd0da2

xsview: a xenstore viewer written in PyQT.
From: Mark Williamson <mark.williamson@cl.cam.ac.uk>
Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Thu Oct 04 13:52:51 2007 +0100 (2007-10-04)
parents 062fe1c7b09f
children 65c4977850d7
files tools/misc/Makefile tools/misc/xsview tools/python/setup.py tools/python/xen/xsview/main.py tools/python/xen/xsview/xsviewer.py
line diff
     1.1 --- a/tools/misc/Makefile	Thu Oct 04 10:31:44 2007 +0100
     1.2 +++ b/tools/misc/Makefile	Thu Oct 04 13:52:51 2007 +0100
     1.3 @@ -14,7 +14,7 @@ TARGETS-$(CONFIG_X86) += xen-detect
     1.4  TARGETS := $(TARGETS-y)
     1.5  
     1.6  INSTALL_BIN  = $(TARGETS) xencons
     1.7 -INSTALL_SBIN = netfix xm xen-bugtool xen-python-path xend xenperf
     1.8 +INSTALL_SBIN = netfix xm xen-bugtool xen-python-path xend xenperf xsview
     1.9  
    1.10  .PHONY: all
    1.11  all: build
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/misc/xsview	Thu Oct 04 13:52:51 2007 +0100
     2.3 @@ -0,0 +1,11 @@
     2.4 +#!/usr/bin/env python
     2.5 +
     2.6 +import sys
     2.7 +
     2.8 +sys.path.append('/usr/lib/python')
     2.9 +sys.path.append('/usr/lib64/python')
    2.10 +from xen.xsview import main
    2.11 +
    2.12 +main.main(sys.argv)
    2.13 +
    2.14 +
     3.1 --- a/tools/python/setup.py	Thu Oct 04 10:31:44 2007 +0100
     3.2 +++ b/tools/python/setup.py	Thu Oct 04 13:52:51 2007 +0100
     3.3 @@ -79,6 +79,7 @@ setup(name            = 'xen',
     3.4                           'xen.xm',
     3.5                           'xen.web',
     3.6                           'xen.sv',
     3.7 +                         'xen.xsview',
     3.8  
     3.9                           'xen.xend.tests',
    3.10                           'xen.xend.server.tests',
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/python/xen/xsview/main.py	Thu Oct 04 13:52:51 2007 +0100
     4.3 @@ -0,0 +1,10 @@
     4.4 +from xsviewer import *
     4.5 +from qt import *
     4.6 +
     4.7 +def main(args):
     4.8 +    app = QApplication(args)
     4.9 +    mainwin = XSViewer(app)
    4.10 +    mainwin.show()
    4.11 +    app.connect(app, SIGNAL("lastWindowClosed()"),
    4.12 +                app, SLOT("quit()"))
    4.13 +    app.exec_loop()
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/python/xen/xsview/xsviewer.py	Thu Oct 04 13:52:51 2007 +0100
     5.3 @@ -0,0 +1,168 @@
     5.4 +from qt import *
     5.5 +
     5.6 +import xen.lowlevel.xs
     5.7 +
     5.8 +class XSViewer(QMainWindow):
     5.9 +    
    5.10 +    def __init__(self, app):
    5.11 +        apply(QMainWindow.__init__, (self,))
    5.12 +        
    5.13 +        self.setCaption('XenStore Viewer')
    5.14 +
    5.15 +        self.new_node = QAction(self, 'New Node')
    5.16 +        self.new_node.setText('New Node...')
    5.17 +        self.connect(self.new_node, SIGNAL('activated()'),
    5.18 +                     self.do_new_node)
    5.19 +        
    5.20 +        self.rm_node = QAction(self, 'Remove Node')
    5.21 +        self.rm_node.setText('Remove Node')
    5.22 +        self.connect(self.rm_node, SIGNAL('activated()'),
    5.23 +                     self.do_rm_node)
    5.24 +
    5.25 +        self.refresh = QAction(self, 'Refresh')
    5.26 +        self.refresh.setText('Refresh')
    5.27 +        self.connect(self.refresh, SIGNAL('activated()'),
    5.28 +                     self.do_refresh)
    5.29 + 
    5.30 +        self.file_menu = QPopupMenu(self)
    5.31 +        self.new_node.addTo(self.file_menu)
    5.32 +        self.rm_node.addTo(self.file_menu)
    5.33 +        self.refresh.addTo(self.file_menu)
    5.34 +
    5.35 +
    5.36 +        self.about = QAction(self, 'About')
    5.37 +        self.about.setText('About...')
    5.38 +        self.connect(self.about, SIGNAL('activated()'),
    5.39 +                     self.do_about)
    5.40 +
    5.41 +        self.help_menu = QPopupMenu(self)
    5.42 +        self.about.addTo(self.help_menu)
    5.43 +
    5.44 +        self.menubar = QMenuBar(self)
    5.45 +        self.menubar.insertItem('&File', self.file_menu)
    5.46 +        self.menubar.insertItem('&Help', self.help_menu)
    5.47 +
    5.48 +        self.vbox = QVBox(self)
    5.49 +        self.setCentralWidget(self.vbox)
    5.50 +
    5.51 +        self.xs_tree = QListView(self.vbox)
    5.52 +        self.xs_tree.addColumn('Key')
    5.53 +        self.xs_tree.setRootIsDecorated(1)
    5.54 +        self.xs_tree.connect(self.xs_tree, SIGNAL('selectionChanged(QListViewItem*)'), self.showValue)
    5.55 +
    5.56 +        self.info_box = QHBox(self.vbox)
    5.57 +        self.info_box.setMargin(2)
    5.58 +        self.info_box.setSpacing(2)
    5.59 +        self.info_label = QLabel(self.info_box)
    5.60 +        self.info_label.setText('Value')
    5.61 +        self.info = QLineEdit(self.info_box)
    5.62 +        self.setval = QPushButton(self.info_box)
    5.63 +        self.setval.setText('Set')
    5.64 +        self.setval.connect(self.setval, SIGNAL('clicked()'), self.setValue)
    5.65 +
    5.66 +        self.xs_handle = xen.lowlevel.xs.xs()
    5.67 +
    5.68 +        self.showtree()
    5.69 +
    5.70 +
    5.71 +    def showtree(self):
    5.72 +        xstransact = self.xs_handle.transaction_start()
    5.73 +        self.walktree(xstransact, '/', '/', self.xs_tree)
    5.74 +        self.xs_handle.transaction_end(xstransact)
    5.75 +
    5.76 +    def walktree(self, trans, node, subdir_prepend, parent_widget):
    5.77 +
    5.78 +        ents = self.xs_handle.ls(trans, node)
    5.79 +        if ents == None:
    5.80 +            return
    5.81 +
    5.82 +        for e in ents:
    5.83 +            i = QListViewItem(parent_widget, e)
    5.84 +            i.full_path = subdir_prepend + e
    5.85 +            self.walktree(trans, i.full_path, i.full_path + '/', i)
    5.86 +
    5.87 +    
    5.88 +    def showValue(self, item):
    5.89 +        trans = self.xs_handle.transaction_start()
    5.90 +        val = self.xs_handle.read(trans, item.full_path)
    5.91 +        self.info.setText(val)
    5.92 +        self.xs_handle.transaction_end(trans)
    5.93 +
    5.94 +
    5.95 +    def setValue(self):
    5.96 +        trans = self.xs_handle.transaction_start()
    5.97 +        item = self.xs_tree.currentItem()
    5.98 +        newval = str(self.info.text())
    5.99 +
   5.100 +        self.xs_handle.write(trans, item.full_path, newval)
   5.101 +
   5.102 +        self.xs_handle.transaction_end(trans)
   5.103 +
   5.104 +
   5.105 +    def do_refresh(self):
   5.106 +        self.xs_tree.clear()
   5.107 +        self.info.clear()
   5.108 +        self.showtree()
   5.109 +
   5.110 +    def do_new_node(self):
   5.111 +        dia = QDialog(self)
   5.112 +        dia.setCaption('Create new node')
   5.113 +
   5.114 +        vbox = QVBox(dia)
   5.115 +
   5.116 +        setting_hbox = QHBox(vbox)
   5.117 +        
   5.118 +        path_label = QLabel(setting_hbox)
   5.119 +        path_label.setText('Node path')
   5.120 +        path = QLineEdit(setting_hbox)
   5.121 +        
   5.122 +        value_label = QLabel(setting_hbox)
   5.123 +        value_label.setText('Node value')
   5.124 +        val = QLineEdit(setting_hbox)
   5.125 +
   5.126 +        button_hbox = QHBox(vbox)
   5.127 +
   5.128 +        set = QPushButton(button_hbox)
   5.129 +        set.setText('Set')
   5.130 +        self.connect(set, SIGNAL('clicked()'), dia, SLOT('accept()'))
   5.131 +
   5.132 +        cancel = QPushButton(button_hbox)
   5.133 +        cancel.setText('Cancel')
   5.134 +        self.connect(cancel, SIGNAL('clicked()'), dia, SLOT('reject()'))
   5.135 +
   5.136 +        setting_hbox.adjustSize()
   5.137 +        button_hbox.adjustSize()
   5.138 +        vbox.adjustSize()
   5.139 +
   5.140 +        if dia.exec_loop() == QDialog.Accepted:
   5.141 +            trans = self.xs_handle.transaction_start()
   5.142 +            self.xs_handle.write(trans, str(path.text()), str(val.text()))
   5.143 +            
   5.144 +            self.xs_handle.transaction_end(trans)
   5.145 +
   5.146 +            self.do_refresh()
   5.147 +        
   5.148 +        # nothing to set.
   5.149 +
   5.150 +    def do_rm_node(self):
   5.151 +        trans = self.xs_handle.transaction_start()
   5.152 +        item = self.xs_tree.currentItem()
   5.153 +        newval = str(self.info.text())
   5.154 +
   5.155 +        self.xs_handle.rm(trans, item.full_path)
   5.156 +
   5.157 +        self.xs_handle.transaction_end(trans)
   5.158 +
   5.159 +        self.do_refresh()
   5.160 +
   5.161 +    def do_about(self):
   5.162 +        about_dia = QMessageBox(self)
   5.163 +        about_dia.setIcon(QMessageBox.Information)
   5.164 +
   5.165 +        about_dia.setCaption('About XenStore Viewer')
   5.166 +        about_dia.setText('XenStore Viewer\n'
   5.167 +                          'by Mark Williamson <mark.williamson@cl.cam.ac.uk>')
   5.168 +
   5.169 +        about_dia.exec_loop()
   5.170 +        
   5.171 +