[polari/wip/fmuellner/tracker: 4/15] tool: Add polari-log-tool helper tool
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/fmuellner/tracker: 4/15] tool: Add polari-log-tool helper tool
- Date: Sun, 24 Feb 2019 13:41:33 +0000 (UTC)
commit bdbb172371c263d8aca6c518b1258c4fad5fef1e
Author: Florian Müllner <fmuellner gnome org>
Date: Sun Jul 23 03:15:57 2017 +0200
tool: Add polari-log-tool helper tool
For debugging, it's helpful to be able to easily run queries against
Polari's DB, so add a small CLI tool to allow that.
src/meson.build | 8 +++-
src/polari-log-tool.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 116 insertions(+), 1 deletion(-)
---
diff --git a/src/meson.build b/src/meson.build
index c71156b..97ffa63 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -101,10 +101,16 @@ libpolari = shared_library('polari-1.0', libsources + lib_nongir_sources + lib_r
libpolari_dep = declare_dependency(
include_directories: include_directories('lib'),
- dependencies: [gio, gtk3, telepathy_glib],
+ dependencies: [gio, gtk3, telepathy_glib, tracker],
link_with: libpolari
)
+polari_log_tool = executable('polari-log-tool', 'polari-log-tool.c',
+ dependencies: libpolari_dep,
+ install_rpath: pkglibdir,
+ install: true
+)
+
gnome.generate_gir(libpolari,
sources: libsources,
nsversion: '1.0',
diff --git a/src/polari-log-tool.c b/src/polari-log-tool.c
new file mode 100644
index 0000000..57a7f61
--- /dev/null
+++ b/src/polari-log-tool.c
@@ -0,0 +1,109 @@
+/* polari-tpl-importer.c
+ *
+ * Copyright (C) 2017 Florian Müllner <fmuellner gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "lib/polari-util.h"
+
+static guint status = 0;
+
+static int
+handle_query (int argc,
+ char *argv[])
+{
+ TrackerSparqlConnection *connection;
+ TrackerSparqlCursor *cursor;
+ GError *error = NULL;
+ char *sparql;
+
+ connection = polari_util_get_tracker_connection (NULL);
+
+ sparql = argv[1];
+
+ cursor = tracker_sparql_connection_query (connection, sparql, NULL, &error);
+
+ if (error)
+ {
+ g_printerr ("%s", error->message);
+ g_error_free (error);
+ return 1;
+ }
+
+ while (tracker_sparql_cursor_next (cursor, NULL, NULL))
+ {
+ int i;
+
+ for (i = 0; i < tracker_sparql_cursor_get_n_columns (cursor); i++)
+ {
+ switch (tracker_sparql_cursor_get_value_type (cursor, i))
+ {
+ case TRACKER_SPARQL_VALUE_TYPE_STRING:
+ case TRACKER_SPARQL_VALUE_TYPE_DATETIME:
+ case TRACKER_SPARQL_VALUE_TYPE_URI:
+ g_print ("%s\t", tracker_sparql_cursor_get_string (cursor, i, NULL));
+ break;
+ case TRACKER_SPARQL_VALUE_TYPE_INTEGER:
+ g_print ("%ld\t", tracker_sparql_cursor_get_integer (cursor, i));
+ break;
+ case TRACKER_SPARQL_VALUE_TYPE_DOUBLE:
+ g_print ("%.3f\t", tracker_sparql_cursor_get_double (cursor, i));
+ break;
+ case TRACKER_SPARQL_VALUE_TYPE_BOOLEAN:
+ g_print ("%s\t", tracker_sparql_cursor_get_boolean (cursor, i) ? "true" : "false");
+ case TRACKER_SPARQL_VALUE_TYPE_BLANK_NODE:
+ case TRACKER_SPARQL_VALUE_TYPE_UNBOUND:
+ g_print ("\t");
+ break;
+ }
+ g_print ("\n");
+ }
+ }
+
+ return status;
+}
+
+static void
+usage ()
+{
+ g_printerr ("Usage:\n");
+ g_printerr (" polari-log-tool COMMAND ARGS\n");
+ g_printerr ("\n");
+ g_printerr ("Commands:\n");
+ g_printerr (" query Run a sparql query\n");
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ const char *command;
+
+ g_set_prgname ("polari-log-tool");
+ g_set_application_name ("Polari Log Tool");
+
+ if (argc < 2)
+ {
+ usage ();
+ return 1;
+ }
+
+ command = argv[1];
+ argc -= 1;
+ argv += 1;
+
+ if (g_str_equal (command, "query"))
+ return handle_query (argc, argv);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]