[tracker/wip/sam/resource: 39/41] Groundwork for tracker-extract JSON output
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/sam/resource: 39/41] Groundwork for tracker-extract JSON output
- Date: Sat, 7 May 2016 14:01:44 +0000 (UTC)
commit 6ddf00135f1a81b91f1642a86f371142d42d6997
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 | 6 ++++++
src/tracker-extract/tracker-extract.c | 7 ++++---
src/tracker-extract/tracker-extract.h | 7 ++++---
src/tracker-extract/tracker-main.c | 18 ++++++++++++++++--
src/tracker/tracker-extract.c | 14 +++++++++++---
6 files changed, 45 insertions(+), 13 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 2be97c1..f3e2bbd 100644
--- a/src/libtracker-common/tracker-enums.h
+++ b/src/libtracker-common/tracker-enums.h
@@ -38,6 +38,12 @@ typedef enum {
typedef enum {
TRACKER_SERIALIZATION_FORMAT_SPARQL,
TRACKER_SERIALIZATION_FORMAT_TURTLE,
+ /* JSON and JSON_LD are treated as the same thing right now, but we could
+ * treat them differently if we wanted. also it's nice to be able to pass
+ * both 'json' and 'json-ld' to `tracker extract --output-format=`.
+ */
+ TRACKER_SERIALIZATION_FORMAT_JSON,
+ TRACKER_SERIALIZATION_FORMAT_JSON_LD,
} TrackerSerializationFormat;
G_END_DECLS
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index b4fe6e5..30f2e9e 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -739,9 +739,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 50fa8c3..882c601 100644
--- a/src/tracker-extract/tracker-extract.h
+++ b/src/tracker-extract/tracker-extract.h
@@ -79,9 +79,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 cc02fdd..db8d081 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;
@@ -95,7 +96,7 @@ static GOptionEntry entries[] = {
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: 'sparql', or 'turtle'"),
+ N_("Output results format: 'sparql', 'turtle' or 'json'"),
N_("FORMAT") },
{ "version", 'V', 0,
G_OPTION_ARG_NONE, &version,
@@ -244,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);
@@ -253,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 */
@@ -271,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]