From dca52050225bbfe62bf9e7d1eac735feffc95fc3 Mon Sep 17 00:00:00 2001 From: lxnay Date: Thu, 9 Aug 2007 18:45:46 +0000 Subject: [PATCH] add error reporting tool git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@429 cd1c1023-2f26-0410-ae45-c471fc1f0318 --- client/equo | 93 ++++++++++++++++++++++++++--------- handlers/error_report.php | 11 +++++ libraries/activatorTools.py | 2 +- libraries/entropyConstants.py | 1 + libraries/outputTools.py | 2 +- libraries/remoteTools.py | 23 +++++++++ 6 files changed, 106 insertions(+), 26 deletions(-) create mode 100644 handlers/error_report.php diff --git a/client/equo b/client/equo index 85dadc183..c00bde410 100644 --- a/client/equo +++ b/client/equo @@ -97,31 +97,76 @@ if len(options) < 1 or string.join(options).find("--help") != -1 or string.join( entropyTools.print_error("not enough parameters") sys.exit(1) -# sync mirrors tool -elif (options[0] == "update") or (options[0] == "repoinfo") or (options[0] == "status"): - if options[0] == "update": - entropyTools.applicationLockCheck("update") - rc = equoTools.repositories(options) - sys.exit(rc) +try: + # sync mirrors tool + if (options[0] == "update") or (options[0] == "repoinfo") or (options[0] == "status"): + if options[0] == "update": + entropyTools.applicationLockCheck("update") + rc = equoTools.repositories(options) + sys.exit(rc) -elif (options[0] == "search") or (options[0] == "install") or (options[0] == "remove") or (options[0] == "deptest"): - if options[0] == "install": - entropyTools.applicationLockCheck("install") - elif options[0] == "remove": - entropyTools.applicationLockCheck("remove") - rc = equoTools.package(options) - sys.exit(rc) + elif (options[0] == "search") or (options[0] == "install") or (options[0] == "remove") or (options[0] == "deptest"): + if options[0] == "install": + entropyTools.applicationLockCheck("install") + elif options[0] == "remove": + entropyTools.applicationLockCheck("remove") + rc = equoTools.package(options) + sys.exit(rc) -elif (options[0] == "query"): - rc = equoTools.query(options[1:]) - sys.exit(rc) + elif (options[0] == "query"): + rc = equoTools.query(options[1:]) + sys.exit(rc) -elif (options[0] == "database"): - entropyTools.applicationLockCheck("database") - rc = equoTools.database(options[1:]) - sys.exit(rc) + elif (options[0] == "database"): + entropyTools.applicationLockCheck("database") + rc = equoTools.database(options[1:]) + sys.exit(rc) -elif (options[0] == "cleanup"): - entropyTools.applicationLockCheck("cleanup") - entropyTools.cleanup([ etpConst['packagestmpdir'], etpConst['logdir'], etpConst['entropyunpackdir'], etpConst['packagesbindir'] ]) - sys.exit(0) \ No newline at end of file + elif (options[0] == "cleanup"): + entropyTools.applicationLockCheck("cleanup") + entropyTools.cleanup([ etpConst['packagestmpdir'], etpConst['logdir'], etpConst['entropyunpackdir'], etpConst['packagesbindir'] ]) + sys.exit(0) +except: + from entropyTools import askquestion + from remoteTools import getOnlineContent, reportApplicationError + import string + print_error(darkred("Hi. My name is Bug Reporter. I am sorry to inform you that Equo crashed. Well, you know, shit happens.")) + print_error(darkred("But there's something you could do to help Equo to be a better application.")) + print_error(darkgreen("Now I am showing you what happened. Don't panic, I'm here to help you. Suddenly happened:")) + print + import traceback + traceback.print_exc() + try: + ferror = open("/tmp/equoerror.txt","w") + traceback.print_exc(file = ferror) + ferror.flush() + ferror.close() + f = open("/tmp/equoerror.txt","r") + errorText = f.readlines() + f.close() + errorText = string.join(errorText," ") + except: + print + print_error(darkred("Oh well, I cannot even write to /tmp. So, please copy the error and mail lxnay@sabayonlinux.org.")) + sys.exit(1) + print + print_error(blue("Ok, back here. Let me see if you are connected to the Internet. Yes, I am blue now, so?")) + conntest = getOnlineContent("http://svn.sabayonlinux.org") + if (conntest != False): + print_error(darkgreen("Of course you are on the Internet...")) + rc = askquestion(" Erm... Can I send the error to my creators so they can fix me?") + if rc == "No": + print_error(darkgreen("Ok, ok ok ok... Sorry!")) + sys.exit(2) + else: + print_error(darkgreen("Gosh, you aren't! Well, I wrote the error to /tmp/equoerror.txt. When you want, mail the file to lxnay@sabayonlinux.org.")) + sys.exit(3) + + # ok, come on! + result = reportApplicationError(errorText) + if (result != False): + print_error(darkgreen("Thank you very much. The error has been reported and hopefully, the problem will be solved as soon as possible.")) + else: + print_error(darkred("Ugh. Cannot send the report. I saved the error to /tmp/equoerror.txt. When you want, mail the file to lxnay@sabayonlinux.org.")) + sys.exit(4) + \ No newline at end of file diff --git a/handlers/error_report.php b/handlers/error_report.php new file mode 100644 index 000000000..99cf0695c --- /dev/null +++ b/handlers/error_report.php @@ -0,0 +1,11 @@ +Entropy Error Reporting Handler

'; +$message .= $_GET['stacktrace'] . "


Architecture: " . $arch . "

"; +print_r($message); +mail($mail,$subject,$message, $header); +?> \ No newline at end of file diff --git a/libraries/activatorTools.py b/libraries/activatorTools.py index b953f6eec..afd06e5a2 100644 --- a/libraries/activatorTools.py +++ b/libraries/activatorTools.py @@ -641,7 +641,7 @@ def packages(options): print_error(yellow(" * ")+red("packages: Exception caught: ")+str(e)+red(" . Showing traceback:")) import traceback - traceback.print_stack() + traceback.print_exc() # trap CTRL+C if (str(e) == "100"): diff --git a/libraries/entropyConstants.py b/libraries/entropyConstants.py index b18194803..430c9d7da 100644 --- a/libraries/entropyConstants.py +++ b/libraries/entropyConstants.py @@ -384,6 +384,7 @@ else: # Handlers used by entropy to run and retrieve data remotely, using php helpers etpHandlers = { 'md5sum': "md5sum.php?arch="+ETP_ARCH_CONST+"&package=", # md5sum handler + 'errorsend': "http://svn.sabayonlinux.org/entropy/handlers/error_report.php?arch="+ETP_ARCH_CONST+"&stacktrace=", } diff --git a/libraries/outputTools.py b/libraries/outputTools.py index dc93c520d..c22692d77 100644 --- a/libraries/outputTools.py +++ b/libraries/outputTools.py @@ -230,7 +230,7 @@ def print_error(msg, back = False): if (back): writechar("\r"+red(">>")+" "+msg) return - print green(">>")+" "+msg + print red(">>")+" "+msg def print_info(msg, back = False): writechar("\r"+_cleanline+"\r") diff --git a/libraries/remoteTools.py b/libraries/remoteTools.py index 0ca336081..57f4b3cbd 100644 --- a/libraries/remoteTools.py +++ b/libraries/remoteTools.py @@ -27,6 +27,7 @@ from entropyConstants import * from clientConstants import * from outputTools import * import entropyTools +import string # Logging initialization import logTools @@ -108,6 +109,28 @@ def getOnlineContent(url): except: return False +# Error reporting function +# @input: error string (please use repr()) +# @returns bool: True if ok. False if not. +# @returns False: if the file is not found +def reportApplicationError(errorstring): + remoteLog.log(ETP_LOGPRI_INFO,ETP_LOGLEVEL_VERBOSE,"reportApplicationError: called. Requested string -> "+str(errorstring)) + outstring = "" + for char in errorstring: + if char == " ": + char = "%20" + outstring += char + outstring = outstring.split("\n") + outstring = string.join(outstring,"
") + url = etpHandlers['errorsend']+outstring + # now pray the server + try: + file = urllib2.urlopen(url) + result = file.readlines() + return result + except: + return False + ################################################### # HTTP/FTP equo INTERNAL FUNCTIONS ###################################################