diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2011-04-22 02:38:45 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2011-04-22 02:38:45 +0200 |
commit | 345d57bc15bb90fe5f7db6d6a3d6898794682d36 (patch) | |
tree | 98c49615be0de1b3f2c4a5ac64d22886038049a2 /src/plugins/abrt-action-list-dsos.py | |
parent | 4b3cb55883bfcb90002da0c21a8c39ac79843b92 (diff) | |
download | abrt-345d57bc15bb90fe5f7db6d6a3d6898794682d36.tar.gz abrt-345d57bc15bb90fe5f7db6d6a3d6898794682d36.tar.xz abrt-345d57bc15bb90fe5f7db6d6a3d6898794682d36.zip |
Make abrt-action-list-dsos.py take -m maps -o dsos params; and abrt-action-analyze-core.py to take -o build_ids param
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/plugins/abrt-action-list-dsos.py')
-rwxr-xr-x | src/plugins/abrt-action-list-dsos.py | 100 |
1 files changed, 83 insertions, 17 deletions
diff --git a/src/plugins/abrt-action-list-dsos.py b/src/plugins/abrt-action-list-dsos.py index d73ed08d..db450ced 100755 --- a/src/plugins/abrt-action-list-dsos.py +++ b/src/plugins/abrt-action-list-dsos.py @@ -1,26 +1,92 @@ -#! /usr/bin/python -u +#!/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. + +import sys +import os +import getopt import rpm -def list_dsos_rpm(dso_paths): +GETTEXT_PROGNAME = "abrt" +import locale +import gettext - ts = rpm.TransactionSet() - for path in dso_paths: - mi = ts.dbMatch('basenames', path) - if len(mi): - for h in mi: - print "%s <> %s - (%s)" % (path, h[rpm.RPMTAG_NEVRA], h[rpm.RPMTAG_VENDOR]) - else: - print "%s doesn't belong to any package" % (path) +_ = lambda x: gettext.lgettext(x) -def parse_maps(maps_path): - f = open(maps_path, "r") - return [x.strip()[x.find('/'):] for x in f.readlines() if x.find('/') > -1] +def log(s): + sys.stderr.write("%s\n" % s) + +def error_msg(s): + sys.stderr.write("%s\n" % s) + +def error_msg_and_die(s): + sys.stderr.write("%s\n" % s) +def xopen(name, mode): + try: + r = open(name, mode) + except IOError, e: + error_msg_and_die("Can't open '%s': %s" % (name, e)); + return r + + +def parse_maps(maps_path): + try: + f = xopen(maps_path, "r") + return [x.strip()[x.find('/'):] for x in f.readlines() if x.find('/') > -1] + except IOError, e: + error_msg_and_die("Can't read '%s': %s" % (name, e)); if __name__ == "__main__": + progname = os.path.basename(sys.argv[0]) + help_text = _("Usage: %s [-o OUTFILE] -m PROC_PID_MAP_FILE") % progname + try: + opts, args = getopt.getopt(sys.argv[1:], "o:m:h", ["help"]) + except getopt.GetoptError, err: + error_msg(err) # prints something like "option -a not recognized" + error_msg_and_die(help_text) + + opt_o = None + memfile = None + + for opt, arg in opts: + if opt in ("-h", "--help"): + print help_text + exit(0) + #elif opt == "-v": + # verbose += 1 + elif opt == "-o": + opt_o = arg + elif opt == "-m": + memfile = arg + + if not memfile: + error_msg(_("MAP_FILE is not specified")) + error_msg_and_die(help_text) + try: - dsos = parse_maps("maps") - list_dsos_rpm(dsos) - except Exception, ex: - print "Couldn't get the dsos list: %s", ex + # Note that we open -o FILE only when we reach the point + # when we are definitely going to write something to it + outfile = sys.stdout + outname = opt_o + try: + dso_paths = parse_maps(memfile) + for path in dso_paths: + ts = rpm.TransactionSet() + mi = ts.dbMatch('basenames', path) + if len(mi): + for h in mi: + if (outname) + outfile = xopen(outname, "w") + outname = None + outfile.write("%s %s (%s)\n" % (path, h[rpm.RPMTAG_NEVRA], h[rpm.RPMTAG_VENDOR])) + + except Exception, ex: + error_msg_and_die("Can't get the DSO list: %s", ex) + + outfile.close() + except: + if not opt_o: + opt_o = "<stdout>" + error_msg_and_die("Error writing to '%s'" % opt_o) |