[tracker] tracker-info: Add --resource-is-uri | -i to avoid filename -> urn lookups
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] tracker-info: Add --resource-is-uri | -i to avoid filename -> urn lookups
- Date: Fri, 27 Jun 2014 09:27:04 +0000 (UTC)
commit 622721e93fb91f0f6ed562e9ad93990e2e64814a
Author: Martyn Russell <martyn lanedo com>
Date: Fri Jun 27 08:46:01 2014 +0100
tracker-info: Add --resource-is-uri | -i to avoid filename -> urn lookups
docs/manpages/tracker-info.1 | 14 +++++++++++++
src/tracker-utils/tracker-info.c | 40 ++++++++++++++++++++++---------------
2 files changed, 38 insertions(+), 16 deletions(-)
---
diff --git a/docs/manpages/tracker-info.1 b/docs/manpages/tracker-info.1
index db68cfb..6dbc97c 100644
--- a/docs/manpages/tracker-info.1
+++ b/docs/manpages/tracker-info.1
@@ -39,6 +39,20 @@ 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 \-i, \-\-resource-is-iri
+In most cases, the \fIFILE\fR argument supplied points to a URL or
+PATH which is queried for according to the resource associated with it
+by \fInie:url\fR. However, in cases where the \fIFILE\fR specified
+turns out to be the actual URN itself, this argument is required to
+tell \fBtracker-info\fR not to do the extra step of looking up the URN
+related by \fInie:url\fR.
+
+For example, consider that you store URNs by the actual URL itself and
+use the unique nie:url in another resource (which is quite reasonable
+when using containers and multi-resource conditions), you would need
+this argument to tell \fBtracker-info\fR that the \fIFILE\fR supplied
+is actually a URN not URL.
+.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 90b7768..4eda511 100644
--- a/src/tracker-utils/tracker-info.c
+++ b/src/tracker-utils/tracker-info.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2006, Jamie McCracken <jamiemcc gnome org>
* Copyright (C) 2008-2010, Nokia <ivan frade nokia com>
+ * Copyright (C) 2014, SoftAtHome <contact softathome com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -44,6 +45,7 @@ static gchar **filenames;
static gboolean full_namespaces;
static gboolean print_version;
static gboolean plain_text_content;
+static gboolean resource_is_iri;
static gboolean turtle;
static GOptionEntry entries[] = {
@@ -59,6 +61,10 @@ static GOptionEntry entries[] = {
N_("Show plain text content if available for resources"),
NULL,
},
+ { "resource-is-iri", 'i', 0, G_OPTION_ARG_NONE, &resource_is_iri,
+ N_("Instead of looking up a file name, treat the FILE arguments as actual IRIs (e.g.
<file:///path/to/some/file.txt>)"),
+ NULL,
+ },
{ "turtle", 't', 0, G_OPTION_ARG_NONE, &turtle,
N_("Output results as RDF in Turtle format"),
NULL,
@@ -395,19 +401,21 @@ main (int argc, char **argv)
}
for (p = filenames; *p; p++) {
- TrackerSparqlCursor *cursor;
+ TrackerSparqlCursor *cursor = NULL;
GError *error = NULL;
- gchar *uri;
+ gchar *uri = NULL;
gchar *query;
gchar *urn = NULL;
- if (!turtle) {
+ if (!turtle && !resource_is_iri) {
g_print ("%s:'%s'\n", _("Querying information for entity"), *p);
}
/* support both, URIs and local file paths */
if (has_valid_uri_scheme (*p)) {
uri = g_strdup (*p);
+ } else if (resource_is_iri) {
+ uri = g_strdup (*p);
} else {
GFile *file;
@@ -416,26 +424,26 @@ main (int argc, char **argv)
g_object_unref (file);
}
- /* First check whether there's some entity with nie:url like this */
- query = g_strdup_printf ("SELECT ?urn WHERE { ?urn nie:url \"%s\" }", uri);
- cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
- g_free (query);
-
- if (error) {
- g_printerr (" %s, %s\n",
- _("Unable to retrieve URN for URI"),
- error->message);
+ if (!resource_is_iri) {
+ /* First check whether there's some entity with nie:url like this */
+ query = g_strdup_printf ("SELECT ?urn WHERE { ?urn nie:url \"%s\" }", uri);
+ cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
+ g_free (query);
- g_clear_error (&error);
- continue;
+ if (error) {
+ g_printerr (" %s, %s\n",
+ _("Unable to retrieve URN for URI"),
+ error->message);
+ g_clear_error (&error);
+ continue;
+ }
}
if (!cursor || !tracker_sparql_cursor_next (cursor, NULL, &error)) {
if (error) {
g_printerr (" %s, %s\n",
_("Unable to retrieve data for URI"),
- error->message);
-
+ error->message);
g_object_unref (cursor);
g_clear_error (&error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]