-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
148 lines (122 loc) · 4.6 KB
/
server.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import time
import itertools
import os
import sys
from flask import Flask, render_template, redirect, jsonify, request, Response, url_for, abort
from config_monitoring import host, port, title, database
import db
# from scripts import merger
# from scripts.testbranch import downloadSource
if sys.platform == 'win32':
os.system(title)
#subprocess.Popen([sys.executable, 'scripts/db.py'])
app = Flask(__name__)
app.config.from_object('config_monitoring')
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
dtb = db.Database(database)
# svn = merger.Merger()
@app.route("/")
def index():
"""
Парсим результаты с dtb.py
test = dtb.read_urls_test()
Получаем список, вида:
l = [['SmartStation_x86 Windows', '192.168.6.104', '8081', '/tvz-win-trunk', '9581', True, 1],[],...]
где:
l[0][0] - Имя страницы из конфига
l[0][1] - ip вебсервера, на котором запущено тестирование
l[0][2] - порт вебсервера, на котором запущено тестирование
l[0][3] - путь к вебсерверу
l[0][4] - последняя ревизия
l[0][5] - статус сервера 192.168.6.104
l[0][6] - primary key из БД
cams = dtb.read_cam_status()
c = [('192.168.10.10', 0, 0), ('192.168.10.11', 0, 1),...]
c[0][0] = ip камеры
c[0][1] = Статус камеры. True или False
c[0][2] = primary key из БД
res = dtb.read_res_status()
res = [('Redmine', 'redmine.nordavind.ru', True, 0), ...]
res[0][0] = название ресурса
res[0][1] = ip или url
res[0][2] = статус
res[0][3] = primary key из БД
"""
test = dtb.read_test()
build = dtb.read_build()
doc = dtb.read_doc()
merge = dtb.read_merge()
cam = dtb.read_cam()
res = dtb.read_res()
buttons = dtb.read_button()
return render_template('index.html', test=test, build=build, doc=doc, merge=merge, cam=cam, res=res,
buttons=buttons)
@app.route("/merge", methods=['GET'])
def index_merge():
buttons = dtb.read_button()
return render_template('merge_template.html', buttons=buttons)
@app.route('/buttons', methods=['POST'])
def merge():
buttons = [i[0] for i in dtb.read_button()]
input_name = [key for key in dict(request.form).keys()]
input_name = input_name[0]
if input_name in buttons:
# out = svn.mergeGo(input_name)
out = 'svn'
return render_template('merge_result.html', out=out)
else:
return redirect('/')
@app.route('/js')
def getjs():
jsResStatus = {}
for data in dtb.read_res():
jsResStatus[data[0]] = data[2]
jsCamStatus = {}
for data in dtb.read_cam():
#{primary key=status}
jsCamStatus[data[2]] = data[1]
jsMergeStatus = {}
for data in dtb.read_merge():
jsMergeStatus[data[6]] = [data[0], data[1], data[2], data[3], data[4], data[5]]
jsDocStatus = {}
for data in dtb.read_doc():
jsDocStatus[data[6]] = [data[0], data[1], data[2], data[3], data[4], data[5]]
jsBuildStatus = {}
for data in dtb.read_build():
jsBuildStatus[data[6]] = [data[0], data[1], data[2], data[3], data[4], data[5]]
jsTestStatus = {}
for data in dtb.read_test():
jsTestStatus[data[6]] = [data[0], data[1], data[2], data[3], data[4], data[5]]
return jsonify(jsResStatus=jsResStatus,
jsCamStatus=jsCamStatus,
jsMergeStatus=jsMergeStatus,
jsDocStatus=jsDocStatus,
jsBuildStatus=jsBuildStatus,
jsTestStatus=jsTestStatus)
@app.route('/branch')
def branch():
return render_template('branch.html')
@app.route('/jsbranch', methods=['POST'])
def jsbranch():
sourceApp, sourceTesting = request.get_json()
print([sourceApp, sourceTesting])
#downloadSource([sourceApp, sourceTesting])
return redirect('/branch')
@app.route('/mergeout')
def mergeout():
if request.headers.get('accept') == 'text/event-stream':
def events():
for i, c in enumerate(itertools.cycle('\|/-')):
yield "data: %s %d\n\n" % (c, i)
time.sleep(.1) # an artificial delay
return Response(events(), content_type='text/event-stream')
return redirect(url_for('static', filename='mergeout.html'))
# @app.route('/login')
# def login():
# abort(404)
#
# @app.errorhandler(404)
# def page_not_found(error):
# return render_template('branch.html'), 404
if __name__ == '__main__':
app.run(host=host, port=port)