forked from NavInfoNC/nc-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
executable file
·89 lines (64 loc) · 2.64 KB
/
index.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# Build-in modules
import os, re
from bottle import run, static_file, route, template
import urllib
import json
import socket
script_dir = os.path.dirname(os.path.abspath(__file__))
base_url = 'http://mapbar:[email protected]/job/'
# Set timeout
socket.setdefaulttimeout(15)
@route('/rst/<filepath:path>')
def rst(filepath):
return static_file(filepath, root=os.path.join(os.path.dirname(script_dir), 'raspberry', '_build', 'html'))
@route('/js/<filepath:path>')
def resource_js(filepath):
return static_file(filepath, root=os.path.join(script_dir, 'html', 'js'))
@route('/css/<filepath:path>')
def resource_css(filepath):
return static_file(filepath, root=os.path.join(script_dir, 'html', 'css'))
@route('/fonts/<filepath:path>')
def resource_fonts(filepath):
return static_file(filepath, root=os.path.join(script_dir, 'html', 'fonts'))
@route('/')
@route('/index.html')
@route('/index.htm')
@route('/index')
def index():
return template(open(os.path.join(script_dir, 'html', 'index.tpl')).read())
@route('/status/<job_name>')
def page_status(job_name):
try:
url = base_url + job_name + "/api/json?tree=color,lastBuild[timestamp]"
info = json.loads(urllib.urlopen(url).read())
status = info['color']
if status.endswith("_anime"):
status = status[0:-6] + " building"
return '{"status": "%s", "timestamp": %d}' % (status, info['lastBuild']["timestamp"])
except:
return '{"status": "timeout", "timestamp": 0}'
@route('/health/<job_name>')
def page_health(job_name):
result = dict()
try:
url = base_url + job_name + "/lastCompletedBuild/testReport/api/json?depth=1&tree=failCount,passCount,skipCount"
info = json.loads(urllib.urlopen(url).read())
result['failed'] = info['failCount']
result['skipped'] = info['skipCount']
result['total'] = info['failCount'] + info['passCount'] + info['skipCount']
result_list = list()
if info['failCount'] > 0:
url = base_url + job_name + "/lastCompletedBuild/testReport/api/json?depth=1&tree=suites[cases[className,name,status]]"
info = json.loads(urllib.urlopen(url).read())
for cases in info['suites']:
for case in cases['cases']:
if case['status'] == 'FAILED' or case['status'] == 'REGRESSION':
result_list.append('.'.join([case['className'], case['name']]))
result['failedList'] = result_list
except:
pass
return result
if __name__ == '__main__':
run(host='0.0.0.0', port='8009', debug=True)