-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevelop_status.py
71 lines (59 loc) · 1.88 KB
/
develop_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
"""
Display Develop status
@author fabien
"""
import json, base64
from time import time
try:
# python 3
import urllib2
from urllib.error import URLError
from urllib.request import urlopen
except ImportError:
# python 2
import urllib2
from urllib2 import URLError
from urllib2 import urlopen
class Py3status:
cache_timeout = 25
jenkins_endpoint = ""
jenkins_username = ""
jenkins_token = ""
def develop_status(self, i3s_output_list, i3s_config):
response = {
'cached_until': time() + self.cache_timeout
}
url = self.jenkins_endpoint + "/view/TV/api/json"
request = urllib2.Request(url)
authinfo = base64.encodestring("%s:%s" % (self.jenkins_username, self.jenkins_token)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % authinfo)
try:
data = json.loads(urlopen(request).read().decode())
except URLError:
response['color'] = i3s_config['color_bad']
response['full_text'] = 'Error occurred'
return response
job_to_ignore = ["23.install-snapshot-to-last"]
fail_colors = ["red", "red_anime", "yellow", "yellow_anime"]
failed_jobs = [job for job in data["jobs"] if (job["name"] not in job_to_ignore and job["color"] in fail_colors)]
response['full_text'] = "Develop"
print failed_jobs
if not failed_jobs:
response['color'] = i3s_config['color_good']
else:
response['color'] = i3s_config['color_bad']
return response
if __name__ == "__main__":
"""
Test this module by calling it directly.
"""
from time import sleep
x = Py3status()
config = {
'color_good': '#00FF00',
'color_bad': '#FF0000',
}
while True:
print(x.develop_status([], config))
sleep(1)