[tracker/tracker-0.10] utils/tracker-resdump: Added tool to dump a resource as TTL
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.10] utils/tracker-resdump: Added tool to dump a resource as TTL
- Date: Wed, 2 Mar 2011 14:45:16 +0000 (UTC)
commit b13473b179236158d28eef01ef16ef2872d1f7f8
Author: Philip Van Hoof <philip codeminded be>
Date: Mon Feb 21 15:51:46 2011 +0100
utils/tracker-resdump: Added tool to dump a resource as TTL
configure.ac | 14 ++++
utils/Makefile.am | 4 +
utils/tracker-resdump/.gitignore | 2 +
utils/tracker-resdump/Makefile.am | 33 ++++++++
utils/tracker-resdump/tracker-resdump.vala | 118 ++++++++++++++++++++++++++++
5 files changed, 171 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 48c1989..9f0e402 100644
--- a/configure.ac
+++ b/configure.ac
@@ -305,6 +305,13 @@ PKG_CHECK_MODULES(TRACKER_EXPLORER, [$TRACKER_EXPLORER_REQUIRED],
[have_tracker_explorer=yes],
[have_tracker_explorer=no])
+TRACKER_RESDUMP_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
+ gee-1.0 >= $GEE_REQUIRED"
+
+PKG_CHECK_MODULES(TRACKER_RESDUMP, [$TRACKER_RESDUMP_REQUIRED],
+ [have_tracker_resdump=yes],
+ [have_tracker_resdump=no])
+
# Check requirements for tracker-store
TRACKER_STORE_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
gio-unix-2.0 >= $GLIB_REQUIRED
@@ -1290,6 +1297,12 @@ fi
AM_CONDITIONAL(HAVE_TRACKER_EXPLORER, test "$have_tracker_explorer" = "yes")
+##################################################################
+# Check for tracker-resdump
+##################################################################
+
+AM_CONDITIONAL(HAVE_TRACKER_RESDUMP, test "$have_tracker_resdump" = "yes")
+
####################################################################
####################################################################
####################################################################
@@ -2093,6 +2106,7 @@ AC_CONFIG_FILES([
utils/data-generators/cc/Makefile
utils/mtp/Makefile
utils/tracker-sql/Makefile
+ utils/tracker-resdump/Makefile
examples/Makefile
examples/libtracker-extract/Makefile
examples/libtracker-miner/Makefile
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 4081411..80ca573 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -11,3 +11,7 @@ SUBDIRS = \
if HAVE_TOTEM_PL_PARSER
SUBDIRS += playlists
endif
+
+if HAVE_TRACKER_RESDUMP
+SUBDIRS += tracker-resdump
+endif
diff --git a/utils/tracker-resdump/.gitignore b/utils/tracker-resdump/.gitignore
new file mode 100644
index 0000000..704302e
--- /dev/null
+++ b/utils/tracker-resdump/.gitignore
@@ -0,0 +1,2 @@
+tracker-resdump
+tracker-resdump.c
diff --git a/utils/tracker-resdump/Makefile.am b/utils/tracker-resdump/Makefile.am
new file mode 100644
index 0000000..d2c63ef
--- /dev/null
+++ b/utils/tracker-resdump/Makefile.am
@@ -0,0 +1,33 @@
+include $(top_srcdir)/Makefile.decl
+
+noinst_PROGRAMS = tracker-resdump
+
+AM_VALAFLAGS = \
+ --pkg gio-2.0 \
+ --pkg gee-1.0 \
+ $(BUILD_VALAFLAGS) \
+ $(top_srcdir)/src/libtracker-sparql/tracker-sparql-$(TRACKER_API_VERSION).vapi \
+ $(top_srcdir)/src/libtracker-bus/tracker-bus.vapi
+
+AM_CPPFLAGS =\
+ $(BUILD_CFLAGS) \
+ -I$(top_srcdir)/src \
+ -I$(top_builddir)/src \
+ $(LIBTRACKER_SPARQL_CFLAGS) \
+ $(TRACKER_RESDUMP_CFLAGS)
+
+LDADD =\
+ $(top_builddir)/src/libtracker-data/libtracker-data.la \
+ $(top_builddir)/src/libtracker-direct/libtracker-direct.la \
+ $(top_builddir)/src/libtracker-bus/libtracker-bus.la \
+ $(top_builddir)/src/libtracker-sparql/libtracker-sparql-$(TRACKER_API_VERSION).la \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(BUILD_LIBS)\
+ $(LIBTRACKER_SPARQL_LIBS) \
+ $(TRACKER_RESDUMP_LIBS)
+
+tracker_resdump_SOURCES = tracker-resdump.vala
+tracker_resdump_CFLAGS = $(AM_CPPFLAGS)
+tracker_resdump_VALAFLAGS = $(AM_VALAFLAGS)
+tracker_resdump_LDADD = $(LDADD)
+
diff --git a/utils/tracker-resdump/tracker-resdump.vala b/utils/tracker-resdump/tracker-resdump.vala
new file mode 100644
index 0000000..4d75818
--- /dev/null
+++ b/utils/tracker-resdump/tracker-resdump.vala
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2010, Nokia
+ *
+ * This library 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 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+using Tracker.Sparql;
+
+static Connection conn;
+
+static void usage (string[] args) {
+ stderr.printf("Usage: %s urn\n", args[0]);
+}
+
+static Gee.Set<string> looked_up_iris;
+
+static bool dump_resource (string urn) {
+ Gee.List<string> iris_to_lookup = new Gee.ArrayList<string> ();
+
+ looked_up_iris.add (urn);
+
+ try {
+ Cursor cursor = conn.query ("SELECT ?p rdfs:range(?p) ?o {<%s> ?p ?o}".printf (urn));
+
+ Gee.List<string> type_statements = new Gee.ArrayList<string>();
+ Gee.List<string> statements = new Gee.ArrayList<string>();
+
+ while (cursor.next ()) {
+ // Skip tracker internal stuff
+ if (cursor.get_string (0).has_prefix ("http://www.tracker-project.org/ontologies/tracker#")) {
+ continue;
+ }
+
+ string statement = "<%s> <%s> ".printf (urn, cursor.get_string (0));
+
+ switch (cursor.get_string(1)) {
+ case "http://www.w3.org/2001/XMLSchema#string":
+ case "http://www.w3.org/2001/XMLSchema#dateTime":
+ statement += "\"%s\"".printf (escape_string (cursor.get_string (2)));
+ break;
+ case "http://www.w3.org/2001/XMLSchema#integer":
+ case "http://www.w3.org/2001/XMLSchema#double":
+ case "http://www.w3.org/2001/XMLSchema#boolean":
+ statement += "%s".printf (cursor.get_string (2));
+ break;
+ default:
+ // Assume resource
+ unowned string obj = cursor.get_string (2);
+ if (!looked_up_iris.contains (obj)) {
+ iris_to_lookup.add (obj);
+ }
+ statement += "<%s>".printf (obj);
+ break;
+ }
+
+ if (cursor.get_string (0) == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") {
+ type_statements.add (statement);
+ } else {
+ statements.add (statement);
+ }
+ }
+
+ foreach (string s in type_statements) {
+ stdout.printf ("%s .\n", s);
+ }
+
+ foreach (string s in statements) {
+ stdout.printf ("%s .\n", s);
+ }
+
+ foreach (string s in iris_to_lookup) {
+ if (!dump_resource (s)) {
+ return false;
+ }
+ }
+ } catch (GLib.Error e) {
+ critical ("Couldn't query info for resource %s: %s", urn, e.message);
+ return false;
+ }
+
+ return true;
+}
+
+static int main(string[] args)
+{
+ if (args.length != 2) {
+ usage (args);
+ return 1;
+ }
+
+ try {
+ conn = Connection.get();
+ } catch (GLib.Error e) {
+ critical("Couldn't connect to Tracker: %s", e.message);
+ return 1;
+ }
+
+ looked_up_iris = new Gee.HashSet<string>();
+
+ if (dump_resource (args[1])) {
+ return 0;
+ }
+
+ return 1;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]