author | Simon Howkins <simonh@symbian.org> |
Mon, 05 Oct 2009 18:14:18 +0100 | |
changeset 592 | 85da6704f82d |
child 778 | 33511d5b1edb |
permissions | -rw-r--r-- |
592
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
1 |
command_help = """ |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
2 |
Send XML data from file to Diamonds. v.1.23 |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
3 |
Use: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
4 |
send_xml_to_diamonds.py options |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
5 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
6 |
Mandatory options: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
7 |
-s Server address |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
8 |
-u Url |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
9 |
-f path of XML file |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
10 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
11 |
Optional options: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
12 |
-m Send only mail, without POST connection. Recommend only, |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
13 |
when direct POST connection is not available. |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
14 |
-o mail server. Not needed inside Nokia intranet. |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
15 |
-h help |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
16 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
17 |
Examples: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
18 |
Sending only by mail, without POST. (not recommended) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
19 |
send_xml_to_diamonds.py -s diamonds.nmp.nokia.com -u /diamonds/builds/ -f c:\\build.xml -m buildtoolsautomation@nokia.com |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
20 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
21 |
Sending a new build to release instance of Diamonds |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
22 |
send_xml_to_diamonds.py -s diamonds.nmp.nokia.com -u /diamonds/builds/ -f c:\\build.xml |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
23 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
24 |
Updating test results to existing build |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
25 |
send_xml_to_diamonds.py -s diamonds.nmp.nokia.com -u /diamonds/builds/123/ -f c:\\test.xml |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
26 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
27 |
Sending data for Relative Change in SW Asset metrics |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
28 |
send_xml_to_diamonds.py -s diamonds.nmp.nokia.com -u /diamonds/metrics/ -f c:\\relative.xml |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
29 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
30 |
Sending data for Function Coverage |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
31 |
send_xml_to_diamonds.py -s diamonds.nmp.nokia.com -u /diamonds/tests/coverage/ -f c:\\coverage.xml |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
32 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
33 |
Note: If you want to send XML to development version of Diamonds in testing purposes, use |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
34 |
address: trdeli02.nmp.nokia.com:9001 in the server address: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
35 |
send_xml_to_diamonds.py -s trdeli02.nmp.nokia.com:9001 -u /diamonds/builds/ -f c:\\build.xml |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
36 |
""" |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
37 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
38 |
from httplib import * |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
39 |
import os, sys, time, re |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
40 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
41 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
42 |
def send_email(subject, body, sender, receivers, encoding, mail_server): |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
43 |
""" |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
44 |
Create an email message as MIMEText instance. |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
45 |
""" |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
46 |
from email.Header import Header |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
47 |
from email.MIMEText import MIMEText |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
48 |
from email.Utils import parseaddr, formataddr |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
49 |
import smtplib |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
50 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
51 |
msg = MIMEText(body, "plain", encoding) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
52 |
msg["To"] = Header(u", ".join(receivers), encoding) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
53 |
msg["Subject"] = Header(subject, encoding) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
54 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
55 |
smtp = smtplib.SMTP() |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
56 |
smtp.connect(mail_server) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
57 |
smtp.sendmail(sender, receivers, msg.as_string()) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
58 |
smtp.close() |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
59 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
60 |
def get_username(): |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
61 |
platform = sys.platform |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
62 |
if platform == "win32": |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
63 |
return os.getenv("USERNAME") |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
64 |
else: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
65 |
return os.getlogin() |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
66 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
67 |
def get_mail_subject(sender, server, url): |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
68 |
return "[DIAMONDS_DATA] %s>>>%s>>>%s" % (sender, server, url) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
69 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
70 |
def get_response_message(response): |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
71 |
return "Response status:%s \ |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
72 |
\nResponse reason:%s\n" \ |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
73 |
% (response.status, response.reason) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
74 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
75 |
def get_process_time(total_time): |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
76 |
if total_time<=60: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
77 |
return "%s seconds" % round(total_time, 1) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
78 |
else: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
79 |
return "%s minutes and %s seconds" % (int(total_time/60), round((total_time%60), 1)) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
80 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
81 |
def main(): |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
82 |
start_time = time.time() |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
83 |
server_valid = False |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
84 |
url_valid = False |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
85 |
sfile_valid = False |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
86 |
mail_address = None |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
87 |
mail_server_address = "smtp.nokia.com" |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
88 |
_ = sys.argv.pop(0) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
89 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
90 |
while sys.argv: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
91 |
parameter = sys.argv.pop(0) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
92 |
if re.search('^-', parameter): |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
93 |
if parameter == '-s': |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
94 |
server = sys.argv.pop(0) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
95 |
server_valid = True |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
96 |
elif parameter == '-u': |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
97 |
url = sys.argv.pop(0) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
98 |
url_valid = True |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
99 |
elif parameter == '-f': |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
100 |
source_file = sys.argv.pop(0) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
101 |
sfile_valid = True |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
102 |
try: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
103 |
xml = open(source_file).read() |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
104 |
except: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
105 |
sys.exit("Can not open the file %s" % source_file) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
106 |
elif parameter == '-m': |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
107 |
mail_address = sys.argv.pop(0) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
108 |
elif parameter == '-o': |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
109 |
mail_server_address = sys.argv.pop(0) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
110 |
elif parameter == '-h': |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
111 |
sys.exit("HELP:\n %s" % (command_help)) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
112 |
else: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
113 |
sys.exit("Incorrect parameter! %s" % (parameter) + command_help ) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
114 |
else: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
115 |
sys.exit("Incorrect parameter! %s" % (parameter) + command_help) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
116 |
if not server_valid or not url_valid or not sfile_valid: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
117 |
sys.exit("Too few parameters: Use -h for help") |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
118 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
119 |
diamonds_mail_box = "diamonds@diamonds.nmp.nokia.com" |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
120 |
import_failed_message = "XML was not sent successfully to Diamonds via REST interface!\n" |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
121 |
import_succeed_message = "XML was sent successfully to Diamonds via REST interface.\n" |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
122 |
mail_sent_message = "XML was sent to Diamonds by mail. Scheduled script will try to import it to Diamonds. If you can not see data soon in Diamonds, please contact to Diamonds developers.\n" |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
123 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
124 |
if not mail_address: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
125 |
connection = HTTPConnection(server) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
126 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
127 |
try: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
128 |
connection.request("POST", url, xml) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
129 |
except: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
130 |
print "Can not connect to the server %s\n" % server |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
131 |
sender = get_username() |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
132 |
send_email(get_mail_subject(sender, server, url), xml, sender, [diamonds_mail_box], "latin-1", mail_server_address) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
133 |
sys.exit(mail_sent_message) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
134 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
135 |
response = connection.getresponse() |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
136 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
137 |
# More info about httplib |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
138 |
# http://docs.python.org/lib/module-httplib.html |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
139 |
if response.status == 200: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
140 |
print import_succeed_message |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
141 |
print get_response_message(response) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
142 |
print "Server response:%s\n" % response.read() |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
143 |
else: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
144 |
print import_failed_message |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
145 |
print get_response_message(response) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
146 |
sender = get_username() |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
147 |
send_email(get_mail_subject(sender, server, url), xml, sender, [diamonds_mail_box], "latin-1", mail_server_address) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
148 |
print mail_sent_message |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
149 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
150 |
connection.close() |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
151 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
152 |
else: |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
153 |
print 'Sending only mail' |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
154 |
sender = get_username() |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
155 |
send_email(get_mail_subject(sender, server, url), xml, sender, [mail_address], "latin-1", mail_server_address) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
156 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
157 |
print "------------------------" |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
158 |
print "Processed in %s" % get_process_time(time.time()-start_time) |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
159 |
print "------------------------" |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
160 |
|
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
161 |
if __name__ == "__main__": |
85da6704f82d
Added target to push a collated and calculated BRAG status to diamonds.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
162 |
main() |