Blame 0065-cli-batch-reporting-in-abrt-cli.patch

69165ba
From 46fac7e2c0eaf98668698558ec4acbc2ade76ba7 Mon Sep 17 00:00:00 2001
69165ba
From: Matej Habrnal <mhabrnal@redhat.com>
69165ba
Date: Sat, 20 Sep 2014 22:50:11 +0200
69165ba
Subject: [ABRT PATCH 65/66] cli: batch reporting in abrt-cli
69165ba
69165ba
Added option process (p) to the abrt-cli.
69165ba
With option process abrt-cli goes through all problems one by one (when
69165ba
parameter --since is not specified) and asks the user what action will be
69165ba
executed.
69165ba
69165ba
Resolves #1066482
69165ba
69165ba
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
69165ba
Signed-off-by: Jakub Filak <jfilak@redhat.com>
69165ba
---
69165ba
 doc/abrt-cli.txt      |   2 +
69165ba
 po/POTFILES.in        |   1 +
69165ba
 src/cli/Makefile.am   |   1 +
69165ba
 src/cli/abrt-cli.c    |   1 +
69165ba
 src/cli/builtin-cmd.h |   1 +
69165ba
 src/cli/process.c     | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++
69165ba
 6 files changed, 175 insertions(+)
69165ba
 create mode 100644 src/cli/process.c
69165ba
69165ba
diff --git a/doc/abrt-cli.txt b/doc/abrt-cli.txt
69165ba
index 1c95655..cd14bc9 100644
69165ba
--- a/doc/abrt-cli.txt
69165ba
+++ b/doc/abrt-cli.txt
69165ba
@@ -15,6 +15,8 @@ SYNOPSIS
69165ba
 
69165ba
 'abrt-cli' info   [-vd] [-s SIZE] DIR...
69165ba
 
69165ba
+'abrt-cli' process [-v] DIR...
69165ba
+
69165ba
 OPTIONS
69165ba
 -------
69165ba
 -v,--verbose::
69165ba
diff --git a/po/POTFILES.in b/po/POTFILES.in
69165ba
index 141c73a..cbe89fa 100644
69165ba
--- a/po/POTFILES.in
69165ba
+++ b/po/POTFILES.in
69165ba
@@ -52,6 +52,7 @@ src/cli/abrt-cli.c
69165ba
 src/cli/list.c
69165ba
 src/cli/status.c
69165ba
 src/cli/report.c
69165ba
+src/cli/process.c
69165ba
 
69165ba
 src/plugins/analyze_CCpp.xml.in
69165ba
 src/plugins/analyze_VMcore.xml.in
69165ba
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
69165ba
index 75efac5..9fff5b3 100644
69165ba
--- a/src/cli/Makefile.am
69165ba
+++ b/src/cli/Makefile.am
69165ba
@@ -9,6 +9,7 @@ BUILTIN_C += list.c
69165ba
 BUILTIN_C += rm.c
69165ba
 BUILTIN_C += report.c
69165ba
 BUILTIN_C += status.c
69165ba
+BUILTIN_C += process.c
69165ba
 
69165ba
 abrt_cli_SOURCES = $(CLI_C) $(BUILTIN_C) builtin-cmd.h abrt-cli-core.h
69165ba
 
69165ba
diff --git a/src/cli/abrt-cli.c b/src/cli/abrt-cli.c
69165ba
index c04c132..bc11c7f 100644
69165ba
--- a/src/cli/abrt-cli.c
69165ba
+++ b/src/cli/abrt-cli.c
69165ba
@@ -150,6 +150,7 @@ int main(int argc, const char **argv)
69165ba
         CMD(report, "e",_("Analyze and report problem data in DIR")),
69165ba
         CMD(info, "i", _("Print information about DIR")),
69165ba
         CMD(status, "st",_("Print the count of the recent crashes")),
69165ba
+        CMD(process, "p",_("Process multiple problems")),
69165ba
         {NULL, NULL, NULL, NULL}
69165ba
     };
69165ba
 
69165ba
diff --git a/src/cli/builtin-cmd.h b/src/cli/builtin-cmd.h
69165ba
index 18588e1..bc80479 100644
69165ba
--- a/src/cli/builtin-cmd.h
69165ba
+++ b/src/cli/builtin-cmd.h
69165ba
@@ -25,5 +25,6 @@ extern int cmd_remove(int argc, const char **argv);
69165ba
 extern int cmd_report(int argc, const char **argv);
