[tracker/wip/sam/resource: 9/13] Groundwork for tracker-extract JSON output
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/sam/resource: 9/13] Groundwork for tracker-extract JSON output
- Date: Fri, 8 Apr 2016 23:41:43 +0000 (UTC)
commit 3c611dc1a84fa5e55b27115f0395bec9d06b9307
Author: Sam Thursfield <sam afuera me uk>
Date: Thu Apr 7 17:30:56 2016 +0100
Groundwork for tracker-extract JSON output
configure.ac | 6 ++++--
src/libtracker-common/tracker-enums.h | 10 ++++++++++
src/tracker-extract/tracker-extract.c | 7 ++++---
src/tracker-extract/tracker-extract.h | 7 ++++---
src/tracker-extract/tracker-main.c | 19 ++++++++++++++++++-
src/tracker/tracker-extract.c | 14 +++++++++++---
6 files changed, 51 insertions(+), 12 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index bcf676f..10729fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -237,6 +237,7 @@ GSTREAMER_REQUIRED=0.10.31
GUPNP_DLNA_REQUIRED=0.9.4
LIBPNG_REQUIRED=0.89
LIBMEDIAART_REQUIRED=1.9.0
+JSON_GLIB_REQUIRED=1.0.4
# 3.6.11 for sqlite_backup API
# 3.6.16 to fix test failures
@@ -321,8 +322,9 @@ LIBTRACKER_CONTROL_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
PKG_CHECK_MODULES(LIBTRACKER_CONTROL, [$LIBTRACKER_CONTROL_REQUIRED])
# Check requirements for libtracker-sparql
-LIBTRACKER_SPARQL_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
- gio-unix-2.0 >= $GLIB_REQUIRED
+LIBTRACKER_SPARQL_REQUIRED="glib-2.0 >= $GLIB_REQUIRED
+ gio-unix-2.0 >= $GLIB_REQUIRED
+ json-glib-1.0 >= $JSON_GLIB_REQUIRED
uuid"
PKG_CHECK_MODULES(LIBTRACKER_SPARQL, [$LIBTRACKER_SPARQL_REQUIRED])
diff --git a/src/libtracker-common/tracker-enums.h b/src/libtracker-common/tracker-enums.h
index 3fd43d9..edce490 100644
--- a/src/libtracker-common/tracker-enums.h
+++ b/src/libtracker-common/tracker-enums.h
@@ -35,6 +35,16 @@ typedef enum {
TRACKER_SCHED_IDLE_NEVER,
} TrackerSchedIdle;
+typedef enum {
+ /* JSON and JSON_LD are treated as the same thing right now, but that
+ * could theoretically change, and it's nice to be able to use either
+ * 'json' or 'json-ld' with `tracker extract --output-format=` and such.
+ */
+ TRACKER_SERIALIZATION_FORMAT_JSON,
+ TRACKER_SERIALIZATION_FORMAT_JSON_LD,
+ TRACKER_SERIALIZATION_FORMAT_SPARQL,
+} TrackerSerializationFormat;
+
G_END_DECLS
#endif /* __TRACKER_ENUMS_H__ */
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 04b3291..9ff3c31 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -762,9 +762,10 @@ tracker_extract_get_media_art_process (TrackerExtract *extract)
#endif
void
-tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
- const gchar *uri,
- const gchar *mime)
+tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
+ const gchar *uri,
+ const gchar *mime,
+ TrackerSerializationFormat output_format)
{
GError *error = NULL;
TrackerExtractPrivate *priv;
diff --git a/src/tracker-extract/tracker-extract.h b/src/tracker-extract/tracker-extract.h
index 704ece4..b1f0aa1 100644
--- a/src/tracker-extract/tracker-extract.h
+++ b/src/tracker-extract/tracker-extract.h
@@ -81,9 +81,10 @@ void tracker_extract_dbus_start (TrackerExtract
void tracker_extract_dbus_stop (TrackerExtract *extract);
/* Not DBus API */
-void tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
- const gchar *path,
- const gchar *mime);
+void tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
+ const gchar *path,
+ const gchar *mime,
+ TrackerSerializationFormat output_format);
G_END_DECLS
diff --git a/src/tracker-extract/tracker-main.c b/src/tracker-extract/tracker-main.c
index 2c8ecd8..0baf9cd 100644
--- a/src/tracker-extract/tracker-main.c
+++ b/src/tracker-extract/tracker-main.c
@@ -72,6 +72,7 @@ static gint verbosity = -1;
static gchar *filename;
static gchar *mime_type;
static gchar *force_module;
+static gchar *output_format_name;
static gboolean version;
static TrackerConfig *config;
@@ -94,6 +95,9 @@ static GOptionEntry entries[] = {
G_OPTION_ARG_STRING, &force_module,
N_("Force a module to be used for extraction (e.g. \"foo\" for \"foo.so\")"),
N_("MODULE") },
+ { "output-format", 'o', 0, G_OPTION_ARG_STRING, &output_format_name,
+ N_("Output results format: 'json' or 'sparql'"),
+ N_("FORMAT") },
{ "version", 'V', 0,
G_OPTION_ARG_NONE, &version,
N_("Displays version information"),
@@ -241,6 +245,9 @@ run_standalone (TrackerConfig *config)
TrackerExtract *object;
GFile *file;
gchar *uri;
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+ TrackerSerializationFormat output_format;
/* Set log handler for library messages */
g_log_set_default_handler (log_handler, NULL);
@@ -250,6 +257,16 @@ run_standalone (TrackerConfig *config)
verbosity = 3;
}
+ /* Look up the output format by name */
+ enum_class = g_type_class_ref (TRACKER_TYPE_SERIALIZATION_FORMAT);
+ enum_value = g_enum_get_value_by_nick (enum_class, output_format_name);
+ g_type_class_unref (enum_class);
+ if (!enum_value) {
+ g_printerr (N_("Unsupported serialization format '%s'\n"), output_format_name);
+ return EXIT_FAILURE;
+ }
+ output_format = enum_value->value;
+
tracker_locale_init ();
/* This makes sure we don't steal all the system's resources */
@@ -268,7 +285,7 @@ run_standalone (TrackerConfig *config)
return EXIT_FAILURE;
}
- tracker_extract_get_metadata_by_cmdline (object, uri, mime_type);
+ tracker_extract_get_metadata_by_cmdline (object, uri, mime_type, output_format);
g_object_unref (object);
g_object_unref (file);
diff --git a/src/tracker/tracker-extract.c b/src/tracker/tracker-extract.c
index d4979f3..5f5b838 100644
--- a/src/tracker/tracker-extract.c
+++ b/src/tracker/tracker-extract.c
@@ -30,6 +30,7 @@
#include "tracker-config.h"
#include "tracker-extract.h"
+static gchar *output_format = "json-ld";
static gchar *verbosity;
static gchar **filenames;
@@ -37,6 +38,9 @@ static gchar **filenames;
((filenames && g_strv_length (filenames) > 0))
static GOptionEntry entries[] = {
+ { "output-format", 'o', 0, G_OPTION_ARG_STRING, &output_format,
+ N_("Output results format: 'json' or 'sparql'"),
+ N_("FORMAT") },
{ "verbosity", 'v', 0, G_OPTION_ARG_STRING, &verbosity,
N_("Sets the logging verbosity to LEVEL ('debug', 'detailed', 'minimal', 'errors') for all
processes"),
N_("LEVEL") },
@@ -48,7 +52,8 @@ static GOptionEntry entries[] = {
static gint
-extract_files (TrackerVerbosity verbosity)
+extract_files (TrackerVerbosity verbosity,
+ char *output_format)
{
char **p;
char *tracker_extract_path;
@@ -60,7 +65,10 @@ extract_files (TrackerVerbosity verbosity)
tracker_extract_path = g_build_filename(LIBEXECDIR, "tracker-extract", NULL);
for (p = filenames; *p; p++) {
- char *argv[] = {tracker_extract_path, "--verbosity", verbosity_str, "--file", *p, NULL};
+ char *argv[] = {tracker_extract_path,
+ "--output-format", output_format,
+ "--verbosity", verbosity_str,
+ "--file", *p, NULL };
g_spawn_sync(NULL, argv, NULL, G_SPAWN_DEFAULT, NULL, NULL, NULL, NULL, NULL, &error);
@@ -99,7 +107,7 @@ extract_run (void)
}
}
- return extract_files (verbosity_level);
+ return extract_files (verbosity_level, output_format);
}
static int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]