[tracker-miners: 1/2] tracker-info: show message if incomplete data




commit afa118d459431c6f8d8b0dfaab427e5b93b525f7
Author: Nishit Patel <nishitlimbani130 gmail com>
Date:   Wed May 12 16:37:19 2021 +0530

    tracker-info: show message if incomplete data
    
    If the data of the file is not complete then display message
    with reason, also add tracker-cli-utils to share code between
    cli files.
    
    Closes: #147

 src/tracker/meson.build         |   1 +
 src/tracker/tracker-cli-utils.c | 102 ++++++++++++++++++++++++++++++++++++++++
 src/tracker/tracker-cli-utils.h |  31 ++++++++++++
 src/tracker/tracker-info.c      |  59 +++++++++++++++++++++++
 src/tracker/tracker-status.c    |  78 ++----------------------------
 5 files changed, 196 insertions(+), 75 deletions(-)
---
diff --git a/src/tracker/meson.build b/src/tracker/meson.build
index 1433f8308..887f2d46d 100644
--- a/src/tracker/meson.build
+++ b/src/tracker/meson.build
@@ -13,6 +13,7 @@ common_sources = [
     'tracker-miner-manager.c',
     'tracker-dbus.c',
     'tracker-process.c',
+    'tracker-cli-utils.c',
 ]
 
 foreach m: modules
diff --git a/src/tracker/tracker-cli-utils.c b/src/tracker/tracker-cli-utils.c
new file mode 100644
index 000000000..e7aa1fffe
--- /dev/null
+++ b/src/tracker/tracker-cli-utils.c
@@ -0,0 +1,102 @@
+/*
+ *
+ * Copyright (C) 2021, Nishit Patel <nishitlimbani130 gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ *
+ */
+
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "tracker-cli-utils.h"
+
+
+static gint
+sort_by_date (gconstpointer a,
+              gconstpointer b)
+{
+       GFileInfo *info_a = (GFileInfo *) a, *info_b = (GFileInfo *) b;
+       gint64 time_a, time_b;
+
+       time_a = g_file_info_get_attribute_uint64 (info_a, G_FILE_ATTRIBUTE_TIME_CREATED);
+       time_b = g_file_info_get_attribute_uint64 (info_b, G_FILE_ATTRIBUTE_TIME_CREATED);
+
+       if (time_a < time_b)
+               return -1;
+       else if (time_a > time_b)
+               return 1;
+       return 0;
+}
+
+
+GList *
+tracker_cli_get_error_keyfiles (void)
+{
+       GFile *file;
+       GFileEnumerator *enumerator;
+       GList *infos = NULL, *keyfiles = NULL, *l;
+       gchar *path;
+
+       path = g_build_filename (g_get_user_cache_dir (),
+                                "tracker3",
+                                "files",
+                                "errors",
+                                NULL);
+       file = g_file_new_for_path (path);
+       g_free (path);
+
+       enumerator = g_file_enumerate_children (file,
+                                               G_FILE_ATTRIBUTE_STANDARD_NAME ","
+                                               G_FILE_ATTRIBUTE_TIME_CHANGED,
+                                               G_FILE_QUERY_INFO_NONE,
+                                               NULL,
+                                               NULL);
+       while (TRUE) {
+               GFileInfo *info;
+
+               if (!g_file_enumerator_iterate (enumerator, &info, NULL, NULL, NULL))
+                       break;
+               if (!info)
+                       break;
+
+               infos = g_list_prepend (infos, g_object_ref (info));
+       }
+
+       infos = g_list_sort (infos, sort_by_date);
+
+       for (l = infos; l; l = l->next) {
+               GKeyFile *keyfile;
+               GFile *child;
+
+               child = g_file_get_child (file, g_file_info_get_name (l->data));
+               path = g_file_get_path (child);
+               keyfile = g_key_file_new ();
+               g_key_file_load_from_file (keyfile,
+                                          path, 0,
+                                          NULL);
+
+               keyfiles = g_list_prepend (keyfiles, keyfile);
+               g_object_unref (child);
+       }
+
+       g_object_unref (enumerator);
+       g_list_free_full (infos, g_object_unref);
+
+       return keyfiles;
+}
\ No newline at end of file
diff --git a/src/tracker/tracker-cli-utils.h b/src/tracker/tracker-cli-utils.h
new file mode 100644
index 000000000..c7f9092e1
--- /dev/null
+++ b/src/tracker/tracker-cli-utils.h
@@ -0,0 +1,31 @@
+/*
+ *
+ * Copyright (C) 2021, Nishit Patel <nishitlimbani130 gmail com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ */
+
+#ifndef __TRACKER_CLI_UTILS_H_
+#define __TRACKER_CLI_UTILS_H_
+
+#include <glib.h>
+#include <gio/gio.h>
+
+
+GList* tracker_cli_get_error_keyfiles (void);
+
+#endif /* __TRACKER_CLI_UTILS_H__ */
diff --git a/src/tracker/tracker-info.c b/src/tracker/tracker-info.c
index 5ea83350c..d26e8abc8 100644
--- a/src/tracker/tracker-info.c
+++ b/src/tracker/tracker-info.c
@@ -32,9 +32,18 @@
 
 #include <libtracker-sparql/tracker-sparql.h>
 
