[Ocfs2-tools-commits] manish commits r736 - in trunk: .
ocfs2console/ocfs2interface
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri Mar 25 18:05:26 CST 2005
Author: manish
Date: 2005-03-25 18:05:24 -0600 (Fri, 25 Mar 2005)
New Revision: 736
Added:
trunk/ocfs2console/ocfs2interface/ipwidget.py
Modified:
trunk/CREDITS
trunk/ocfs2console/ocfs2interface/clconfig.py
Log:
Use ipwidget from anaconda for add node dialog
Modified: trunk/CREDITS
===================================================================
--- trunk/CREDITS 2005-03-26 00:03:00 UTC (rev 735)
+++ trunk/CREDITS 2005-03-26 00:05:24 UTC (rev 736)
@@ -31,3 +31,6 @@
ocfs2console/blkid:
From e2fsprogs 1.36, by Theodore Ts'o and Andreas Dilger.
+
+ocfs2console/ocfs2interface/ipwidget.py:
+ From anaconda 10.1.1.13, by Jonathan Blandford and Michael Fulbright
Modified: trunk/ocfs2console/ocfs2interface/clconfig.py
===================================================================
--- trunk/ocfs2console/ocfs2interface/clconfig.py 2005-03-26 00:03:00 UTC (rev 735)
+++ trunk/ocfs2console/ocfs2interface/clconfig.py 2005-03-26 00:05:24 UTC (rev 736)
@@ -24,13 +24,14 @@
from guiutil import set_props, error_box
from process import Process
+from ipwidget import IPEditor, IPMissing, IPError
COLUMN_NAME, COLUMN_NODE, COLUMN_IP_ADDR, COLUMN_IP_PORT = range(4)
fields = (
(COLUMN_NAME, 'Name', gtk.Entry),
(COLUMN_NODE, 'Node', None),
- (COLUMN_IP_ADDR, 'IP Address', gtk.Entry),
+ (COLUMN_IP_ADDR, 'IP Address', IPEditor),
(COLUMN_IP_PORT, 'IP Port', gtk.SpinButton)
)
@@ -71,9 +72,9 @@
button.connect('clicked', self.add_node)
vbbox.add(button)
-# button = gtk.Button(stock=gtk.STOCK_APPLY)
-# button.connect('clicked', self.apply_changes)
-# vbbox.add(button)
+ button = gtk.Button(stock=gtk.STOCK_APPLY)
+ button.connect('clicked', self.apply_changes)
+ vbbox.add(button)
def get_cluster_state(self):
command = 'o2cb_ctl -I -t node -o'
@@ -150,16 +151,20 @@
return
name = widgets[COLUMN_NAME].get_text()
- ip_addr = widgets[COLUMN_IP_ADDR].get_text()
- ip_port = widgets[COLUMN_IP_PORT].get_text()
if not name:
error_box(dialog, 'Node name not specified')
- elif not ip_addr:
- error_box(dialog, 'IP address not specified')
- else:
- break
+ continue
+ try:
+ ip_addr = widgets[COLUMN_IP_ADDR].get_text()
+ except (IPMissing, IPError), msg:
+ error_box(dialog, msg[0])
+ continue
+
+ ip_port = widgets[COLUMN_IP_PORT].get_text()
+ break
+
dialog.destroy()
command = ('o2cb_ctl', '-C', '-n', name, '-t', 'node',
@@ -226,8 +231,7 @@
success, output, k = o2cb_ctl.reap()
if not success:
- error_box(self.toplevel,
- '%s\nCould not create cluster' % output)
+ error_box(parent, '%s\nCould not create cluster' % output)
return
try:
Added: trunk/ocfs2console/ocfs2interface/ipwidget.py
===================================================================
--- trunk/ocfs2console/ocfs2interface/ipwidget.py 2005-03-26 00:03:00 UTC (rev 735)
+++ trunk/ocfs2console/ocfs2interface/ipwidget.py 2005-03-26 00:05:24 UTC (rev 736)
@@ -0,0 +1,168 @@
+#
+# class to create an IP address entry widget and to sanity check entered values
+#
+# Jonathan Blandford <jrb at redhat.com>
+# Michael Fulbright <msf at redhat.com>
+#
+# Copyright 2002 Red Hat, Inc.
+#
+# This software may be freely redistributed under the terms of the GNU
+# library public license.
+#
+# You should have received a copy of the GNU Library Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+# Modified by Manish Singh <manish.singh at oracle.com>
+
+import re
+import string
+import gtk
+import gobject
+
+# we're not gettexted - Manish
+def _(text):
+ return text
+
+# The below is from network.py from anaconda
+#
+# Matt Wilson <ewt at redhat.com>
+# Erik Troan <ewt at redhat.com>
+# Mike Fulbright <msf at redhat.com>
+# Brent Fox <bfox at redhat.com>
+#
+# Copyright 2001-2003 Red Hat, Inc.
+#
+# sanity check an IP string. if valid, returns octets, if invalid, return None
+def sanityCheckIPString(ip_string):
+ ip_re = re.compile('^([0-2]?[0-9]?[0-9])\\.([0-2]?[0-9]?[0-9])\\.([0-2]?[0-9]?[0-9])\\.([0-2]?[0-9]?[0-9])$')
+
+ #Sanity check the string
+ m = ip_re.match (ip_string)
+ try:
+ if not m:
+ return None
+ octets = m.groups()
+ if len(octets) != 4:
+ return None
+ for octet in octets:
+ if (int(octet) < 0) or (int(octet) > 255):
+ return None
+ except TypeError:
+ return None
+
+ return octets
+
+ip_fields = ['entry1', 'entry2', 'entry3', 'entry4']
+
+# Includes an error message, and the widget with problems
+class IPError(Exception):
+ pass
+
+class IPMissing(Exception):
+ pass
+
+class IPEditor(gtk.HBox):
+ def __init__ (self):
+ gtk.HBox.__init__(self)
+
+ self.entrys = {}
+ for name in ip_fields:
+ self.entrys[name] = gtk.Entry(3)
+ self.entrys[name].set_size_request(50,-1)
+ self.entrys[name].set_max_length(3)
+
+ for i in range(0, len(ip_fields)):
+ name = ip_fields[i]
+ if name != 'entry4':
+ nname = self.entrys[ip_fields[i+1]]
+ else:
+ nname = None
+
+ self.entrys[name].connect('insert_text', self.entry_insert_text_cb, nname)
+
+ for name in ip_fields:
+ self.pack_start(self.entrys[name], gtk.FALSE, gtk.FALSE)
+ if name != 'entry4':
+ self.pack_start(gtk.Label('.'), gtk.FALSE, gtk.FALSE)
+
+ def getFocusableWidget(self):
+ return self.entrys['entry1']
+
+ def clear_entries (self):
+ for name in ip_fields:
+ self.entrys[name].set_text('')
+
+ def hydrate (self, ip_string):
+ self.clear_entries()
+
+ octets = sanityCheckIPString(ip_string)
+ if octets is None:
+ return
+
+ i = 0
+ for name in ip_fields:
+ self.entrys[name].set_text(octets[i])
+ i = i + 1
+
+ def dehydrate (self):
+ widget = None
+ # test if empty
+ empty = 1
+ for e in ['entry1', 'entry2', 'entry3', 'entry4']:
+ if len(string.strip(self.entrys[e].get_text())) > 0:
+ empty = 0
+ break
+
+ if empty:
+ raise IPMissing, (_("IP Address is missing"), widget)
+
+ try:
+ widget = self.entrys['entry1']
+ if int(widget.get_text()) > 255 or int(widget.get_text()) <= 0:
+ raise IPError, (_("IP Addresses must contain numbers between 1 and 255"), widget)
+
+ for ent in ['entry2', 'entry3', 'entry4']:
+ widget = self.entrys[ent]
+ if int(widget.get_text()) > 255:
+ raise IPError, (_("IP Addresses must contain numbers between 0 and 255"), widget)
+ except ValueError, msg:
+ raise IPError, (_("IP Addresses must contain numbers between 0 and 255"), widget)
+
+ return self.entrys['entry1'].get_text() + "." + self.entrys['entry2'].get_text() + "." +self.entrys['entry3'].get_text() + "." +self.entrys['entry4'].get_text()
+
+ def entry_insert_text_cb(self, entry, text, length, pos, next):
+ if text == '.':
+ entry.emit_stop_by_name ("insert_text")
+ if next:
+ next.grab_focus()
+ return
+ reg = re.compile ("[^0-9]+")
+ if reg.match (text):
+ entry.emit_stop_by_name ("insert_text")
+
+ get_text = dehydrate
+
+
+
+if __name__ == "__main__":
+ def output(xxx, data):
+ try:
+ print data.dehydrate()
+ except:
+ print "oops errors"
+ gtk.mainquit()
+
+ win = gtk.Window()
+ win.connect('destroy', gtk.mainquit)
+ vbox = gtk.VBox()
+ ip = IPEditor()
+ vbox = gtk.VBox()
+ vbox.pack_start(ip)
+ button = gtk.Button("Quit")
+ button.connect("pressed", output, ip)
+ vbox.pack_start(button, gtk.FALSE, gtk.FALSE)
+ win.add(vbox)
+ win.show_all()
+ gtk.main()
+
More information about the Ocfs2-tools-commits
mailing list