doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

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

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