1. Before this change, "abrt-cli report DIR", if it found that
it was already reported, was saying:
ABRT Server:
URL=https://retrace.fedoraproject.org/faf/reports/8739/
Bugzilla:
URL=https://bugzilla.redhat.com/show_bug.cgi?id=688129
This change makes it:
A bug was already filed about this problem:
ABRT Server:
URL=https://retrace.fedoraproject.org/faf/reports/8739/
Bugzilla:
URL=https://bugzilla.redhat.com/show_bug.cgi?id=688129
2. If "abrt-cli report DIR" found that ureport was sent, but no bugs were
filed,
abrt-action-ureport used to die silently. Now it prints one line:
"uReport was already sent, not sending it again".
3. Since now abrt-action-generate-core-backtrace emits its own message,
"Generating core_backtarce" message at verbosity 1 is removed from here.
To support i18n, the script had to be rewritten in python
Signed-off-by: Denys Vlasenko <dvlasenk(a)redhat.com>
---
src/plugins/abrt-action-ureport | 144 +++++++++++++++++++++++++---------------
1 file changed, 91 insertions(+), 53 deletions(-)
mode change 100644 => 100755 src/plugins/abrt-action-ureport
diff --git a/src/plugins/abrt-action-ureport b/src/plugins/abrt-action-ureport
old mode 100644
new mode 100755
index b6ae6a2..41916bd
--- a/src/plugins/abrt-action-ureport
+++ b/src/plugins/abrt-action-ureport
@@ -1,68 +1,106 @@
-#!/bin/sh
+#!/usr/bin/python -u
+# WARNING: python -u means unbuffered I/O. Without it the messages are
+# passed to the parent asynchronously which looks bad in clients.
#
# This script wraps reporter-ureport client and keeps number of sent
# uReports to a server consistent with number of problem ocurrences.
-# $1 a message
-log1()
-{
- test -n "$ABRT_VERBOSE" && test "$ABRT_VERBOSE" -ge 1
&& echo "$1" >&2
-}
-
-# $1 a full path fo file
-# $2 a default value
-try_parse_number()
-{
- if test -f $1 && grep -q "^[0-9][0-9]*$" < "$1"
&& test 0 -eq $(wc -l < $1); then
- cat -- "$1"
- else
- log1 "Not a number in file '$1'"
- printf "%s" "$2"
- fi
-}
+import sys
+import os
+import getopt
-#
-# Main
-#
+from report import dd_opendir, DD_FAIL_QUIETLY_ENOENT
+from reportclient import _, set_verbosity, error_msg_and_die, error_msg, log1, log
+
+def spawn_and_wait(prog):
+ return os.spawnlp(os.P_WAIT, prog, prog)
+
+def try_parse_number(dd, filename):
+ try:
+ n = dd.load_text(filename, DD_FAIL_QUIETLY_ENOENT)
+ if n == "":
+ return 0
+ return int(n)
+ except:
+ error_msg(_("Not a number in file '%s'"), filename)
+ return 0
+
+if __name__ == "__main__":
+ # localization
+ #init_gettext() - done by reportclient module init
+
+ verbose = 0
+ ABRT_VERBOSE = os.getenv("ABRT_VERBOSE")
+ if ABRT_VERBOSE:
+ try:
+ verbose = int(ABRT_VERBOSE)
+ except:
+ pass
-1>&2
+ progname = os.path.basename(sys.argv[0])
+ help_text = _("Usage: %s [-v]") % progname
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "vh", ["help"])
+ except getopt.GetoptError, err:
+ error_msg(err) # prints something like "option -a not recognized"
+ error_msg_and_die(help_text)
-UREPORTS=$(try_parse_number "$PWD/ureports_counter" "0")
-COUNT=$(try_parse_number "$PWD/count" "0")
+ for opt, arg in opts:
+ if opt in ("-h", "--help"):
+ print help_text
+ sys.exit(0)
+ if opt == "-v":
+ verbose += 1
-# Send only if the problem is not yet reported
-# if the count file is corrupted or
-# if the number of ureports is lower then the number of occurrences
-if test 0 -ne "$UREPORTS" && test 0 -ne "$COUNT" &&
test "$UREPORTS" -ge "$COUNT"; then
- log1 "uReport has been already sent: '$PWD'"
+ set_verbosity(verbose)
- if test -f reported_to; then
- grep -e "^Bugzilla: " -e "^ABRT Server: " < reported_to |
sort -u
+ dirname = os.getcwd()
- if grep -q -e "^Bugzilla: " -e "^ABRT Server: " <
reported_to; then
- exit 70 # EXIT_STOP_EVENT_RUN
- fi
+ dd = dd_opendir(dirname, 0)
+ if not dd:
+ sys.exit(1)
+ core_backtrace_exists = dd.exist("core_backtrace")
+ reported_to = dd.load_text("reported_to", DD_FAIL_QUIETLY_ENOENT)
+ ureports_counter = try_parse_number(dd, "ureports_counter")
+ count = try_parse_number(dd, "count")
+ dd.close()
- log1 "Bug for '$PWD' not yet filed. Continuing."
- exit 0
- fi
+ # Send only if the problem is not yet reported
+ # if the count file is corrupted or
+ # if the number of ureports is lower then the number of occurrences
+ if ureports_counter != 0 and count != 0 and ureports_counter >= count:
+ log1("uReport has been already sent: '%s'", dirname)
- log1 "uReport was sent but '$PWD/reported_to' doesn't exist.
Continuing."
- exit 0
-fi
+ if reported_to and reported_to != "":
+ bugs = set()
+ for line in reported_to.split("\n"):
+ if line.startswith("Bugzilla:") or line.startswith("ABRT
Server:"):
+ bugs.add(line)
+ if bugs:
+ log(_("A bug was already filed about this problem:"))
+ bugs = sorted(bugs)
+ for bug in bugs:
+ print bug
+ sys.exit(70) # EXIT_STOP_EVENT_RUN
+ log1("Bug for '%s' not yet filed. Continuing.", dirname)
+ sys.exit(0)
+ else:
+ log1("'%s/reported_to' doesn't exist", dirname)
-if test ! -s core_backtrace; then
- log1 "Generating core_backtrace"
+ log(_("uReport was already sent, not sending it again"))
+ sys.exit(0)
- abrt-action-generate-core-backtrace || {
- log1 "uReport can't be sent without core_backtrace. Exiting."
- exit 1
- }
-fi
+ if not core_backtrace_exists:
+ exitcode = spawn_and_wait("abrt-action-generate-core-backtrace")
+ if exitcode != 0:
+ log1("uReport can't be sent without core_backtrace. Exiting.")
+ sys.exit(1)
-reporter-ureport
-RET_CODE=$?
-if [ $RET_CODE -eq 0 ] || [ $RET_CODE -eq 70 ]; then
- printf "%s" "$((UREPORTS + 1))" > ureports_counter
- exit $RET_CODE
-fi
+ exitcode = spawn_and_wait("reporter-ureport")
+ if exitcode == 0 or exitcode == 70:
+ dd = dd_opendir(dirname, 0)
+ if not dd:
+ sys.exit(1)
+ dd.save_text("ureports_counter", str(ureports_counter + 1))
+ dd.close()
+ sys.exit(exitcode)
--
1.8.1.4