[tracker/sam/cli-graphs: 1/2] cli: Add `tracker sparql --list-graphs` option



commit 72ab6fb759e05a1b0a811fdcd22c924f1c84b5b5
Author: Sam Thursfield <sam afuera me uk>
Date:   Mon May 11 01:32:49 2020 +0200

    cli: Add `tracker sparql --list-graphs` option

 docs/manpages/tracker-sparql.1.txt |  5 ++++-
 src/tracker/tracker-sparql.c       | 30 ++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)
---
diff --git a/docs/manpages/tracker-sparql.1.txt b/docs/manpages/tracker-sparql.1.txt
index 1df1d7200..d943de5dd 100644
--- a/docs/manpages/tracker-sparql.1.txt
+++ b/docs/manpages/tracker-sparql.1.txt
@@ -88,7 +88,10 @@ See also *--tree* and *--query*.
   _property_ does not have to be supplied here. This is optional and
   filters the results according to any argument supplied. With no
   _property_, all properties are listed.
-
+* -g, --list-graphs::
+  List all the named graphs in the database. These are used by the
+  filesystem miner to separate metadata so that apps can only see
+  the information relevant to them.
 *-t, --tree=[_class_]*::
   Prints a tree showing all parent classes of _class_ in the ontology.
   The _class_ can be provided in shorthand or longhand (see
diff --git a/src/tracker/tracker-sparql.c b/src/tracker/tracker-sparql.c
index 736c7581d..ed51640d6 100644
--- a/src/tracker/tracker-sparql.c
+++ b/src/tracker/tracker-sparql.c
@@ -40,6 +40,7 @@
         list_properties || \
         list_notifies || \
         list_indexes || \
+        list_graphs || \
         tree || \
         search || \
         get_shorthand || \
@@ -94,6 +95,7 @@ static gboolean list_class_prefixes;
 static gchar *list_properties;
 static gchar *list_notifies;
 static gchar *list_indexes;
+static gchar *list_graphs;
 static gchar *tree;
 static gchar *get_shorthand;
 static gchar *get_longhand;
@@ -147,6 +149,10 @@ static GOptionEntry entries[] = {
          N_("Retrieve indexes used in database to improve performance (PROPERTY is optional)"),
          N_("PROPERTY"),
        },
+       { "list-graphs", 'g', 0, G_OPTION_ARG_NONE, &list_graphs,
+         N_("Retrieve all named graphs"),
+         NULL,
+       },
        { "tree", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, parse_tree,
          N_("Describe subclasses, superclasses (can be used with -s to highlight parts of the tree and -p to 
show properties)"),
          N_("CLASS"),
@@ -1288,6 +1294,30 @@ sparql_run (void)
                print_cursor (cursor, _("No indexes were found"), _("Indexes"), TRUE);
        }
 
+       if (list_graphs) {
+               const gchar *query;
+
+               /* First list classes */
+               query = g_strdup_printf ("SELECT DISTINCT ?g "
+                                        "WHERE {"
+                                        "  GRAPH ?g { ?s ?p ?o }"
+                                        "}");
+
+               cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
+
+               if (error) {
+                       g_printerr ("%s, %s\n",
+                                   _("Could not list named graphs"),
+                                   error->message);
+                       g_error_free (error);
+                       g_object_unref (connection);
+
+                       return EXIT_FAILURE;
+               }
+
+               print_cursor (cursor, _("No graphs were found"), _("Named graphs"), TRUE);
+       }
+
        if (tree) {
                return tree_get (connection, tree, search);
        }


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