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

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