summaryrefslogtreecommitdiffstats
path: root/scripts/send-error-report
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/send-error-report')
-rwxr-xr-xscripts/send-error-report80
1 files changed, 80 insertions, 0 deletions
diff --git a/scripts/send-error-report b/scripts/send-error-report
new file mode 100755
index 0000000000..d23ae27dda
--- /dev/null
+++ b/scripts/send-error-report
@@ -0,0 +1,80 @@
1#!/usr/bin/env python
2
3# Sends an error report (if the report-error class was enabled) to a remote server.
4#
5# Copyright (C) 2013 Intel Corporation
6# Author: Andreea Proca <andreea.b.proca@intel.com>
7
8
9
10import httplib, urllib, os, sys, json
11
12
13def sendData(json_file, server):
14
15 if os.path.isfile(json_file):
16
17 home = os.path.expanduser("~")
18 userfile = os.path.join(home, ".oe-send-error")
19 if os.path.isfile(userfile):
20 with open(userfile) as g:
21 username = g.readline()
22 email = g.readline()
23 else:
24 print("Please enter your name and your email (optionally), they'll be saved in the file you send.")
25 username = raw_input("Name: ")
26 email = raw_input("E-mail (not required): ")
27 if len(username) > 0 and len(username) < 50:
28 with open(userfile, "w") as g:
29 g.write(username + "\n")
30 g.write(email + "\n")
31 else:
32 print("Invalid inputs, try again.")
33 return
34
35 with open(json_file) as f:
36 data = f.read()
37
38 try:
39 jsondata = json.loads(data)
40 jsondata['username'] = username.strip()
41 jsondata['email'] = email.strip()
42 data = json.dumps(jsondata, indent=4, sort_keys=True)
43 except:
44 print("Invalid json data")
45 return
46
47 try:
48 params = urllib.urlencode({'data': data})
49 headers = {"Content-type": "application/json"}
50 conn = httplib.HTTPConnection(server)
51 conn.request("POST", "/ClientPost/", params, headers)
52 response = conn.getresponse()
53 print response.status, response.reason
54 res = response.read()
55 if response.status == 200:
56 print(res)
57 else:
58 print("There was a problem submiting your data, response written in %s.response.html" % json_file)
59 with open("%s.response.html" % json_file, "w") as f:
60 f.write(res)
61 conn.close()
62 except:
63 print("Server connection failed")
64
65 else:
66 print("No data file found.")
67
68
69if __name__ == '__main__':
70 print ("\nSends an error report (if the report-error class was enabled) to a remote server.")
71 if len(sys.argv) < 2:
72 print("\nThis scripts sends the contents of a file to an upstream server.")
73 print("\nUsage: send-error-report <error_fileName> [server]")
74 print("\nIf this is the first when sending a report you'll be asked for your name and optionally your email address.")
75 print("They will be associated with your report.\n")
76
77 elif len(sys.argv) == 3:
78 sendData(sys.argv[1], sys.argv[2])
79 else:
80 sendData(sys.argv[1], "errors.yoctoproject.org")