[Ocfs2-tools-commits] manish commits r565 - trunk/ocfs2tool

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Thu Jan 20 19:46:19 CST 2005


Author: manish
Date: 2005-01-20 19:46:17 -0600 (Thu, 20 Jan 2005)
New Revision: 565

Modified:
   trunk/ocfs2tool/format.py
   trunk/ocfs2tool/interface.py
   trunk/ocfs2tool/ocfs2module.c
   trunk/ocfs2tool/ocfsplist.c
   trunk/ocfs2tool/ocfsplist.h
   trunk/ocfs2tool/toolbar.py
Log:
Add filtering support


Modified: trunk/ocfs2tool/format.py
===================================================================
--- trunk/ocfs2tool/format.py	2005-01-21 00:38:09 UTC (rev 564)
+++ trunk/ocfs2tool/format.py	2005-01-21 01:46:17 UTC (rev 565)
@@ -144,7 +144,7 @@
 )
 
 def format_partition(parent, device):
-    partitions = ocfs2.partition_list(True)
+    partitions = ocfs2.partition_list(unmounted=True)
 
     if not partitions:
         error_box(parent, 'No unmounted partitions')

Modified: trunk/ocfs2tool/interface.py
===================================================================
--- trunk/ocfs2tool/interface.py	2005-01-21 00:38:09 UTC (rev 564)
+++ trunk/ocfs2tool/interface.py	2005-01-21 01:46:17 UTC (rev 565)
@@ -111,6 +111,8 @@
         self.mount_button.set_sensitive(False)
         self.unmount_button.set_sensitive(False)
 
+        filter = self.filter_entry.get_text()
+
         old_device = self.get_device()
 
         store = gtk.ListStore(str, str)
@@ -119,7 +121,7 @@
         sel = self.get_selection()
         selected = False
 
-        for partition in ocfs2.partition_list():
+        for partition in ocfs2.partition_list(filter=filter):
             iter = store.append(partition)
 
             if partition[0] == old_device:
@@ -204,6 +206,9 @@
 def clconfig(pv):
     cluster_configurator(pv.toplevel)
 
+def filter_update(entry, pv):
+    refresh(pv)
+
 def create_window():
     window = gtk.Window()
     set_props(window, title='OCFS2 Tool',
@@ -225,12 +230,14 @@
 
     toolbar = Toolbar(mount=mount, unmount=unmount, refresh=refresh)
 
-    tb, buttons = toolbar.get_widgets(pv)
+    tb, buttons, pv.filter_entry = toolbar.get_widgets(pv)
     vbox.pack_start(tb, expand=False, fill=False)
 
     for k, v in buttons.iteritems():
         setattr(pv, k + '_button', v)
- 
+
+    pv.filter_entry.connect('activate', filter_update, pv)
+
     vpaned = gtk.VPaned()
     vpaned.set_border_width(4)
     vbox.pack_start(vpaned, expand=True, fill=True)

Modified: trunk/ocfs2tool/ocfs2module.c
===================================================================
--- trunk/ocfs2tool/ocfs2module.c	2005-01-21 00:38:09 UTC (rev 564)
+++ trunk/ocfs2tool/ocfs2module.c	2005-01-21 01:46:17 UTC (rev 565)
@@ -41,17 +41,23 @@
 
 static PyObject *
 partition_list (PyObject *self,
-		PyObject *args)
+		PyObject *args,
+		PyObject *kwargs)
 {
+  gchar             *filter = NULL;
   gboolean           unmounted = FALSE, bail = FALSE;
   GList             *list, *last;
   PyObject          *ret, *val;
   OcfsPartitionInfo *info;
 
-  if (!PyArg_ParseTuple (args, "|i:partition_list", &unmounted))
+  static gchar *kwlist[] = { "filter", "unmounted" };
+
+  if (!PyArg_ParseTupleAndKeywords (args, kwargs,
+				    "|si:partition_list", kwlist,
+				    &filter, &unmounted))
     return NULL;
 
-  list = ocfs_partition_list (unmounted);
+  list = ocfs_partition_list (filter, unmounted);
 
   ret = PyList_New (0);
   if (ret == NULL)
@@ -191,7 +197,7 @@
 }
 
 static PyMethodDef ocfs2_methods[] = {
-  {"partition_list", partition_list, METH_VARARGS},
+  {"partition_list", partition_list, METH_VARARGS | METH_KEYWORDS},
   {"get_super", get_super, METH_VARARGS},
   {NULL,       NULL}    /* sentinel */
 };