69165ba
 extern int cmd_info(int argc, const char **argv);
69165ba
 extern int cmd_status(int argc, const char **argv);
69165ba
+extern int cmd_process(int argc, const char **argv);
69165ba
 
69165ba
 #endif /* _BUILTIN-CMD_H_ */
69165ba
diff --git a/src/cli/process.c b/src/cli/process.c
69165ba
new file mode 100644
69165ba
index 0000000..7f4fff5
69165ba
--- /dev/null
69165ba
+++ b/src/cli/process.c
69165ba
@@ -0,0 +1,169 @@
69165ba
+/*
69165ba
+    Copyright (C) 2014  ABRT Team
69165ba
+    Copyright (C) 2014  RedHat inc.
69165ba
+
69165ba
+    This program is free software; you can redistribute it and/or modify
69165ba
+    it under the terms of the GNU General Public License as published by
69165ba
+    the Free Software Foundation; either version 2 of the License, or
69165ba
+    (at your option) any later version.
69165ba
+
69165ba
+    This program is distributed in the hope that it will be useful,
69165ba
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
69165ba
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
69165ba
+    GNU General Public License for more details.
69165ba
+
69165ba
+    You should have received a copy of the GNU General Public License along
69165ba
+    with this program; if not, write to the Free Software Foundation, Inc.,
69165ba
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
69165ba
+*/
69165ba
+
69165ba
+#include "libabrt.h"
69165ba
+#include "client.h"
69165ba
+
69165ba
+#include "abrt-cli-core.h"
69165ba
+#include "builtin-cmd.h"
69165ba
+
69165ba
+
69165ba
+enum {
69165ba
+    ACT_ERR = 0,
69165ba
+    ACT_REMOVE,
69165ba
+    ACT_REPORT,
69165ba
+    ACT_INFO,
69165ba
+    ACT_SKIP
69165ba
+};
69165ba
+
69165ba
+static int process_one_crash(problem_data_t *problem_data)
69165ba
+{
69165ba
+    if (problem_data == NULL)
69165ba
+        return ACT_ERR;
69165ba
+
69165ba
+    static const char *name_to_skip[] = {
69165ba
+            FILENAME_PACKAGE   ,
69165ba
+            FILENAME_UID       ,
69165ba
+            FILENAME_COUNT
69165ba
+    };
69165ba
+
69165ba
+    char *desc = make_description(problem_data,
69165ba
+                        /*names_to_skip:*/ (char **)name_to_skip,
69165ba
+                        /*max_text_size:*/ CD_TEXT_ATT_SIZE_BZ,
69165ba
+                        MAKEDESC_SHOW_ONLY_LIST | MAKEDESC_SHOW_URLS);
69165ba
+
69165ba
+    fputs(desc, stdout);
69165ba
+    free(desc);
69165ba
+
69165ba
+    const char *dir_name = problem_data_get_content_or_NULL(problem_data,
69165ba
+                                                            CD_DUMPDIR);
69165ba
+    char *action = NULL;
69165ba
+    int ret_val = 0;
69165ba
+    while (ret_val == 0)
69165ba
+    {
69165ba
+        const char *not_reportable = problem_data_get_content_or_NULL(problem_data, FILENAME_NOT_REPORTABLE);
69165ba
+
69165ba
+        /* if the problem is not-reportable then ask does not contain option report(e) */
69165ba
+        if (not_reportable != NULL)
69165ba
+            action = ask(_("Actions: remove(rm), info(i), skip(s):"));
69165ba
+        else
69165ba
+            action = ask(_("Actions: remove(rm), report(e), info(i), skip(s):"));
69165ba
+
69165ba
+        if(strcmp(action, "rm") == 0 || strcmp(action, "remove") == 0 )
69165ba
+        {
69165ba
+            log(_("Deleting '%s'"), dir_name);
69165ba
+            delete_dump_dir_possibly_using_abrtd(dir_name);
69165ba
+
69165ba
+            ret_val = ACT_REMOVE;
69165ba
+        }
69165ba
+        else if (not_reportable == NULL && (strcmp(action, "e") == 0 || strcmp(action, "report") == 0))
69165ba
+        {
69165ba
+            log(_("Reporting '%s'"), dir_name);
69165ba
+            report_problem_in_dir(dir_name,
69165ba
+                                     LIBREPORT_WAIT
69165ba
+                                   | LIBREPORT_RUN_CLI);
69165ba
+
69165ba
+            ret_val = ACT_REPORT;
69165ba
+        }
69165ba
+        else if (strcmp(action, "i") == 0 || strcmp(action, "info") == 0)
69165ba
+        {
69165ba
+            char *desc = make_description(problem_data,
69165ba
+                                    /*names_to_skip:*/ NULL,
69165ba
+                                    /*max_text_size:*/ CD_TEXT_ATT_SIZE_BZ,
69165ba
+                                    MAKEDESC_SHOW_FILES | MAKEDESC_SHOW_MULTILINE);
69165ba
+
69165ba
+            fputs(desc, stdout);
69165ba
+            free(desc);
69165ba
+
69165ba
+            ret_val = ACT_INFO;
69165ba
+        }
69165ba
+        else if (strcmp(action, "s") == 0 || strcmp(action, "skip") == 0)
69165ba
+        {
69165ba
+            ret_val = ACT_SKIP;
69165ba
+        }
69165ba
+
69165ba
+        free(action);
69165ba
+    }
69165ba
+
69165ba
+    return ret_val;
69165ba
+}
69165ba
+
69165ba
+static void process_crashes(vector_of_problem_data_t *crash_list, long since)
69165ba
+{
69165ba
+
69165ba
+    for (unsigned i = 0; i < crash_list->len; ++i)
69165ba
+    {
69165ba
+        problem_data_t *crash = get_problem_data(crash_list, i);
69165ba
+
69165ba
+        if (since != 0)
69165ba
+        {
69165ba
+            char *s = problem_data_get_content_or_NULL(crash, FILENAME_LAST_OCCURRENCE);
69165ba
+            long val = s ? atol(s) : 0;
69165ba
+            if (val < since)
69165ba
+                continue;
69165ba
+        }
69165ba
+
69165ba
+        /* do not print '\n' before first problem */
69165ba
+        if(i != 0)
69165ba
+            printf("\n");
69165ba
+
69165ba
+        int action = process_one_crash(crash);
69165ba
+
69165ba
+        if (i != crash_list->len - 1)
69165ba
+        {
69165ba
+            if (action == ACT_REMOVE || action == ACT_REPORT || action == ACT_INFO)
69165ba
+            {
69165ba
+                /* dummy must be free because the function ask allocate memory */
69165ba
+                char *dummy = ask(_("For next problem press ENTER:"));
69165ba
+                free(dummy);
69165ba
+            }
69165ba
+        }
69165ba
+    }
69165ba
+    return;
69165ba
+}
69165ba
+
69165ba
+int cmd_process(int argc, const char **argv)
69165ba
+{
69165ba
+    const char *program_usage_string = _(
69165ba
+        "Without --since argument, iterates over all detected problems."
69165ba
+    );
69165ba
+
69165ba
+    int opt_since = 0;
69165ba
+    struct options program_options[] = {
69165ba
+        OPT__VERBOSE(&g_verbose),
69165ba
+        OPT_INTEGER('s', "since" , &opt_since,  _("Selects only problems detected after timestamp")),
69165ba
+        OPT_END()
69165ba
+    };
69165ba
+
69165ba
+    parse_opts(argc, (char **)argv, program_options, program_usage_string);
69165ba
+    argv += optind;
69165ba
+
69165ba
+    GList *D_list = get_problem_storages();
69165ba
+
69165ba
+    vector_of_problem_data_t *ci = fetch_crash_infos(D_list);
69165ba
+
69165ba
+    g_ptr_array_sort_with_data(ci, &cmp_problem_data, (char *) FILENAME_LAST_OCCURRENCE);
69165ba
+
69165ba
+    process_crashes(ci, opt_since);
69165ba
+
69165ba
+    free_vector_of_problem_data(ci);
69165ba
+    list_free_with_free(D_list);
69165ba
+
69165ba
+    return 0;
69165ba
+}
69165ba
-- 
69165ba
1.8.3.1
69165ba