+#include "tracker-cli-utils.h"
+#include "tracker-color.h"
+
 #define INFO_OPTIONS_ENABLED() \
        (filenames && g_strv_length (filenames) > 0);
 
+#define GROUP "Report"
+#define KEY_URI "Uri"
+#define KEY_MESSAGE "Message"
+#define KEY_SPARQL "Sparql"
+#define ERROR_MESSAGE "Extraction failed for this file. Some metadata will be missing."
+
 static gchar **filenames;
 static gboolean full_namespaces;
 static gboolean plain_text_content;
@@ -378,6 +387,50 @@ output_eligible_status_for_file (gchar   *path,
        }
 }
 
+static void
+print_errors (GList *keyfiles,
+             gchar *file_uri)
+{
+       GList *l;
+       GKeyFile *keyfile;
+       GFile *file;
+
+       file = g_file_new_for_uri (file_uri);
+
+
+       for (l = keyfiles; l; l = l->next) {
+               gchar *uri;
+               GFile *error_file;
+
+               keyfile = l->data;
+               uri = g_key_file_get_string (keyfile, GROUP, KEY_URI, NULL);
+               error_file = g_file_new_for_uri (uri);
+
+               if (g_file_equal (file, error_file)) {
+                       gchar *message = g_key_file_get_string (keyfile, GROUP, KEY_MESSAGE, NULL);
+                       gchar *sparql = g_key_file_get_string (keyfile, GROUP, KEY_SPARQL, NULL);
+
+                       if (message)
+                               g_print (CRIT_BEGIN "%s\n%s: %s" CRIT_END "\n",
+                                        ERROR_MESSAGE,
+                                        _("Error message"),
+                                        message);
+                       if (sparql)
+                               g_print ("SPARQL: %s\n", sparql);
+                       g_print ("\n");
+
+                       g_free (message);
+               }
+
+               g_free (uri);
+               g_object_unref (error_file);
+       }
+
+       g_object_unref (file);
+
+}
+
+
 static int
 info_run (void)
 {
@@ -413,6 +466,7 @@ info_run (void)
                gchar *uri = NULL;
                gchar *query;
                gchar *urn = NULL;
+               GList *keyfiles;
 
                if (!turtle && !resource_is_iri) {
                        g_print ("%s: '%s'\n", _("Querying information for entity"), *p);
@@ -521,6 +575,11 @@ info_run (void)
                        }
                }
 