Modified: trunk/ocfs2tool/ocfsplist.c
===================================================================
--- trunk/ocfs2tool/ocfsplist.c	2005-01-21 00:38:09 UTC (rev 564)
+++ trunk/ocfs2tool/ocfsplist.c	2005-01-21 01:46:17 UTC (rev 565)
@@ -43,18 +43,21 @@
 
 struct _BuildData
 {
-  gboolean  unmounted;
-  GList    *list;
+  GPatternSpec *filter;
+  gboolean      unmounted;
+
+  GList        *list;
 };
 
 
-static gboolean is_ocfs2_partition  (const gchar *device);
-static gboolean valid_device        (const gchar *device,
-				     gboolean     no_ocfs_check);
-static void     partition_info_fill (GHashTable  *info);
-static gboolean list_builder        (gpointer     key,
-				     gpointer     value,
-				     gpointer     user_data);
+static gboolean is_ocfs2_partition  (const gchar  *device);
+static gboolean valid_device        (const gchar  *device,
+				     GPatternSpec *filter,
+				     gboolean      no_ocfs_check);
+static void     partition_info_fill (GHashTable   *info);
+static gboolean list_builder        (gpointer      key,
+				     gpointer      value,
+				     gpointer      user_data);
 
 
 static gboolean
@@ -73,8 +76,9 @@
 }
 
 static gboolean
-valid_device (const gchar *device,
-	      gboolean     no_ocfs_check)
+valid_device (const gchar  *device,
+              GPatternSpec *filter,
+	      gboolean      no_ocfs_check)
 {
   gboolean     is_bad = FALSE;
   struct stat  sbuf;
@@ -82,6 +86,9 @@
   gchar        buf[100], *proc, *d;
   gint         i, fd;
 
+  if (filter && !g_pattern_match_string (filter, device))
+    return FALSE;
+
   if ((stat (device, &sbuf) != 0) ||
       (!S_ISBLK (sbuf.st_mode)) ||
       ((sbuf.st_mode & 0222) == 0))
@@ -203,7 +210,7 @@
     {
       device = list->data;
 
-      if (valid_device (device, bdata->unmounted))
+      if (valid_device (device, bdata->filter, bdata->unmounted))
 	{
 	  info = g_new (OcfsPartitionInfo, 1);
 
@@ -265,11 +272,15 @@
 #endif
 
 GList *
-ocfs_partition_list (gboolean unmounted)
+ocfs_partition_list (const gchar *filter,
+                     gboolean     unmounted)
 {
   GHashTable *info;
-  BuildData   bdata = { unmounted, NULL };
+  BuildData   bdata = { NULL, unmounted, NULL };
 
+  if (filter && *filter)
+    bdata.filter = g_pattern_spec_new (filter);
+
   info = g_hash_table_new (g_str_hash, g_str_equal);
 
   partition_info_fill (info);
@@ -295,7 +306,7 @@
 
   g_print ("All:\n");
 
-  plist = ocfs_partition_list (FALSE);
+  plist = ocfs_partition_list (NULL, FALSE);
   
   for (list = plist; list; list = list->next)
     {

Modified: trunk/ocfs2tool/ocfsplist.h
===================================================================
--- trunk/ocfs2tool/ocfsplist.h	2005-01-21 00:38:09 UTC (rev 564)
+++ trunk/ocfs2tool/ocfsplist.h	2005-01-21 01:46:17 UTC (rev 565)
@@ -38,7 +38,8 @@
 };
 
 
-GList *ocfs_partition_list (gboolean unmounted);
+GList *ocfs_partition_list (const gchar *filter,
+                            gboolean     unmounted);
 
 
 #endif /* __OCFS_PARTITION_LIST_H__ */

Modified: trunk/ocfs2tool/toolbar.py
===================================================================
--- trunk/ocfs2tool/toolbar.py	2005-01-21 00:38:09 UTC (rev 564)
+++ trunk/ocfs2tool/toolbar.py	2005-01-21 01:46:17 UTC (rev 565)
@@ -50,10 +50,8 @@
         filter_box, entry = self.get_filter_box()
         toolbar.append_widget(filter_box, 'Partition name filter', None)
 
-        items['filter'] = entry
+        return toolbar, items, entry
 
-        return toolbar, items
-
     def get_filter_box(self):
         hbox = gtk.HBox(False, 4)
 



More information about the Ocfs2-tools-commits mailing list