[tracker/tracker-0.14] tracker-info: Added --plain-text-content || -c option



commit e6731f2d65db17e584d8ed302b33be07f932544b
Author: Martyn Russell <martyn lanedo com>
Date:   Wed Oct 17 12:03:57 2012 +0100

    tracker-info: Added --plain-text-content || -c option
    
    To show nie:plainTextContent for resources. By default this is disabled.

 docs/manpages/tracker-info.1     |    6 +++++
 src/tracker-utils/tracker-info.c |   47 ++++++++++++++++++++++++++++++-------
 2 files changed, 44 insertions(+), 9 deletions(-)
---
diff --git a/docs/manpages/tracker-info.1 b/docs/manpages/tracker-info.1
index cde9cff..48fd819 100644
--- a/docs/manpages/tracker-info.1
+++ b/docs/manpages/tracker-info.1
@@ -33,6 +33,12 @@ This makes things much easier to see generally and the output is less
 cluttered. This option reverses that so FULL namespaces are shown
 instead.
 .TP
+.B \-c, \-\-plain\-text\-content
+If the resource being displayed has nie:PlainTextContent (i.e.
+information about the content of the resource, which could be the
+contents of a file on the disk), then this option displays that in the
+output.
+.TP
 .B \-t, \-\-turtle
 Output results as Turtle RDF. If \-f is enabled, full URIs are shown
 for subjects, predicates and objects; otherwise, shortened URIs are
diff --git a/src/tracker-utils/tracker-info.c b/src/tracker-utils/tracker-info.c
index dceb73d..753d867 100644
--- a/src/tracker-utils/tracker-info.c
+++ b/src/tracker-utils/tracker-info.c
@@ -43,6 +43,7 @@
 static gchar **filenames;
 static gboolean full_namespaces;
 static gboolean print_version;
+static gboolean plain_text_content;
 static gboolean turtle;
 
 static GOptionEntry entries[] = {
@@ -54,6 +55,10 @@ static GOptionEntry entries[] = {
 	  N_("Show full namespaces (i.e. don't use nie:title, use full URLs)"),
 	  NULL,
 	},
+	{ "plain-text-content", 'c', 0, G_OPTION_ARG_NONE, &plain_text_content,
+	  N_("Show plain text content if available for resources"),
+	  NULL,
+	},
 	{ "turtle", 't', 0, G_OPTION_ARG_NONE, &turtle,
 	  N_("Output results as RDF in Turtle format"),
 	  NULL,
@@ -167,6 +172,22 @@ get_prefixes (TrackerSparqlConnection *connection)
 	return retval;
 }
 
+static inline void
+print_key_and_value (GHashTable  *prefixes,
+                     const gchar *key,
+                     const gchar *value)
+{
+	if (G_UNLIKELY (full_namespaces)) {
+		g_print ("  '%s' = '%s'\n", key, value);
+	} else {
+		gchar *shorthand;
+
+		shorthand = get_shorthand (prefixes, key);
+		g_print ("  '%s' = '%s'\n", shorthand, value);
+		g_free (shorthand);
+	}
+}
+
 static void
 print_plain (gchar               *urn_or_filename,
              gchar               *urn,
@@ -174,6 +195,9 @@ print_plain (gchar               *urn_or_filename,
              GHashTable          *prefixes,
              gboolean             full_namespaces)
 {
+	gchar *fts_key = NULL;
+	gchar *fts_value = NULL;
+
 	while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
 		const gchar *key = tracker_sparql_cursor_get_string (cursor, 0, NULL);
 		const gchar *value = tracker_sparql_cursor_get_string (cursor, 1, NULL);
@@ -184,19 +208,24 @@ print_plain (gchar               *urn_or_filename,
 
 		/* Don't display nie:plainTextContent */
 		if (strcmp (key, "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent";) == 0) {
+			if (plain_text_content) {
+				fts_key = g_strdup (key);
+				fts_value = g_strdup (value);
+			}
+
+			/* Always print FTS data at the end because of it's length */
 			continue;
 		}
 
-		if (G_UNLIKELY (full_namespaces)) {
-			g_print ("  '%s' = '%s'\n", key, value);
-		} else {
-			gchar *shorthand;
+		print_key_and_value (prefixes, key, value);
+	}
 
-			shorthand = get_shorthand (prefixes, key);
-			g_print ("  '%s' = '%s'\n", shorthand, value);
-			g_free (shorthand);
-		}
+	if (fts_key && fts_value) {
+		print_key_and_value (prefixes, fts_key, fts_value);
 	}
+
+	g_free (fts_key);
+	g_free (fts_value);
 }
 
 /* print a URI prefix in Turtle format */
@@ -273,7 +302,7 @@ print_turtle (gchar               *urn,
 		}
 
 		/* Don't display nie:plainTextContent */
-		if (strcmp (key, "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent";) == 0) {
+		if (!plain_text_content && strcmp (key, "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent";) == 0) {
 			continue;
 		}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]