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

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