+               keyfiles = tracker_cli_get_error_keyfiles ();
+
+               if (keyfiles && !turtle)
+                       print_errors (keyfiles, uri);
+
                g_print ("\n");
 
                g_free (uri);
diff --git a/src/tracker/tracker-status.c b/src/tracker/tracker-status.c
index 56dffe3eb..f8ac1f5e3 100644
--- a/src/tracker/tracker-status.c
+++ b/src/tracker/tracker-status.c
@@ -35,6 +35,7 @@
 #include "tracker-term-utils.h"
 #include "tracker-miner-manager.h"
 #include "tracker-color.h"
+#include "tracker-cli-utils.h"
 
 #define GROUP "Report"
 #define KEY_URI "Uri"
@@ -313,79 +314,6 @@ are_miners_finished (gint *max_remaining_time)
        return finished;
 }
 
-static gint
-sort_by_date (gconstpointer a,
-              gconstpointer b)
-{
-       GFileInfo *info_a = (GFileInfo *) a, *info_b = (GFileInfo *) b;
-       gint64 time_a, time_b;
-
-       time_a = g_file_info_get_attribute_uint64 (info_a, G_FILE_ATTRIBUTE_TIME_CREATED);
-       time_b = g_file_info_get_attribute_uint64 (info_b, G_FILE_ATTRIBUTE_TIME_CREATED);
-
-       if (time_a < time_b)
-               return -1;
-       else if (time_a > time_b)
-               return 1;
-       return 0;
-}
-
-static GList *
-get_error_keyfiles (void)
-{
-       GFile *file;
-       GFileEnumerator *enumerator;
-       GList *infos = NULL, *keyfiles = NULL, *l;
-       gchar *path;
-
-       path = g_build_filename (g_get_user_cache_dir (),
-                                "tracker3",
-                                "files",
-                                "errors",
-                                NULL);
-       file = g_file_new_for_path (path);
-       g_free (path);
-
-       enumerator = g_file_enumerate_children (file,
-                                               G_FILE_ATTRIBUTE_STANDARD_NAME ","
-                                               G_FILE_ATTRIBUTE_TIME_CHANGED,
-                                               G_FILE_QUERY_INFO_NONE,
-                                               NULL,
-                                               NULL);
-       while (TRUE) {
-               GFileInfo *info;
-
-               if (!g_file_enumerator_iterate (enumerator, &info, NULL, NULL, NULL))
-                       break;
-               if (!info)
-                       break;
-
-               infos = g_list_prepend (infos, g_object_ref (info));
-       }
-
-       infos = g_list_sort (infos, sort_by_date);
-
-       for (l = infos; l; l = l->next) {
-               GKeyFile *keyfile;
-               GFile *child;
-
-               child = g_file_get_child (file, g_file_info_get_name (l->data));
-               path = g_file_get_path (child);
-               keyfile = g_key_file_new ();
-               g_key_file_load_from_file (keyfile,
-                                          path, 0,
-                                          NULL);
-
-               keyfiles = g_list_prepend (keyfiles, keyfile);
-               g_object_unref (child);
-       }
-
-       g_object_unref (enumerator);
-       g_list_free_full (infos, g_object_unref);
-
-       return keyfiles;
-}
-
 static gint
 print_errors (GList *keyfiles)
 {
@@ -494,7 +422,7 @@ get_no_args (void)
                g_print ("%s\n", _("All data miners are idle, indexing complete"));
        }
 
-       keyfiles = get_error_keyfiles ();
+       keyfiles = tracker_cli_get_error_keyfiles ();
 
        if (keyfiles) {
                g_print (g_dngettext (NULL,
@@ -523,7 +451,7 @@ show_errors (gchar **terms)
 
        tracker_term_pipe_to_pager ();
 
-       keyfiles = get_error_keyfiles ();
+       keyfiles = tracker_cli_get_error_keyfiles ();
 
        for (i = 0; terms[i] != NULL; i++) {
                for (l = keyfiles; l; l = l->next) {


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