diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2023-01-02 12:13:04 +0100 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2023-01-10 13:02:31 +0100 |
commit | eea91637f3fb280acfb42b8e81275f3932f41324 (patch) | |
tree | d77010640a4cca14e4ff1132b2e5278da2a63a22 | |
parent | a54bbd0b7fdb843782227dd6505ac11bb3b74e0b (diff) | |
download | tracker-eea91637f3fb280acfb42b8e81275f3932f41324.tar.gz |
cli: Add --output-format argument to "tracker3 export"
And kinda deprecate the --show-graphs option that did output TriG.
We now are able to output TTL, TriG, and JSON-LD.
-rw-r--r-- | docs/manpages/tracker3-export.1.txt | 13 | ||||
-rw-r--r-- | src/tracker/tracker-export.c | 44 |
2 files changed, 44 insertions, 13 deletions
diff --git a/docs/manpages/tracker3-export.1.txt b/docs/manpages/tracker3-export.1.txt index 83e83a7e0..1d4c1129c 100644 --- a/docs/manpages/tracker3-export.1.txt +++ b/docs/manpages/tracker3-export.1.txt @@ -20,15 +20,12 @@ tool such as rapper(1) to convert the data to different formats. == OPTIONS +*-o, --output-format=<__RDF_FORMAT__>*:: + Choose which RDF format to use to output results. Supported formats are + _turtle_, _trig_ and _json-ld_. + *-g, --show-graphs*:: - Tracker can separate data into multiple graphs. This feature is used - by the filesystem miner to separate different types of content. This - flag causes the relevant GRAPH statements to be output along with - the data. - - In this mode the output is TriG syntax rather than Turtle, due to - the extra GRAPH statements. Some tools which understand Turtle do not - understand TriG. + Deprecated. Does the same than *--output-format trig*. *--2to3*:: Helper for migrating data from Tracker 2.x databases. This option diff --git a/src/tracker/tracker-export.c b/src/tracker/tracker-export.c index c9da3644e..467f98129 100644 --- a/src/tracker/tracker-export.c +++ b/src/tracker/tracker-export.c @@ -38,6 +38,7 @@ static gchar *database_path; static gchar *dbus_service; static gchar *remote_service; +static gchar *output_format; static gboolean show_graphs; static gchar **iris; static gchar *data_type = NULL; @@ -52,6 +53,10 @@ static GOptionEntry entries[] = { N_("Connects to a DBus service"), N_("DBus service name") }, + { "output", 'o', 0, G_OPTION_ARG_STRING, &output_format, + N_("Output results format: “turtle”, “trig” or “json-ld”"), + N_("RDF_FORMAT") + }, { "remote-service", 'r', 0, G_OPTION_ARG_STRING, &remote_service, N_("Connects to a remote service"), N_("Remote service URI") @@ -315,6 +320,7 @@ export_run_default (void) g_autoptr(GError) error = NULL; g_autoptr(GString) query = NULL; g_autoptr(GMainLoop) loop = NULL; + TrackerRdfFormat format; guint i; connection = create_connection (&error); @@ -341,15 +347,43 @@ export_run_default (void) "}"); } - tracker_term_pipe_to_pager (); - loop = g_main_loop_new (NULL, FALSE); + if (output_format) { + /* Matches TrackerRdfFormat */ + const gchar *formats[] = { + "turtle", + "trig", + "json-ld", + }; + guint i; + gboolean found = FALSE; + + G_STATIC_ASSERT (G_N_ELEMENTS (formats) == TRACKER_N_RDF_FORMATS); + + for (i = 0; i < G_N_ELEMENTS (formats); i++) { + if (g_strcmp0 (formats[i], output_format) == 0) { + format = i; + found = TRUE; + break; + } + } + + if (!found) { + g_printerr (_("Unsupported serialization format “%s”\n"), output_format); + return EXIT_FAILURE; + } + } else if (show_graphs) { + format = TRACKER_RDF_FORMAT_TRIG; + } else { + format = TRACKER_RDF_FORMAT_TURTLE; + } + + tracker_term_pipe_to_pager (); + tracker_sparql_connection_serialize_async (connection, TRACKER_SERIALIZE_FLAGS_NONE, - show_graphs ? - TRACKER_RDF_FORMAT_TRIG : - TRACKER_RDF_FORMAT_TURTLE, + format, query->str, NULL, serialize_cb, loop); g_main_loop_run (loop); |