-
Notifications
You must be signed in to change notification settings - Fork 1
/
cctray_status.py
44 lines (34 loc) · 1.14 KB
/
cctray_status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
import xml.etree.ElementTree as etree
class CCTray:
url = None
max_len = 1
def __init__(self, url, max_len):
self.url = url
self.max_len = max_len
def fetch(self):
response = requests.get(self.url, verify=False)
xml = response.text
tree = etree.fromstring(xml)
status = []
if tree.find('Project') is not None:
status = [
[
project.attrib.get('activity').lower(),
project.attrib.get('lastBuildStatus').lower(),
project.attrib.get('name').count('::')
]
for project in tree.findall('Project')
]
total_count = len(status)
if total_count > self.max_len:
status = [s for s in status if s[2] <= 1]
input = [
'BUILDING' if s[0] == 'building' else
'OK' if s[1] == 'success' else
'ERROR' if s[1] == 'failure' else
'ERROR' if s[1] == 'error'
else 'UNKNOWN'
for s in status
]
return input