[FAF PATCH] hub: sort problem packages by tags and counts
by Richard Marko
Rationale behind this is that maintainers
are mainly interested in packages currently
used in the distribution (tagged ones).
Closes #197.
Signed-off-by: Richard Marko <rmarko(a)redhat.com>
---
pyfaf/hub/problems/views.py | 15 +++++++++------
pyfaf/hub/templates/package_table.html | 33 +++++++++++++++++++++++++++++++++
pyfaf/hub/templates/problems/item.html | 4 ++--
pyfaf/storage/opsys.py | 19 +++++++++++++++++++
4 files changed, 63 insertions(+), 8 deletions(-)
create mode 100644 pyfaf/hub/templates/package_table.html
diff --git a/pyfaf/hub/problems/views.py b/pyfaf/hub/problems/views.py
index 4009c4f..8b23c18 100644
--- a/pyfaf/hub/problems/views.py
+++ b/pyfaf/hub/problems/views.py
@@ -124,18 +124,21 @@ def item(request, **kwargs):
.group_by(ReportPackage.installed_package_id)
.order_by(sql.expression.desc('cnt'))
.subquery())
- packages = [(pkg.nevr(), cnt) for (pkg, cnt) in
- db.session.query(Package, sub.c.cnt).join(sub).all()]
+
+ packages = db.session.query(Package, sub.c.cnt).join(sub).all()
# merge packages with different architectures
merged = dict()
for package, count in packages:
- if package in merged:
- merged[package] += count
+ key = package.nevr()
+ if key in merged:
+ merged[key] = (package, merged[key][1] + count)
else:
- merged[package] = count
+ merged[key] = (package, count)
- packages = merged
+ # sort by tag first, count second
+ sort_key = lambda (package, count): (package.build.newest_tag_name, count)
+ packages = sorted(merged.values(), key=sort_key, reverse=True)
forward = { 'problem': problem,
'osreleases': osreleases,
diff --git a/pyfaf/hub/templates/package_table.html b/pyfaf/hub/templates/package_table.html
new file mode 100644
index 0000000..f83d763
--- /dev/null
+++ b/pyfaf/hub/templates/package_table.html
@@ -0,0 +1,33 @@
+{% load custom_filters %}
+
+{% if data %}
+ <table class="table table-striped table-bordered metric">
+ <tr>
+ <th>Name</th>
+ <th>Version</th>
+ <th>Tag</th>
+ <th>Count</th>
+ </tr>
+ {% for package, cnt in data %}
+ <tr
+ {% if forloop.counter > row_limit and data|length > row_limit|add:1 %} {# avoid +1 more #}
+ class='hide'
+ {% endif %}
+ >
+ <td>{{ package.name }}</td>
+ <td>{{ package.nevr }}</td>
+ <td>{{ package.build.newest_tag_name }}</td>
+ <td>{{ cnt }}</td>
+ </tr>
+ {% if data|length > row_limit|add:1 and forloop.counter = row_limit %}
+ <tr>
+ <td colspan='4'>
+ <button class="btn btn-mini btn-more" type="button">
+ + {{ data|length|substract:row_limit }} more
+ </button>
+ </td>
+ </tr>
+ {% endif %}
+ {% endfor %}
+ </table>
+{% endif %}
diff --git a/pyfaf/hub/templates/problems/item.html b/pyfaf/hub/templates/problems/item.html
index 710b1c3..3a66837 100644
--- a/pyfaf/hub/templates/problems/item.html
+++ b/pyfaf/hub/templates/problems/item.html
@@ -124,8 +124,8 @@
{% with 'Package' as metric_name %}
{% with 3 as row_limit %}
- {% with packages.items as data %}
- {% include 'metric_table.html' %}
+ {% with packages as data %}
+ {% include 'package_table.html' %}
{% endwith %}
{% endwith %}
{% endwith %}
diff --git a/pyfaf/storage/opsys.py b/pyfaf/storage/opsys.py
index ee728b3..524fbd6 100644
--- a/pyfaf/storage/opsys.py
+++ b/pyfaf/storage/opsys.py
@@ -177,6 +177,25 @@ class Build(GenericTable):
return self.nvr()
return "{0}-{1}:{2}-{3}".format(self.component.name, self.epoch, self.version, self.release)
+ @property
+ def sorted_tags(self):
+ """
+ Return tags for this build quasi-sorted from newer to older.
+ """
+
+ return sorted(self.tags, key=lambda x: x.name, reverse=True)
+
+ @property
+ def newest_tag_name(self):
+ """
+ Return newest tag string this build has.
+ """
+
+ if self.sorted_tags:
+ return self.sorted_tags[0].name
+
+ return ''
+
class BuildArch(GenericTable):
__tablename__ = "buildarchs"
__lobs__ = { "build.log": 1 << 26, "state.log": 1 << 16, "root.log": 1 << 26 }
--
1.8.1.4
11 years
[FAF PATCH] add faf-koji-update-tags
by Richard Marko
Closes #196.
Signed-off-by: Richard Marko <rmarko(a)redhat.com>
---
bin/Makefile.am | 1 +
bin/faf-koji-update-tags | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
faf.spec.in | 1 +
3 files changed, 91 insertions(+)
create mode 100755 bin/faf-koji-update-tags
diff --git a/bin/Makefile.am b/bin/Makefile.am
index 0bac9dd..463a23a 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -32,6 +32,7 @@ bin_SCRIPTS = \
faf-koji \
faf-koji-pull-builds \
faf-koji-pull-tags \
+ faf-koji-update-tags \
faf-llvm-build \
faf-llvm-build-all \
faf-mail \
diff --git a/bin/faf-koji-update-tags b/bin/faf-koji-update-tags
new file mode 100755
index 0000000..5771de3
--- /dev/null
+++ b/bin/faf-koji-update-tags
@@ -0,0 +1,89 @@
+#!/usr/bin/python
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import sys
+import logging
+
+import koji
+import pyfaf
+
+from pyfaf.storage.opsys import (Tag,
+ OpSys,
+ Build,
+ BuildTag,
+ BuildSystem,
+ OpSysComponent)
+
+# Command line argument processing
+cmdline_parser = pyfaf.argparse.ArgumentParser(
+ description="Update builds with currently assigned tags.")
+cmdline_parser.add_argument("opsys", help="Operating system")
+cmdline = cmdline_parser.parse_args()
+
+db = pyfaf.storage.Database(debug=cmdline.verbose > 2)
+
+buildsys = (db.session.query(BuildSystem)
+ .join(OpSys)
+ .filter(OpSys.name == cmdline.opsys)
+ .first())
+
+if not buildsys:
+ logging.error("No buildsystem found for '{0}'".format(cmdline.opsys))
+ sys.exit(1)
+
+logging.info("Syncing tags for {0}.".format(cmdline.opsys))
+logging.debug("Using {0} as XML-RPC URL.".format(buildsys.xmlrpc_url))
+
+koji_client = koji.ClientSession(buildsys.xmlrpc_url)
+
+db_tags = {}
+for tag in db.session.query(Tag):
+ db_tags[tag.name] = tag
+
+builds = (db.session.query(Build)
+ .join(OpSysComponent)
+ .join(OpSys)
+ .filter(OpSys.name == cmdline.opsys))
+
+result = {}
+for build in builds:
+ nvr = build.nvr()
+
+ remote_tags = set(t['name'] for t in
+ koji_client.listTags(build.secondary_id))
+
+ local_tags = set(t.name for t in build.tags)
+
+ for tag in remote_tags - local_tags:
+ logging.info("Adding tag '{0}' to build '{1}'".format(tag, nvr))
+
+ new = BuildTag()
+ new.build_id = build.id
+ new.tag_id = db_tags[tag].id
+
+ db.session.add(new)
+
+ for tag in local_tags - remote_tags:
+ logging.info("Removing tag '{0}' from build '{1}'".format(tag, nvr))
+
+ build_tag = (db.session.query(BuildTag)
+ .join(Tag)
+ .filter(BuildTag.build_id == build.id)
+ .filter(Tag.name == tag)
+ .one())
+
+ db.session.delete(build_tag)
+
+ db.session.flush()
diff --git a/faf.spec.in b/faf.spec.in
index 5b732ba..cf21ce3 100644
--- a/faf.spec.in
+++ b/faf.spec.in
@@ -267,6 +267,7 @@ fi
%{_bindir}/faf-koji
%{_bindir}/faf-koji-pull-builds
%{_bindir}/faf-koji-pull-tags
+%{_bindir}/faf-koji-update-tags
%{_bindir}/faf-llvm-build
%{_bindir}/faf-llvm-build-all
%{_bindir}/faf-mail
--
1.8.1.4
11 years
[LIBREPORT PATCH] ureport: save solutions in not-reportable item
by Jakub Filak
Solution texts are saved in not-reportable item. Solution URLs are saved
in reported_to.
Closes #156
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/plugins/ureport.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 81 insertions(+), 6 deletions(-)
diff --git a/src/plugins/ureport.c b/src/plugins/ureport.c
index 764c7aa..74f1304 100644
--- a/src/plugins/ureport.c
+++ b/src/plugins/ureport.c
@@ -51,6 +51,7 @@ struct ureport_server_response {
char *message;
char *bthash;
GList *reported_to_list;
+ char *solution;
};
void free_ureport_server_response(struct ureport_server_response *resp)
@@ -58,6 +59,7 @@ void free_ureport_server_response(struct ureport_server_response *resp)
if (!resp)
return;
+ free(resp->solution);
g_list_free_full(resp->reported_to_list, g_free);
free(resp->bthash);
free(resp->message);
@@ -65,6 +67,68 @@ void free_ureport_server_response(struct ureport_server_response *resp)
free(resp);
}
+static char *parse_solution_from_json_list(struct json_object *list, GList **reported_to)
+{
+ json_object *list_elem, *struct_elem;
+ const char *cause, *note, *url;
+ struct strbuf *solution_buf = strbuf_new();
+
+ const unsigned length = json_object_array_length(list);
+
+ const char *one_format = _("Your problem seems to be caused by %s\n\n%s\n");
+ if (length > 1)
+ {
+ strbuf_append_str(solution_buf, _("Your problem seems to be caused by one of the following:\n"));
+ one_format = "\n* %s\n\n%s\n";
+ }
+
+ bool empty = true;
+ for (unsigned i = 0; i < length; ++i)
+ {
+ list_elem = json_object_array_get_idx(list, i);
+ if (!list_elem)
+ continue;
+
+ struct_elem = json_object_object_get(list_elem, "cause");
+ if (!struct_elem)
+ continue;
+
+ cause = json_object_get_string(struct_elem);
+ if (!cause)
+ continue;
+
+ struct_elem = json_object_object_get(list_elem, "note");
+ if (!struct_elem)
+ continue;
+
+ note = json_object_get_string(struct_elem);
+ if (!note)
+ continue;
+
+ empty = false;
+ strbuf_append_strf(solution_buf, one_format, cause, note);
+
+ struct_elem = json_object_object_get(list_elem, "url");
+ if (!struct_elem)
+ continue;
+
+ url = json_object_get_string(struct_elem);
+ if (url)
+ {
+ char *reported_to_line = xasprintf("%s: URL=%s", cause, url);
+ *reported_to = g_list_append(*reported_to, reported_to_line);
+ }
+ }
+
+ if (empty)
+ {
+ strbuf_free(solution_buf);
+ return NULL;
+ }
+
+ return strbuf_free_nobuf(solution_buf);
+}
+
/* reported_to json element should be a list of structures
{ "reporter": "Bugzilla",
"type": "url",
@@ -166,6 +230,10 @@ static struct ureport_server_response *ureport_server_parse_json(json_object *js
if (reported_to_list)
out_response->reported_to_list = parse_reported_to_from_json_list(reported_to_list);
+ json_object *solutions = json_object_object_get(json, "solutions");
+ if (solutions)
+ out_response->solution = parse_solution_from_json_list(solutions, &(out_response->reported_to_list));
+
return out_response;
}
@@ -381,28 +449,35 @@ int main(int argc, char **argv)
VERB1 log("is known: %s", response->value);
ret = 0; /* "success" */
+ dd = dd_opendir(dump_dir_path, /* flags */ 0);
+ if (!dd)
+ xfunc_die();
+
if (response->bthash)
{
- dd = dd_opendir(dump_dir_path, /* flags */ 0);
- if (!dd)
- xfunc_die();
-
char *msg = xasprintf("uReport: BTHASH=%s", response->bthash);
add_reported_to(dd, msg);
free(msg);
+ }
+ if (response->reported_to_list)
+ {
for (GList *e = response->reported_to_list; e; e = g_list_next(e))
add_reported_to(dd, e->data);
-
- dd_close(dd);
}
+ if (response->solution)
+ dd_save_text(dd, FILENAME_NOT_REPORTABLE, response->solution);
+
+ dd_close(dd);
+
/* If a reported problem is not known then emit NEEDMORE */
if (strcmp("true", response->value) == 0)
{
log(_("This problem has already been reported."));
if (response->message)
log(response->message);
+
ret = EXIT_STOP_EVENT_RUN;
}
}
--
1.8.1.4
11 years
[FAF PATCH] pyfaf: return solutions in JSON
by Jakub Filak
A solution is still a part of the message and JSON solution has
been added. The JSON solution is returned in a list because we can
expect that a single problem can have more solutions.
Closes #186
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
pyfaf/hub/reports/views.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/pyfaf/hub/reports/views.py b/pyfaf/hub/reports/views.py
index 1afd2a6..6c7e029 100644
--- a/pyfaf/hub/reports/views.py
+++ b/pyfaf/hub/reports/views.py
@@ -288,6 +288,9 @@ def new(request):
response['message'] += ("\n\nYou can get more information at {0}"
.format(solution.url))
+ response['solutions'] = [{'cause': solution.cause,
+ 'note': solution.note_text,
+ 'url': solution.url}]
response['result'] = True
try:
--
1.8.1.4
11 years
[LIBREPORT PATCH 1/3] do not build or install any piece of BZ when --without-bugzilla
by Michal Toman
Signed-off-by: Michal Toman <mtoman(a)redhat.com>
---
configure.ac | 23 +++++++++++++++++++++++
src/plugins/Makefile.am | 5 ++---
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index 67310d1..179add8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -104,8 +104,31 @@ XMLRPC_CLIENT_CFLAGS=`xmlrpc-c-config client --cflags 2> /dev/null`
XMLRPC_CLIENT_LIBS=`xmlrpc-c-config client --libs 2> /dev/null`
AC_SUBST(XMLRPC_CLIENT_CFLAGS)
AC_SUBST(XMLRPC_CLIENT_LIBS)
+
+# enable bugzilla translations
+for FILE in `grep "#.*ugzilla.*" po/POTFILES.in`
+do
+ sed -ie "s,$FILE,${FILE:1}," po/POTFILES.in
+ sed -ie "\,^${FILE:1}$,d" po/POTFILES.skip
+done
else
AM_CONDITIONAL(BUILD_BUGZILLA, false)
+
+# disablie bugzilla translations
+for FILE in `grep "ugzilla" po/POTFILES.in`
+do
+ if test "${FILE:0:1}" = "#"
+ then
+ continue
+ fi
+
+ sed -ie "s,$FILE,#$FILE," po/POTFILES.in
+ grep "$FILE" po/POTFILES.skip > /dev/null 2>&1
+ if test $?
+ then
+ echo "$FILE" >> po/POTFILES.skip
+ fi
+done
fi dnl end NO_BUGZILLA
AC_PATH_PROG([PYTHON_CONFIG], [python-config], [no])
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 79fe9d2..16ff97c 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -62,14 +62,13 @@ eventsconfdir = $(EVENTS_CONF_DIR)
dist_eventsconf_DATA = \
mailx_event.conf \
print_event.conf \
- bugzilla_event.conf \
rhtsupport_event.conf \
uploader_event.conf \
- emergencyanalysis_event.conf \
- bugzilla_anaconda_event.conf
+ emergencyanalysis_event.conf
reporters_extra_dist =
if BUILD_BUGZILLA
+dist_eventsconf_DATA += bugzilla_event.conf bugzilla_anaconda_event.conf
reporters_extra_dist += report_Bugzilla.xml.in report_Bugzilla.conf
endif
--
1.8.1.4
11 years
[ABRT PATCH v3] abrt-action-ureport: rewrite in python, improve messages
by Denys Vlasenko
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
11 years
[ABRT PATCH v2] abrt-action-ureport: rewrite in python, improve messages
by Denys Vlasenko
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 | 142 +++++++++++++++++++++++++---------------
1 file changed, 89 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..af1e0b4
--- a/src/plugins/abrt-action-ureport
+++ b/src/plugins/abrt-action-ureport
@@ -1,68 +1,104 @@
-#!/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
+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)
+ 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")
+ 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
11 years
[ABRT PATCH v2 1/5] rename problem_api.c -> problem_api_dbus.c
by Jiri Moskovcak
Signed-off-by: Jiri Moskovcak <jmoskovc(a)redhat.com>
---
src/lib/Makefile.am | 2 +-
src/lib/problem_api.c | 176 ---------------------------------------------
src/lib/problem_api_dbus.c | 176 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 177 insertions(+), 177 deletions(-)
delete mode 100644 src/lib/problem_api.c
create mode 100644 src/lib/problem_api_dbus.c
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 4b1ddb9..281e5f3 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -12,7 +12,7 @@ libabrt_la_SOURCES = \
abrt_glib.c \
migrate_dirs.c \
check_recent_crash_file.c \
- problem_api.c \
+ problem_api_dbus.c \
ignored_problems.c
libabrt_la_CPPFLAGS = \
diff --git a/src/lib/problem_api.c b/src/lib/problem_api.c
deleted file mode 100644
index 04f4069..0000000
--- a/src/lib/problem_api.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- Copyright (C) 2011 ABRT Team
- Copyright (C) 2011 RedHat inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#include "libabrt.h"
-
-static GDBusProxy *get_dbus_proxy(void)
-{
- static GDBusProxy *proxy;
-
- /* we cache it, so we can't free it! */
- if (proxy != NULL)
- return proxy;
-
- GError *error = NULL;
- proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- ABRT_DBUS_NAME,
- ABRT_DBUS_OBJECT,
- ABRT_DBUS_IFACE,
- NULL,
- &error);
- if (error)
- {
- error_msg(_("Can't connect to system DBus: %s"), error->message);
- g_error_free(error);
- /* proxy is NULL in this case */
- }
- return proxy;
-}
-
-int chown_dir_over_dbus(const char *problem_dir_path)
-{
- GDBusProxy *proxy = get_dbus_proxy();
- if (!proxy)
- return 1;
-
- GError *error = NULL;
- g_dbus_proxy_call_sync(proxy,
- "ChownProblemDir",
- g_variant_new("(s)", problem_dir_path),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error)
- {
- error_msg(_("Can't chown '%s': %s"), problem_dir_path, error->message);
- g_error_free(error);
- return 1;
- }
- return 0;
-}
-
-int delete_problem_dirs_over_dbus(const GList *problem_dir_paths)
-{
- GDBusProxy *proxy = get_dbus_proxy();
- if (!proxy)
- return 1;
-
- GVariant *parameters = variant_from_string_list(problem_dir_paths);
-
- GError *error = NULL;
- g_dbus_proxy_call_sync(proxy,
- "DeleteProblem",
- parameters,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-//g_variant_unref(parameters); -- need this??? no?? why?
-
- if (error)
- {
- error_msg(_("Deleting problem directory failed: %s"), error->message);
- g_error_free(error);
- return 1;
- }
- return 0;
-}
-
-problem_data_t *get_problem_data_dbus(const char *problem_dir_path)
-{
- GDBusProxy *proxy = get_dbus_proxy();
- if (!proxy)
- return NULL;
-
- GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
- g_variant_builder_add(builder, "s", FILENAME_TIME );
- g_variant_builder_add(builder, "s", FILENAME_REASON );
- g_variant_builder_add(builder, "s", FILENAME_NOT_REPORTABLE);
- g_variant_builder_add(builder, "s", FILENAME_COMPONENT );
- g_variant_builder_add(builder, "s", FILENAME_EXECUTABLE );
- g_variant_builder_add(builder, "s", FILENAME_REPORTED_TO );
- GVariant *params = g_variant_new("(sas)", problem_dir_path, builder);
- g_variant_builder_unref(builder);
-
- GError *error = NULL;
- GVariant *result = g_dbus_proxy_call_sync(proxy,
- "GetInfo",
- params,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error)
- {
- error_msg(_("Can't get problem data from abrt-dbus: %s"), error->message);
- g_error_free(error);
- return NULL;
- }
-
- problem_data_t *pd = problem_data_new();
- char *key, *val;
- GVariantIter *iter;
- g_variant_get(result, "(a{ss})", &iter);
- while (g_variant_iter_loop(iter, "{ss}", &key, &val))
- {
- problem_data_add_text_noteditable(pd, key, val);
- }
- g_variant_unref(result);
- return pd;
-}
-
-GList *get_problems_over_dbus(bool authorize)
-{
- GDBusProxy *proxy = get_dbus_proxy();
- if (!proxy)
- return ERR_PTR;
-
- GError *error = NULL;
- GVariant *result = g_dbus_proxy_call_sync(proxy,
- authorize ? "GetAllProblems" : "GetProblems",
- g_variant_new("()"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error)
- {
- error_msg(_("Can't get problem list from abrt-dbus: %s"), error->message);
- g_error_free(error);
- return ERR_PTR;
- }
-
- GList *list = NULL;
- if (result)
- {
- /* Fetch "as" from "(as)" */
- GVariant *array = g_variant_get_child_value(result, 0);
- list = string_list_from_variant(array);
- g_variant_unref(array);
- g_variant_unref(result);
- }
-
- return list;
-}
diff --git a/src/lib/problem_api_dbus.c b/src/lib/problem_api_dbus.c
new file mode 100644
index 0000000..04f4069
--- /dev/null
+++ b/src/lib/problem_api_dbus.c
@@ -0,0 +1,176 @@
+/*
+ Copyright (C) 2011 ABRT Team
+ Copyright (C) 2011 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "libabrt.h"
+
+static GDBusProxy *get_dbus_proxy(void)
+{
+ static GDBusProxy *proxy;
+
+ /* we cache it, so we can't free it! */
+ if (proxy != NULL)
+ return proxy;
+
+ GError *error = NULL;
+ proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ ABRT_DBUS_NAME,
+ ABRT_DBUS_OBJECT,
+ ABRT_DBUS_IFACE,
+ NULL,
+ &error);
+ if (error)
+ {
+ error_msg(_("Can't connect to system DBus: %s"), error->message);
+ g_error_free(error);
+ /* proxy is NULL in this case */
+ }
+ return proxy;
+}
+
+int chown_dir_over_dbus(const char *problem_dir_path)
+{
+ GDBusProxy *proxy = get_dbus_proxy();
+ if (!proxy)
+ return 1;
+
+ GError *error = NULL;
+ g_dbus_proxy_call_sync(proxy,
+ "ChownProblemDir",
+ g_variant_new("(s)", problem_dir_path),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error)
+ {
+ error_msg(_("Can't chown '%s': %s"), problem_dir_path, error->message);
+ g_error_free(error);
+ return 1;
+ }
+ return 0;
+}
+
+int delete_problem_dirs_over_dbus(const GList *problem_dir_paths)
+{
+ GDBusProxy *proxy = get_dbus_proxy();
+ if (!proxy)
+ return 1;
+
+ GVariant *parameters = variant_from_string_list(problem_dir_paths);
+
+ GError *error = NULL;
+ g_dbus_proxy_call_sync(proxy,
+ "DeleteProblem",
+ parameters,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+//g_variant_unref(parameters); -- need this??? no?? why?
+
+ if (error)
+ {
+ error_msg(_("Deleting problem directory failed: %s"), error->message);
+ g_error_free(error);
+ return 1;
+ }
+ return 0;
+}
+
+problem_data_t *get_problem_data_dbus(const char *problem_dir_path)
+{
+ GDBusProxy *proxy = get_dbus_proxy();
+ if (!proxy)
+ return NULL;
+
+ GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+ g_variant_builder_add(builder, "s", FILENAME_TIME );
+ g_variant_builder_add(builder, "s", FILENAME_REASON );
+ g_variant_builder_add(builder, "s", FILENAME_NOT_REPORTABLE);
+ g_variant_builder_add(builder, "s", FILENAME_COMPONENT );
+ g_variant_builder_add(builder, "s", FILENAME_EXECUTABLE );
+ g_variant_builder_add(builder, "s", FILENAME_REPORTED_TO );
+ GVariant *params = g_variant_new("(sas)", problem_dir_path, builder);
+ g_variant_builder_unref(builder);
+
+ GError *error = NULL;
+ GVariant *result = g_dbus_proxy_call_sync(proxy,
+ "GetInfo",
+ params,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error)
+ {
+ error_msg(_("Can't get problem data from abrt-dbus: %s"), error->message);
+ g_error_free(error);
+ return NULL;
+ }
+
+ problem_data_t *pd = problem_data_new();
+ char *key, *val;
+ GVariantIter *iter;
+ g_variant_get(result, "(a{ss})", &iter);
+ while (g_variant_iter_loop(iter, "{ss}", &key, &val))
+ {
+ problem_data_add_text_noteditable(pd, key, val);
+ }
+ g_variant_unref(result);
+ return pd;
+}
+
+GList *get_problems_over_dbus(bool authorize)
+{
+ GDBusProxy *proxy = get_dbus_proxy();
+ if (!proxy)
+ return ERR_PTR;
+
+ GError *error = NULL;
+ GVariant *result = g_dbus_proxy_call_sync(proxy,
+ authorize ? "GetAllProblems" : "GetProblems",
+ g_variant_new("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error)
+ {
+ error_msg(_("Can't get problem list from abrt-dbus: %s"), error->message);
+ g_error_free(error);
+ return ERR_PTR;
+ }
+
+ GList *list = NULL;
+ if (result)
+ {
+ /* Fetch "as" from "(as)" */
+ GVariant *array = g_variant_get_child_value(result, 0);
+ list = string_list_from_variant(array);
+ g_variant_unref(array);
+ g_variant_unref(result);
+ }
+
+ return list;
+}
--
1.8.1.4
11 years
[LIBREPORT PATCH v2 1/5] rename problem_api.c -> problem_api_dbus.c
by Jiri Moskovcak
Signed-off-by: Jiri Moskovcak <jmoskovc(a)redhat.com>
---
src/lib/Makefile.am | 2 +-
src/lib/problem_api.c | 176 ---------------------------------------------
src/lib/problem_api_dbus.c | 176 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 177 insertions(+), 177 deletions(-)
delete mode 100644 src/lib/problem_api.c
create mode 100644 src/lib/problem_api_dbus.c
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 4b1ddb9..281e5f3 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -12,7 +12,7 @@ libabrt_la_SOURCES = \
abrt_glib.c \
migrate_dirs.c \
check_recent_crash_file.c \
- problem_api.c \
+ problem_api_dbus.c \
ignored_problems.c
libabrt_la_CPPFLAGS = \
diff --git a/src/lib/problem_api.c b/src/lib/problem_api.c
deleted file mode 100644
index 04f4069..0000000
--- a/src/lib/problem_api.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- Copyright (C) 2011 ABRT Team
- Copyright (C) 2011 RedHat inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#include "libabrt.h"
-
-static GDBusProxy *get_dbus_proxy(void)
-{
- static GDBusProxy *proxy;
-
- /* we cache it, so we can't free it! */
- if (proxy != NULL)
- return proxy;
-
- GError *error = NULL;
- proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- ABRT_DBUS_NAME,
- ABRT_DBUS_OBJECT,
- ABRT_DBUS_IFACE,
- NULL,
- &error);
- if (error)
- {
- error_msg(_("Can't connect to system DBus: %s"), error->message);
- g_error_free(error);
- /* proxy is NULL in this case */
- }
- return proxy;
-}
-
-int chown_dir_over_dbus(const char *problem_dir_path)
-{
- GDBusProxy *proxy = get_dbus_proxy();
- if (!proxy)
- return 1;
-
- GError *error = NULL;
- g_dbus_proxy_call_sync(proxy,
- "ChownProblemDir",
- g_variant_new("(s)", problem_dir_path),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error)
- {
- error_msg(_("Can't chown '%s': %s"), problem_dir_path, error->message);
- g_error_free(error);
- return 1;
- }
- return 0;
-}
-
-int delete_problem_dirs_over_dbus(const GList *problem_dir_paths)
-{
- GDBusProxy *proxy = get_dbus_proxy();
- if (!proxy)
- return 1;
-
- GVariant *parameters = variant_from_string_list(problem_dir_paths);
-
- GError *error = NULL;
- g_dbus_proxy_call_sync(proxy,
- "DeleteProblem",
- parameters,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-//g_variant_unref(parameters); -- need this??? no?? why?
-
- if (error)
- {
- error_msg(_("Deleting problem directory failed: %s"), error->message);
- g_error_free(error);
- return 1;
- }
- return 0;
-}
-
-problem_data_t *get_problem_data_dbus(const char *problem_dir_path)
-{
- GDBusProxy *proxy = get_dbus_proxy();
- if (!proxy)
- return NULL;
-
- GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
- g_variant_builder_add(builder, "s", FILENAME_TIME );
- g_variant_builder_add(builder, "s", FILENAME_REASON );
- g_variant_builder_add(builder, "s", FILENAME_NOT_REPORTABLE);
- g_variant_builder_add(builder, "s", FILENAME_COMPONENT );
- g_variant_builder_add(builder, "s", FILENAME_EXECUTABLE );
- g_variant_builder_add(builder, "s", FILENAME_REPORTED_TO );
- GVariant *params = g_variant_new("(sas)", problem_dir_path, builder);
- g_variant_builder_unref(builder);
-
- GError *error = NULL;
- GVariant *result = g_dbus_proxy_call_sync(proxy,
- "GetInfo",
- params,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error)
- {
- error_msg(_("Can't get problem data from abrt-dbus: %s"), error->message);
- g_error_free(error);
- return NULL;
- }
-
- problem_data_t *pd = problem_data_new();
- char *key, *val;
- GVariantIter *iter;
- g_variant_get(result, "(a{ss})", &iter);
- while (g_variant_iter_loop(iter, "{ss}", &key, &val))
- {
- problem_data_add_text_noteditable(pd, key, val);
- }
- g_variant_unref(result);
- return pd;
-}
-
-GList *get_problems_over_dbus(bool authorize)
-{
- GDBusProxy *proxy = get_dbus_proxy();
- if (!proxy)
- return ERR_PTR;
-
- GError *error = NULL;
- GVariant *result = g_dbus_proxy_call_sync(proxy,
- authorize ? "GetAllProblems" : "GetProblems",
- g_variant_new("()"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error)
- {
- error_msg(_("Can't get problem list from abrt-dbus: %s"), error->message);
- g_error_free(error);
- return ERR_PTR;
- }
-
- GList *list = NULL;
- if (result)
- {
- /* Fetch "as" from "(as)" */
- GVariant *array = g_variant_get_child_value(result, 0);
- list = string_list_from_variant(array);
- g_variant_unref(array);
- g_variant_unref(result);
- }
-
- return list;
-}
diff --git a/src/lib/problem_api_dbus.c b/src/lib/problem_api_dbus.c
new file mode 100644
index 0000000..04f4069
--- /dev/null
+++ b/src/lib/problem_api_dbus.c
@@ -0,0 +1,176 @@
+/*
+ Copyright (C) 2011 ABRT Team
+ Copyright (C) 2011 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "libabrt.h"
+
+static GDBusProxy *get_dbus_proxy(void)
+{
+ static GDBusProxy *proxy;
+
+ /* we cache it, so we can't free it! */
+ if (proxy != NULL)
+ return proxy;
+
+ GError *error = NULL;
+ proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ ABRT_DBUS_NAME,
+ ABRT_DBUS_OBJECT,
+ ABRT_DBUS_IFACE,
+ NULL,
+ &error);
+ if (error)
+ {
+ error_msg(_("Can't connect to system DBus: %s"), error->message);
+ g_error_free(error);
+ /* proxy is NULL in this case */
+ }
+ return proxy;
+}
+
+int chown_dir_over_dbus(const char *problem_dir_path)
+{
+ GDBusProxy *proxy = get_dbus_proxy();
+ if (!proxy)
+ return 1;
+
+ GError *error = NULL;
+ g_dbus_proxy_call_sync(proxy,
+ "ChownProblemDir",
+ g_variant_new("(s)", problem_dir_path),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error)
+ {
+ error_msg(_("Can't chown '%s': %s"), problem_dir_path, error->message);
+ g_error_free(error);
+ return 1;
+ }
+ return 0;
+}
+
+int delete_problem_dirs_over_dbus(const GList *problem_dir_paths)
+{
+ GDBusProxy *proxy = get_dbus_proxy();
+ if (!proxy)
+ return 1;
+
+ GVariant *parameters = variant_from_string_list(problem_dir_paths);
+
+ GError *error = NULL;
+ g_dbus_proxy_call_sync(proxy,
+ "DeleteProblem",
+ parameters,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+//g_variant_unref(parameters); -- need this??? no?? why?
+
+ if (error)
+ {
+ error_msg(_("Deleting problem directory failed: %s"), error->message);
+ g_error_free(error);
+ return 1;
+ }
+ return 0;
+}
+
+problem_data_t *get_problem_data_dbus(const char *problem_dir_path)
+{
+ GDBusProxy *proxy = get_dbus_proxy();
+ if (!proxy)
+ return NULL;
+
+ GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+ g_variant_builder_add(builder, "s", FILENAME_TIME );
+ g_variant_builder_add(builder, "s", FILENAME_REASON );
+ g_variant_builder_add(builder, "s", FILENAME_NOT_REPORTABLE);
+ g_variant_builder_add(builder, "s", FILENAME_COMPONENT );
+ g_variant_builder_add(builder, "s", FILENAME_EXECUTABLE );
+ g_variant_builder_add(builder, "s", FILENAME_REPORTED_TO );
+ GVariant *params = g_variant_new("(sas)", problem_dir_path, builder);
+ g_variant_builder_unref(builder);
+
+ GError *error = NULL;
+ GVariant *result = g_dbus_proxy_call_sync(proxy,
+ "GetInfo",
+ params,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error)
+ {
+ error_msg(_("Can't get problem data from abrt-dbus: %s"), error->message);
+ g_error_free(error);
+ return NULL;
+ }
+
+ problem_data_t *pd = problem_data_new();
+ char *key, *val;
+ GVariantIter *iter;
+ g_variant_get(result, "(a{ss})", &iter);
+ while (g_variant_iter_loop(iter, "{ss}", &key, &val))
+ {
+ problem_data_add_text_noteditable(pd, key, val);
+ }
+ g_variant_unref(result);
+ return pd;
+}
+
+GList *get_problems_over_dbus(bool authorize)
+{
+ GDBusProxy *proxy = get_dbus_proxy();
+ if (!proxy)
+ return ERR_PTR;
+
+ GError *error = NULL;
+ GVariant *result = g_dbus_proxy_call_sync(proxy,
+ authorize ? "GetAllProblems" : "GetProblems",
+ g_variant_new("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error)
+ {
+ error_msg(_("Can't get problem list from abrt-dbus: %s"), error->message);
+ g_error_free(error);
+ return ERR_PTR;
+ }
+
+ GList *list = NULL;
+ if (result)
+ {
+ /* Fetch "as" from "(as)" */
+ GVariant *array = g_variant_get_child_value(result, 0);
+ list = string_list_from_variant(array);
+ g_variant_unref(array);
+ g_variant_unref(result);
+ }
+
+ return list;
+}
--
1.8.1.4
11 years
[LIBREPORT PATCH v2 1/5] rename problem_api.c -> problem_api_dbus.c
by Jiri Moskovcak
Signed-off-by: Jiri Moskovcak <jmoskovc(a)redhat.com>
---
src/lib/Makefile.am | 2 +-
src/lib/problem_api.c | 176 ---------------------------------------------
src/lib/problem_api_dbus.c | 176 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 177 insertions(+), 177 deletions(-)
delete mode 100644 src/lib/problem_api.c
create mode 100644 src/lib/problem_api_dbus.c
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 4b1ddb9..281e5f3 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -12,7 +12,7 @@ libabrt_la_SOURCES = \
abrt_glib.c \
migrate_dirs.c \
check_recent_crash_file.c \
- problem_api.c \
+ problem_api_dbus.c \
ignored_problems.c
libabrt_la_CPPFLAGS = \
diff --git a/src/lib/problem_api.c b/src/lib/problem_api.c
deleted file mode 100644
index 04f4069..0000000
--- a/src/lib/problem_api.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- Copyright (C) 2011 ABRT Team
- Copyright (C) 2011 RedHat inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#include "libabrt.h"
-
-static GDBusProxy *get_dbus_proxy(void)
-{
- static GDBusProxy *proxy;
-
- /* we cache it, so we can't free it! */
- if (proxy != NULL)
- return proxy;
-
- GError *error = NULL;
- proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- ABRT_DBUS_NAME,
- ABRT_DBUS_OBJECT,
- ABRT_DBUS_IFACE,
- NULL,
- &error);
- if (error)
- {
- error_msg(_("Can't connect to system DBus: %s"), error->message);
- g_error_free(error);
- /* proxy is NULL in this case */
- }
- return proxy;
-}
-
-int chown_dir_over_dbus(const char *problem_dir_path)
-{
- GDBusProxy *proxy = get_dbus_proxy();
- if (!proxy)
- return 1;
-
- GError *error = NULL;
- g_dbus_proxy_call_sync(proxy,
- "ChownProblemDir",
- g_variant_new("(s)", problem_dir_path),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error)
- {
- error_msg(_("Can't chown '%s': %s"), problem_dir_path, error->message);
- g_error_free(error);
- return 1;
- }
- return 0;
-}
-
-int delete_problem_dirs_over_dbus(const GList *problem_dir_paths)
-{
- GDBusProxy *proxy = get_dbus_proxy();
- if (!proxy)
- return 1;
-
- GVariant *parameters = variant_from_string_list(problem_dir_paths);
-
- GError *error = NULL;
- g_dbus_proxy_call_sync(proxy,
- "DeleteProblem",
- parameters,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-//g_variant_unref(parameters); -- need this??? no?? why?
-
- if (error)
- {
- error_msg(_("Deleting problem directory failed: %s"), error->message);
- g_error_free(error);
- return 1;
- }
- return 0;
-}
-
-problem_data_t *get_problem_data_dbus(const char *problem_dir_path)
-{
- GDBusProxy *proxy = get_dbus_proxy();
- if (!proxy)
- return NULL;
-
- GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
- g_variant_builder_add(builder, "s", FILENAME_TIME );
- g_variant_builder_add(builder, "s", FILENAME_REASON );
- g_variant_builder_add(builder, "s", FILENAME_NOT_REPORTABLE);
- g_variant_builder_add(builder, "s", FILENAME_COMPONENT );
- g_variant_builder_add(builder, "s", FILENAME_EXECUTABLE );
- g_variant_builder_add(builder, "s", FILENAME_REPORTED_TO );
- GVariant *params = g_variant_new("(sas)", problem_dir_path, builder);
- g_variant_builder_unref(builder);
-
- GError *error = NULL;
- GVariant *result = g_dbus_proxy_call_sync(proxy,
- "GetInfo",
- params,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error)
- {
- error_msg(_("Can't get problem data from abrt-dbus: %s"), error->message);
- g_error_free(error);
- return NULL;
- }
-
- problem_data_t *pd = problem_data_new();
- char *key, *val;
- GVariantIter *iter;
- g_variant_get(result, "(a{ss})", &iter);
- while (g_variant_iter_loop(iter, "{ss}", &key, &val))
- {
- problem_data_add_text_noteditable(pd, key, val);
- }
- g_variant_unref(result);
- return pd;
-}
-
-GList *get_problems_over_dbus(bool authorize)
-{
- GDBusProxy *proxy = get_dbus_proxy();
- if (!proxy)
- return ERR_PTR;
-
- GError *error = NULL;
- GVariant *result = g_dbus_proxy_call_sync(proxy,
- authorize ? "GetAllProblems" : "GetProblems",
- g_variant_new("()"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error)
- {
- error_msg(_("Can't get problem list from abrt-dbus: %s"), error->message);
- g_error_free(error);
- return ERR_PTR;
- }
-
- GList *list = NULL;
- if (result)
- {
- /* Fetch "as" from "(as)" */
- GVariant *array = g_variant_get_child_value(result, 0);
- list = string_list_from_variant(array);
- g_variant_unref(array);
- g_variant_unref(result);
- }
-
- return list;
-}
diff --git a/src/lib/problem_api_dbus.c b/src/lib/problem_api_dbus.c
new file mode 100644
index 0000000..04f4069
--- /dev/null
+++ b/src/lib/problem_api_dbus.c
@@ -0,0 +1,176 @@
+/*
+ Copyright (C) 2011 ABRT Team
+ Copyright (C) 2011 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "libabrt.h"
+
+static GDBusProxy *get_dbus_proxy(void)
+{
+ static GDBusProxy *proxy;
+
+ /* we cache it, so we can't free it! */
+ if (proxy != NULL)
+ return proxy;
+
+ GError *error = NULL;
+ proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ ABRT_DBUS_NAME,
+ ABRT_DBUS_OBJECT,
+ ABRT_DBUS_IFACE,
+ NULL,
+ &error);
+ if (error)
+ {
+ error_msg(_("Can't connect to system DBus: %s"), error->message);
+ g_error_free(error);
+ /* proxy is NULL in this case */
+ }
+ return proxy;
+}
+
+int chown_dir_over_dbus(const char *problem_dir_path)
+{
+ GDBusProxy *proxy = get_dbus_proxy();
+ if (!proxy)
+ return 1;
+
+ GError *error = NULL;
+ g_dbus_proxy_call_sync(proxy,
+ "ChownProblemDir",
+ g_variant_new("(s)", problem_dir_path),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error)
+ {
+ error_msg(_("Can't chown '%s': %s"), problem_dir_path, error->message);
+ g_error_free(error);
+ return 1;
+ }
+ return 0;
+}
+
+int delete_problem_dirs_over_dbus(const GList *problem_dir_paths)
+{
+ GDBusProxy *proxy = get_dbus_proxy();
+ if (!proxy)
+ return 1;
+
+ GVariant *parameters = variant_from_string_list(problem_dir_paths);
+
+ GError *error = NULL;
+ g_dbus_proxy_call_sync(proxy,
+ "DeleteProblem",
+ parameters,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+//g_variant_unref(parameters); -- need this??? no?? why?
+
+ if (error)
+ {
+ error_msg(_("Deleting problem directory failed: %s"), error->message);
+ g_error_free(error);
+ return 1;
+ }
+ return 0;
+}
+
+problem_data_t *get_problem_data_dbus(const char *problem_dir_path)
+{
+ GDBusProxy *proxy = get_dbus_proxy();
+ if (!proxy)
+ return NULL;
+
+ GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+ g_variant_builder_add(builder, "s", FILENAME_TIME );
+ g_variant_builder_add(builder, "s", FILENAME_REASON );
+ g_variant_builder_add(builder, "s", FILENAME_NOT_REPORTABLE);
+ g_variant_builder_add(builder, "s", FILENAME_COMPONENT );
+ g_variant_builder_add(builder, "s", FILENAME_EXECUTABLE );
+ g_variant_builder_add(builder, "s", FILENAME_REPORTED_TO );
+ GVariant *params = g_variant_new("(sas)", problem_dir_path, builder);
+ g_variant_builder_unref(builder);
+
+ GError *error = NULL;
+ GVariant *result = g_dbus_proxy_call_sync(proxy,
+ "GetInfo",
+ params,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error)
+ {
+ error_msg(_("Can't get problem data from abrt-dbus: %s"), error->message);
+ g_error_free(error);
+ return NULL;
+ }
+
+ problem_data_t *pd = problem_data_new();
+ char *key, *val;
+ GVariantIter *iter;
+ g_variant_get(result, "(a{ss})", &iter);
+ while (g_variant_iter_loop(iter, "{ss}", &key, &val))
+ {
+ problem_data_add_text_noteditable(pd, key, val);
+ }
+ g_variant_unref(result);
+ return pd;
+}
+
+GList *get_problems_over_dbus(bool authorize)
+{
+ GDBusProxy *proxy = get_dbus_proxy();
+ if (!proxy)
+ return ERR_PTR;
+
+ GError *error = NULL;
+ GVariant *result = g_dbus_proxy_call_sync(proxy,
+ authorize ? "GetAllProblems" : "GetProblems",
+ g_variant_new("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error)
+ {
+ error_msg(_("Can't get problem list from abrt-dbus: %s"), error->message);
+ g_error_free(error);
+ return ERR_PTR;
+ }
+
+ GList *list = NULL;
+ if (result)
+ {
+ /* Fetch "as" from "(as)" */
+ GVariant *array = g_variant_get_child_value(result, 0);
+ list = string_list_from_variant(array);
+ g_variant_unref(array);
+ g_variant_unref(result);
+ }
+
+ return list;
+}
--
1.8.1.4
11 years