-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
109 lines (94 loc) · 3.4 KB
/
app.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
# -*- coding: utf-8 -*-
import re
from optparse import OptionParser
from flask import Flask, request
from flask import render_template
from models.repo_chart import RepoChart
from models.misc.repo_backup import RepoBackup
repo_backup = RepoBackup()
app = Flask(__name__, template_folder='templates', static_folder='static')
app.jinja_env.variable_start_string = '{['
app.jinja_env.variable_end_string = ']}'
print('Waiting...')
@app.route('/repochart', methods=["GET", "POST"])
def index():
repo_name = request.args.get('repo')
if repo_name:
return render_template(
'index.html',
repo=repo_name,
)
else:
return render_template(
'index.html',
repo='Uahh/RepoChart'
)
@app.route('/repochart/start', methods=["GET", "POST"])
def start():
repo_name = request.args.get('repo')
if repo_name == 'undefined':
repo_name = 'Uahh/RepoChart'
if not re.match(".+/.+", repo_name):
return 'Without'
repo_status = repo_backup.check_repo(repo_name)
if repo_status == False:
repo_name_split = repo_name.split('/')
# if repo_name not in repo_backup.repo_list:
repo_backup.add_repo(repo_name)
repo = RepoChart(repo_name_split[0], repo_name_split[1], server=True)
if repo == 'Network failed':
repo_backup.del_repo(repo_name)
return 'Network failed'
if repo.chart_status == False:
repo.output()
if repo.existence_flag == False:
repo_backup.add_repo(repo_name, type='Without')
return 'Without'
elif repo.large_flag == True:
repo_backup.add_repo(repo_name, type='Large')
return 'Large'
elif repo.star_flag == True:
repo_backup.add_repo(repo_name, type='Normal')
return 'Star'
repo_backup.add_repo(repo_name, type='Normal')
return 'OK'
elif repo_status == 'Without':
return 'Without'
elif repo_status == 'Large':
return 'Large'
else:
if not RepoChart.check_output('', repo_name):
return 'Started'
return 'OK'
@app.route('/repochart/check', methods=["POST"])
def check():
repo_name = request.form.get('repo')
if not re.match(".+/.+", repo_name):
return 'Without'
status = RepoChart.check_output('', repo_name)
if status == True:
return {'status': 'True'}
return {'status': 'False'}
@app.route('/repochart/chartdata', methods=["POST"])
def chart_data():
type = request.form.get('type')
repo_name = request.form.get('repo')
if type == 'circle':
return RepoChart.open_all_charts('', 'circle', repo_name)
elif type == 'square':
return RepoChart.open_all_charts('', 'square', repo_name)
elif type == 'commit_pie':
return RepoChart.open_all_charts('', 'commit_pie', repo_name)
elif type == 'commit_line':
return RepoChart.open_all_charts('', 'commit_line', repo_name)
elif type == 'active_line':
return RepoChart.open_all_charts('', 'active_line', repo_name)
elif type == 'star_line':
return RepoChart.open_all_charts('', 'star_line', repo_name)
elif type == 'code_of_lines':
return RepoChart.open_all_charts('', 'code_of_lines', repo_name)
return 'error'
@app.route('/repochart/error')
def error():
return '404 not found'
app.run(host='0.0.0.0', debug=False, port=52173) # 52inami