[tracker/wip/sam/resource-rebase-5: 3/9] cli: Add --verbosity option to `tracker extract`



commit 8736fe88cee45fda6741a86cb81abfef545ea248
Author: Sam Thursfield <sam afuera me uk>
Date:   Thu Apr 7 16:25:15 2016 +0100

    cli: Add --verbosity option to `tracker extract`
    
    This is based on the --set-log-verbosity option from `tracker daemon`.
    
    The TRACKER_VERBOSITY environment variable also works here, and
    overrides the value on the commandline, so I'm not sure if this patch
    is really necessary...

 docs/manpages/tracker-extract.1 |   48 +++++++++++++++++++++++++++++++++++++++
 src/tracker/tracker-extract.c   |   34 +++++++++++++++++++++++++--
 2 files changed, 79 insertions(+), 3 deletions(-)
---
diff --git a/docs/manpages/tracker-extract.1 b/docs/manpages/tracker-extract.1
index 652912c..0a7076d 100644
--- a/docs/manpages/tracker-extract.1
+++ b/docs/manpages/tracker-extract.1
@@ -20,6 +20,54 @@ uses to extract metadata.
 
 For more information see the libtracker-extract reference documentation.
 
+.SH OPTIONS
+.TP
+.B \-\-verbosity\fR=<\fILEVEL\fR>
+This sets the log verbosity for the extractor process.
+
+The possible \fILEVEL\fR options are:
+.sp
+.RS 12
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+\fIdebug\fR
+\- Show EVERYTHING, from debug messages to errors.
+.sp
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.IP \(bu 2.3
+.\}
+\fIdetailed\fR
+\- Show enough detail to understand what is happening.
+.sp
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+\fIminimal\fR
+\- Show an overview of what is going on
+.sp
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+\fIerrors\fR
+\- Show only warnings, criticals, errors or fatal events.
+.RE
+
 .SH EXAMPLES
 .TP
 Using command line to extract metadata from a file:
diff --git a/src/tracker/tracker-extract.c b/src/tracker/tracker-extract.c
index a6f23c4..d4979f3 100644
--- a/src/tracker/tracker-extract.c
+++ b/src/tracker/tracker-extract.c
@@ -25,14 +25,21 @@
 #include <glib/gi18n.h>
 #include <gio/gio.h>
 
+#include <libtracker-common/tracker-common.h>
+
+#include "tracker-config.h"
 #include "tracker-extract.h"
 
+static gchar *verbosity;
 static gchar **filenames;
 
 #define EXTRACT_OPTIONS_ENABLED()        \
        ((filenames && g_strv_length (filenames) > 0))
 
 static GOptionEntry entries[] = {
+       { "verbosity", 'v', 0, G_OPTION_ARG_STRING, &verbosity,
+         N_("Sets the logging verbosity to LEVEL ('debug', 'detailed', 'minimal', 'errors') for all 
processes"),
+         N_("LEVEL") },
        { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames,
          N_("FILE"),
          N_("FILE") },
@@ -41,16 +48,19 @@ static GOptionEntry entries[] = {
 
 
 static gint
-extract_files (void)
+extract_files (TrackerVerbosity verbosity)
 {
        char **p;
        char *tracker_extract_path;
+       char verbosity_str[2];
        GError *error = NULL;
 
+       snprintf (verbosity_str, 2, "%i", verbosity);
+
        tracker_extract_path = g_build_filename(LIBEXECDIR, "tracker-extract", NULL);
 
        for (p = filenames; *p; p++) {
-               char *argv[] = {tracker_extract_path, "--file", *p, NULL};
+               char *argv[] = {tracker_extract_path, "--verbosity", verbosity_str, "--file", *p, NULL};
 
                g_spawn_sync(NULL, argv, NULL, G_SPAWN_DEFAULT, NULL, NULL, NULL, NULL, NULL, &error);
 
@@ -71,7 +81,25 @@ extract_files (void)
 static int
 extract_run (void)
 {
-       return extract_files ();
+       TrackerVerbosity verbosity_level = TRACKER_VERBOSITY_ERRORS;
+
+       if (verbosity) {
+               if (g_ascii_strcasecmp (verbosity, "debug") == 0) {
+                       verbosity_level = TRACKER_VERBOSITY_DEBUG;
+               } else if (g_ascii_strcasecmp (verbosity, "detailed") == 0) {
+                       verbosity_level = TRACKER_VERBOSITY_DETAILED;
+               } else if (g_ascii_strcasecmp (verbosity, "minimal") == 0) {
+                       verbosity_level = TRACKER_VERBOSITY_MINIMAL;
+               } else if (g_ascii_strcasecmp (verbosity, "errors") == 0) {
+                       verbosity_level = TRACKER_VERBOSITY_ERRORS;
+               } else {
+                       g_printerr ("%s\n",
+                                   _("Invalid log verbosity, try 'debug', 'detailed', 'minimal' or 
'errors'"));
+                       return EXIT_FAILURE;
+               }
+       }
+
+       return extract_files (verbosity_level);
 }
 
 static int


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