diff options
Diffstat (limited to 'scripts/send-error-report')
| -rwxr-xr-x | scripts/send-error-report | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/scripts/send-error-report b/scripts/send-error-report index 1a1b96580d..15b5e84911 100755 --- a/scripts/send-error-report +++ b/scripts/send-error-report @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Sends an error report (if the report-error class was enabled) to a # remote server. @@ -7,7 +7,7 @@ # Author: Andreea Proca <andreea.b.proca@intel.com> # Author: Michael Wood <michael.g.wood@intel.com> -import urllib2 +import urllib.request, urllib.error import sys import json import os @@ -15,16 +15,20 @@ import subprocess import argparse import logging +scripts_lib_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib') +sys.path.insert(0, scripts_lib_path) +import argparse_oe + version = "0.3" log = logging.getLogger("send-error-report") logging.basicConfig(format='%(levelname)s: %(message)s') def getPayloadLimit(url): - req = urllib2.Request(url, None) + req = urllib.request.Request(url, None) try: - response = urllib2.urlopen(req) - except urllib2.URLError as e: + response = urllib.request.urlopen(req) + except urllib.error.URLError as e: # Use this opportunity to bail out if we can't even contact the server log.error("Could not contact server: " + url) log.error(e.reason) @@ -40,12 +44,12 @@ def getPayloadLimit(url): def ask_for_contactdetails(): print("Please enter your name and your email (optionally), they'll be saved in the file you send.") - username = raw_input("Name (required): ") - email = raw_input("E-mail (not required): ") + username = input("Name (required): ") + email = input("E-mail (not required): ") return username, email def edit_content(json_file_path): - edit = raw_input("Review information before sending? (y/n): ") + edit = input("Review information before sending? (y/n): ") if 'y' in edit or 'Y' in edit: editor = os.environ.get('EDITOR', None) if editor: @@ -104,7 +108,7 @@ def prepare_data(args): if max_log_size != 0: for fail in jsondata['failures']: if len(fail['log']) > max_log_size: - print "Truncating log to allow for upload" + print("Truncating log to allow for upload") fail['log'] = fail['log'][-max_log_size:] data = json.dumps(jsondata, indent=4, sort_keys=True) @@ -121,7 +125,7 @@ def prepare_data(args): with open(args.error_file, 'r') as json_fp: data = json_fp.read() - return data + return data.encode('utf-8') def send_data(data, args): @@ -132,18 +136,18 @@ def send_data(data, args): else: url = "http://"+args.server+"/ClientPost/" - req = urllib2.Request(url, data=data, headers=headers) + req = urllib.request.Request(url, data=data, headers=headers) try: - response = urllib2.urlopen(req) - except urllib2.HTTPError, e: + response = urllib.request.urlopen(req) + except urllib.error.HTTPError as e: logging.error(e.reason) sys.exit(1) - print response.read() + print(response.read()) if __name__ == '__main__': - arg_parse = argparse.ArgumentParser(description="This scripts will send an error report to your specified error-report-web server.") + arg_parse = argparse_oe.ArgumentParser(description="This scripts will send an error report to your specified error-report-web server.") arg_parse.add_argument("error_file", help="Generated error report file location", @@ -188,7 +192,7 @@ if __name__ == '__main__': args = arg_parse.parse_args() if (args.json == False): - print "Preparing to send errors to: "+args.server + print("Preparing to send errors to: "+args.server) data = prepare_data(args) send_data(data, args) |
