[libgda] Added a more human readable output to the gda-list-server-op tool
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Added a more human readable output to the gda-list-server-op tool
- Date: Tue, 19 Oct 2010 20:18:38 +0000 (UTC)
commit a1d26068658d5381985312971a48c22b8a6f10de
Author: Vivien Malerba <malerba gnome-db org>
Date: Tue Oct 19 20:32:26 2010 +0200
Added a more human readable output to the gda-list-server-op tool
tools/Makefile.am | 4 +-
tools/gda-list-server-op.c | 39 +++++++--
tools/gda-tree-mgr-xml.c | 205 ++++++++++++++++++++++++++++++++++++++++++++
tools/gda-tree-mgr-xml.h | 56 ++++++++++++
4 files changed, 294 insertions(+), 10 deletions(-)
---
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 4873813..3065085 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -67,7 +67,9 @@ gda-sql-res.o: gda-sql-res.rc
$(WINDRES) $^ -o $@
gda_list_server_op_4_0_SOURCES = \
- gda-list-server-op.c
+ gda-list-server-op.c \
+ gda-tree-mgr-xml.c \
+ gda-tree-mgr-xml.h
gda_list_server_op_4_0_LDADD = \
$(top_builddir)/libgda/libgda-4.0.la \
diff --git a/tools/gda-list-server-op.c b/tools/gda-list-server-op.c
index 37daa68..6676684 100644
--- a/tools/gda-list-server-op.c
+++ b/tools/gda-list-server-op.c
@@ -5,16 +5,19 @@
#include <libgda/libgda.h>
#include <libgda/binreloc/gda-binreloc.h>
#include <glib/gi18n-lib.h>
+#include "gda-tree-mgr-xml.h"
gchar *prov = NULL;
gchar *op = NULL;
gboolean list_ops = FALSE;
+gboolean out_tree = FALSE;
GdaServerProvider *prov_obj = NULL;
static GOptionEntry entries[] = {
{ "provider", 'p', 0, G_OPTION_ARG_STRING, &prov, "Provider name", "provider"},
{ "op", 'o', 0, G_OPTION_ARG_STRING, &op, "Operation", "operation name"},
{ "list-ops", 'l', 0, G_OPTION_ARG_NONE, &list_ops, "List existing operations", NULL },
+ { "tree", 't', 0, G_OPTION_ARG_NONE, &out_tree, "Output results as a tree (default is as XML)", NULL },
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
@@ -75,12 +78,27 @@ main (int argc, char **argv) {
g_print (_("Description for type: %s\n"), gda_server_operation_op_type_to_string (type));
doc = merge_specs (xml_dir, type, &op_supported, &error);
if (doc) {
- xmlChar *buf;
- gint len;
- xmlKeepBlanksDefault (0);
- xmlDocDumpFormatMemory (doc, &buf, &len, 1);
- g_print ("%s\n", buf);
- xmlFree (buf);
+ if (out_tree) {
+ GdaTree *tree;
+ GdaTreeManager *mgr;
+
+ tree = gda_tree_new ();
+ mgr = gda_tree_mgr_xml_new (xmlDocGetRootElement (doc), "prov_name|id|name|gdatype|node_type|descr");
+ gda_tree_add_manager (tree, mgr);
+ gda_tree_manager_add_manager (mgr, mgr);
+ g_object_unref (mgr);
+ gda_tree_update_all (tree, NULL);
+ gda_tree_dump (tree, NULL, NULL);
+ g_object_unref (tree);
+ }
+ else {
+ xmlChar *buf;
+ gint len;
+ xmlKeepBlanksDefault (0);
+ xmlDocDumpFormatMemory (doc, &buf, &len, 1);
+ g_print ("%s\n", buf);
+ xmlFree (buf);
+ }
xmlFreeDoc (doc);
}
else {
@@ -191,7 +209,6 @@ make_paths (xmlNodePtr node, const gchar *parent_path, GSList *exist_list)
for (child = node->children; child; child = child->next)
retlist = make_paths (child, pstr, retlist);
-
xmlFree (id);
}
else {
@@ -330,8 +347,12 @@ merge_specs (const gchar *xml_dir, GdaServerOperationType type, gboolean *op_sup
provider_end = g_strrstr (provider, suffix);
*provider_end = 0;
- if (lcprov && strcmp (lcprov, provider))
- continue;
+ if (lcprov && strcmp (lcprov, provider)) {
+ /* handle the name mismatch between the provider named "PostgreSQL" and
+ * the file names which start with "postgres" */
+ if (strcmp (provider, "postgres") || strcmp (lcprov, "postgresql"))
+ continue;
+ }
*op_supported = TRUE;
pdoc = xmlParseFile (cfile);
diff --git a/tools/gda-tree-mgr-xml.c b/tools/gda-tree-mgr-xml.c
new file mode 100644
index 0000000..45ed02d
--- /dev/null
+++ b/tools/gda-tree-mgr-xml.c
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2010 The GNOME Foundation.
+ *
+ * AUTHORS:
+ * Vivien Malerba <malerba gnome-db org>
+ *
+ * This Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this Library; see the file COPYING.LIB. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <glib/gi18n-lib.h>
+#include <libgda/libgda.h>
+#include <sql-parser/gda-sql-parser.h>
+#include "gda-tree-mgr-xml.h"
+#include "gda-tree-node.h"
+
+struct _GdaTreeMgrXmlPriv {
+ xmlNodePtr root;
+ gchar **attributes;
+};
+
+static void gda_tree_mgr_xml_class_init (GdaTreeMgrXmlClass *klass);
+static void gda_tree_mgr_xml_init (GdaTreeMgrXml *tmgr1, GdaTreeMgrXmlClass *klass);
+static void gda_tree_mgr_xml_dispose (GObject *object);
+
+/* virtual methods */
+static GSList *gda_tree_mgr_xml_update_children (GdaTreeManager *manager, GdaTreeNode *node,
+ const GSList *children_nodes, gboolean *out_error, GError **error);
+
+static GObjectClass *parent_class = NULL;
+
+/*
+ * GdaTreeMgrXml class implementation
+ * @klass:
+ */
+static void
+gda_tree_mgr_xml_class_init (GdaTreeMgrXmlClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ /* virtual methods */
+ ((GdaTreeManagerClass*) klass)->update_children = gda_tree_mgr_xml_update_children;
+
+ object_class->dispose = gda_tree_mgr_xml_dispose;
+}
+
+static void
+gda_tree_mgr_xml_init (GdaTreeMgrXml *mgr, G_GNUC_UNUSED GdaTreeMgrXmlClass *klass)
+{
+ g_return_if_fail (GDA_IS_TREE_MGR_XML (mgr));
+ mgr->priv = g_new0 (GdaTreeMgrXmlPriv, 1);
+}
+
+static void
+gda_tree_mgr_xml_dispose (GObject *object)
+{
+ GdaTreeMgrXml *mgr = (GdaTreeMgrXml *) object;
+
+ g_return_if_fail (GDA_IS_TREE_MGR_XML (mgr));
+
+ if (mgr->priv) {
+ if (mgr->priv->attributes)
+ g_strfreev (mgr->priv->attributes);
+ g_free (mgr->priv);
+ mgr->priv = NULL;
+ }
+
+ /* chain to parent class */
+ parent_class->dispose (object);
+}
+
+/**
+ * gda_tree_mgr_xml_get_type:
+ *
+ * Returns: the GType
+ */
+GType
+gda_tree_mgr_xml_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ static GStaticMutex registering = G_STATIC_MUTEX_INIT;
+ static const GTypeInfo info = {
+ sizeof (GdaTreeMgrXmlClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) gda_tree_mgr_xml_class_init,
+ NULL,
+ NULL,
+ sizeof (GdaTreeMgrXml),
+ 0,
+ (GInstanceInitFunc) gda_tree_mgr_xml_init,
+ 0
+ };
+
+ g_static_mutex_lock (®istering);
+ if (type == 0)
+ type = g_type_register_static (GDA_TYPE_TREE_MANAGER, "GdaTreeMgrXml", &info, 0);
+ g_static_mutex_unlock (®istering);
+ }
+ return type;
+}
+
+/**
+ * gda_tree_mgr_xml_new:
+ * rootnode: the #xmlNodePtr root
+ * xml_attributes: a string containing the XML attributes which will appear in each node, separated by the | character, or %NULL to list all attributes
+ *
+ * Creates a new #GdaTreeManager object which will add one tree node for each
+ * subnodes of an XmlNodePtr
+ *
+ * Returns: (transfer full): a new #GdaTreeManager object
+ */
+GdaTreeManager*
+gda_tree_mgr_xml_new (xmlNodePtr rootnode, const gchar *xml_attributes)
+{
+ GdaTreeMgrXml *mgr;
+ mgr = (GdaTreeMgrXml*) g_object_new (GDA_TYPE_TREE_MGR_XML, NULL);
+ mgr->priv->root = rootnode;
+ if (xml_attributes)
+ mgr->priv->attributes = g_strsplit (xml_attributes, "|", 0);
+ return (GdaTreeManager*) mgr;
+}
+
+static GSList *
+gda_tree_mgr_xml_update_children (GdaTreeManager *manager, GdaTreeNode *node,
+ G_GNUC_UNUSED const GSList *children_nodes,
+ gboolean *out_error, GError **error)
+{
+ GdaTreeMgrXml *mgr = GDA_TREE_MGR_XML (manager);
+ GSList *list = NULL;
+ xmlNodePtr xnode, child;
+ const GValue *cvalue;
+
+ cvalue = gda_tree_node_get_node_attribute (node, "xmlnode");
+ if (cvalue)
+ xnode = (xmlNodePtr) g_value_get_pointer (cvalue);
+ else
+ xnode = mgr->priv->root;
+ for (child = xnode->children; child; child = child->next) {
+ GString *string = NULL;
+ if (mgr->priv->attributes) {
+ gint i;
+ for (i = 0; ; i++) {
+ xmlChar *prop;
+ if (! mgr->priv->attributes[i])
+ break;
+ prop = xmlGetProp (child, BAD_CAST mgr->priv->attributes[i]);
+ if (!prop)
+ continue;
+ if (!string)
+ string = g_string_new ("");
+ else
+ g_string_append_c (string, ' ');
+ g_string_append_printf (string, "[%s=%s]", mgr->priv->attributes[i],
+ (gchar*) prop);
+ xmlFree (prop);
+ }
+ }
+ else {
+ /* use all attributes */
+ xmlAttrPtr attr;
+
+ for (attr = child->properties; attr; attr = attr->next) {
+ xmlChar *prop;
+ prop = xmlGetProp (child, attr->name);
+ if (!prop)
+ continue;
+ if (!string)
+ string = g_string_new ("");
+ else
+ g_string_append_c (string, ' ');
+ g_string_append_printf (string, "[%s=%s]", (gchar*) attr->name, (gchar*) prop);
+ xmlFree (prop);
+ }
+ }
+ if (string) {
+ GValue *xvalue;
+ GdaTreeNode* snode;
+ snode = gda_tree_manager_create_node (manager, node, string->str);
+ g_string_free (string, TRUE);
+ g_value_set_pointer ((xvalue = gda_value_new (G_TYPE_POINTER)), child);
+ gda_tree_node_set_node_attribute (snode, "xmlnode", xvalue, NULL);
+ gda_value_free (xvalue);
+ list = g_slist_prepend (list, snode);
+ }
+ }
+
+ return list;
+}
diff --git a/tools/gda-tree-mgr-xml.h b/tools/gda-tree-mgr-xml.h
new file mode 100644
index 0000000..b1c9c19
--- /dev/null
+++ b/tools/gda-tree-mgr-xml.h
@@ -0,0 +1,56 @@
+/* GDA library
+ * Copyright (C) 2010 The GNOME Foundation.
+ *
+ * AUTHORS:
+ * Vivien Malerba <malerba gnome-db org>
+ *
+ * This Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this Library; see the file COPYING.LIB. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GDA_TREE_MGR_XML_H__
+#define __GDA_TREE_MGR_XML_H__
+
+#include <libgda/gda-connection.h>
+#include "gda-tree-manager.h"
+
+G_BEGIN_DECLS
+
+#define GDA_TYPE_TREE_MGR_XML (gda_tree_mgr_xml_get_type())
+#define GDA_TREE_MGR_XML(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_TREE_MGR_XML, GdaTreeMgrXml))
+#define GDA_TREE_MGR_XML_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_TREE_MGR_XML, GdaTreeMgrXmlClass))
+#define GDA_IS_TREE_MGR_XML(obj) (G_TYPE_CHECK_INSTANCE_TYPE(obj, GDA_TYPE_TREE_MGR_XML))
+#define GDA_IS_TREE_MGR_XML_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GDA_TYPE_TREE_MGR_XML))
+#define GDA_TREE_MGR_XML_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDA_TYPE_TREE_MGR_XML, GdaTreeMgrXmlClass))
+
+typedef struct _GdaTreeMgrXml GdaTreeMgrXml;
+typedef struct _GdaTreeMgrXmlPriv GdaTreeMgrXmlPriv;
+typedef struct _GdaTreeMgrXmlClass GdaTreeMgrXmlClass;
+
+struct _GdaTreeMgrXml {
+ GdaTreeManager object;
+ GdaTreeMgrXmlPriv *priv;
+};
+
+struct _GdaTreeMgrXmlClass {
+ GdaTreeManagerClass object_class;
+};
+
+GType gda_tree_mgr_xml_get_type (void) G_GNUC_CONST;
+GdaTreeManager* gda_tree_mgr_xml_new (xmlNodePtr rootnode, const gchar *xml_attributes);
+
+G_END_DECLS
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]