Skip to content

Commit 86f18b7

Browse files
committed
ci_build/: Re-design build-logs webpage
The newly created webpage combines the previous two webpages- info.txt and log/index.html. This web-page combines the results of both the pages and shows them in a better UI/UX with additional features of filtering and searching within the existing logs. The logs are fetched from a JSON file which is created from the logs stored in the log file _site/community.log Closes #256
1 parent 3f2acbd commit 86f18b7

File tree

11 files changed

+376
-51
lines changed

11 files changed

+376
-51
lines changed

.moban.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ packages:
99
- gci
1010
- gsoc
1111
- gamification
12-
- log
12+
- ci_build
1313
- meta_review
1414
- model
1515
- twitter

.nocover.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ nocover_file_globs:
88
- community/git.py
99
- gci/*.py
1010
- gsoc/*.py
11-
- log/*.py
11+
- ci_build/*.py
1212
- meta_review/handler.py
1313
- model/*.py
1414
- openhub/*.py

ci_build/view_log.py

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import re
2+
import json
3+
import os
4+
import sys
5+
6+
from django.views.generic import TemplateView
7+
8+
from community.views import get_header_and_footer
9+
from community.git import (
10+
get_org_name,
11+
get_owner,
12+
get_deploy_url,
13+
get_upstream_deploy_url
14+
)
15+
16+
17+
class BuildLogsView(TemplateView):
18+
template_name = 'build_logs.html'
19+
20+
def get_build_info(self):
21+
data = {
22+
'Org name': get_org_name(),
23+
'Owner': get_owner(),
24+
'Deploy URL': get_deploy_url(),
25+
}
26+
try:
27+
upstream_deploy_url = get_upstream_deploy_url()
28+
data['Upstream deploy URL'] = upstream_deploy_url
29+
except RuntimeError:
30+
data['Upstream deploy URL'] = 'Not found'
31+
return data
32+
33+
def get_build_logs(self, log_file_path):
34+
log_lines = []
35+
log_level_specific_lines = {
36+
'INFO': [],
37+
'DEBUG': [],
38+
'WARNING': [],
39+
'ERROR': [],
40+
'CRITICAL': []
41+
}
42+
with open(log_file_path) as log_file:
43+
previous_found_level = None
44+
for line in log_file:
45+
log_lines.append(line)
46+
levels = re.findall(r'\[[A-Z]+]', line)
47+
if levels:
48+
level = levels[0]
49+
level = previous_found_level = level[1:-1]
50+
log_level_specific_lines[level].append(line)
51+
elif previous_found_level:
52+
log_level_specific_lines[previous_found_level].append(
53+
line)
54+
return log_lines, log_level_specific_lines
55+
56+
def create_and_copy_build_logs_json(self, logs, level_specific_logs):
57+
ci_build_jsons = {
58+
'site_path': './_site/ci-build-detailed-logs.json',
59+
'public_path': './public/static/ci-build-detailed-logs.json',
60+
'static_path': './static/ci-build-detailed-logs.json'
61+
}
62+
with open(ci_build_jsons['site_path'], 'w+') as build_logs_file:
63+
data = {
64+
'logs': logs,
65+
'logs_level_Specific': level_specific_logs
66+
}
67+
json.dump(data, build_logs_file, indent=4)
68+
return self.copy_build_logs_json(ci_build_jsons)
69+
70+
def copy_build_logs_json(self, ci_build_jsons):
71+
if os.path.isfile(ci_build_jsons['public_path']):
72+
if sys.platform == 'linux':
73+
os.popen('cp {} {}'.format(
74+
ci_build_jsons['site_path'],
75+
ci_build_jsons['public_path']))
76+
os.popen('cp {} {}'.format(
77+
ci_build_jsons['site_path'],
78+
ci_build_jsons['static_path']))
79+
else:
80+
os.popen('copy {} {}'.format(
81+
ci_build_jsons['site_path'],
82+
ci_build_jsons['public_path']))
83+
os.popen('copy {} {}'.format(
84+
ci_build_jsons['site_path'],
85+
ci_build_jsons['static_path']))
86+
return True
87+
return False
88+
89+
def check_build_logs_stored(self):
90+
log_file_path = './_site/community.log'
91+
log_file_exists = os.path.isfile(log_file_path)
92+
if log_file_exists:
93+
logs, level_specific_logs = self.get_build_logs(log_file_path)
94+
return self.create_and_copy_build_logs_json(logs,
95+
level_specific_logs)
96+
return False
97+
98+
def get_context_data(self, **kwargs):
99+
context = super().get_context_data(**kwargs)
100+
context = get_header_and_footer(context)
101+
context['build_info'] = self.get_build_info()
102+
context['logs_stored'] = self.check_build_logs_stored()
103+
return context

community/urls.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from django.conf.urls.static import static
77
from django.conf import settings
88

9-
from community.views import HomePageView, info
9+
from community.views import HomePageView
1010
from gci.views import index as gci_index
1111
from gci.feeds import LatestTasksFeed as gci_tasks_rss
1212
from twitter.view_twitter import index as twitter_index
13-
from log.view_log import index as log_index
13+
from ci_build.view_log import BuildLogsView
1414
from data.views import index as contributors_index
1515
from gamification.views import index as gamification_index
1616
from meta_review.views import index as meta_review_index
@@ -79,12 +79,6 @@ def get_organization():
7979
distill_func=get_index,
8080
distill_file='index.html',
8181
),
82-
distill_url(
83-
'info.txt', info,
84-
name='index',
85-
distill_func=get_index,
86-
distill_file='info.txt',
87-
),
8882
distill_url(
8983
r'gci/tasks/rss.xml', gci_tasks_rss(),
9084
name='gci-tasks-rss',
@@ -104,10 +98,10 @@ def get_organization():
10498
distill_file='twitter/index.html',
10599
),
106100
distill_url(
107-
r'log/', log_index,
108-
name='log',
101+
r'CI/Build/', BuildLogsView.as_view(),
102+
name='ci_build',
109103
distill_func=get_index,
110-
distill_file='log/index.html',
104+
distill_file='CI/Build/index.html',
111105
),
112106
distill_url(
113107
r'contributors/$', contributors_index,

community/views.py

-21
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44

55
from trav import Travis
66

7-
from django.http import HttpResponse
87
from django.views.generic.base import TemplateView
98

109
from .git import (
11-
get_deploy_url,
1210
get_org_name,
13-
get_owner,
14-
get_upstream_deploy_url,
1511
get_remote_url
1612
)
1713
from data.models import Team
@@ -111,20 +107,3 @@ def get_context_data(self, **kwargs):
111107
context['top_gamification_users'] = self.get_top_gamification_users(
112108
count=5)
113109
return context
114-
115-
116-
def info(request):
117-
data = {
118-
'Org name': get_org_name(),
119-
'Owner': get_owner(),
120-
'Deploy URL': get_deploy_url(),
121-
}
122-
try:
123-
upstream_deploy_url = get_upstream_deploy_url()
124-
data['Upstream deploy URL'] = upstream_deploy_url
125-
except RuntimeError:
126-
data['Upstream deploy URL'] = 'Not found'
127-
128-
s = '\n'.join(name + ': ' + value
129-
for name, value in data.items())
130-
return HttpResponse(s)

log/view_log.py

-12
This file was deleted.

setup.cfg

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ testpaths =
1414
gci
1515
gsoc
1616
gamification
17-
log
17+
ci_build
1818
meta_review
1919
model
2020
twitter
@@ -70,7 +70,7 @@ source =
7070
gci
7171
gsoc
7272
gamification
73-
log
73+
ci_build
7474
meta_review
7575
model
7676
twitter
@@ -82,7 +82,7 @@ omit =
8282
community/git.py
8383
gci/*.py
8484
gsoc/*.py
85-
log/*.py
85+
ci_build/*.py
8686
meta_review/handler.py
8787
model/*.py
8888
openhub/*.py

static/css/build_logs.css

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
.build-info-section section,
2+
.build-logs-section section {
3+
min-width: 300px;
4+
width: 80%;
5+
}
6+
7+
.build-information,
8+
.build-logs {
9+
background-color: black;
10+
padding-left: 10px;
11+
font-weight: bold;
12+
color: white;
13+
}
14+
15+
.build-information p {
16+
font-size: 1.5em;
17+
margin: 0;
18+
}
19+
20+
.build-logs {
21+
max-height: 900px;
22+
overflow: scroll;
23+
overflow-x: hidden;
24+
overflow-y: auto;
25+
}
26+
27+
.build-logs p {
28+
margin: 0;
29+
}
30+
31+
.build-logs-section .log-chooser {
32+
width: 25%;
33+
min-width: 150px;
34+
border-radius: 100px;
35+
box-shadow: 0px 0px 25px 2px black;
36+
color: #454343;
37+
background-color: #c7da99;
38+
padding-left: 10px;
39+
margin: auto;
40+
margin-right: 0;
41+
}
42+
43+
.build-logs-section .log-chooser input,
44+
.build-logs-section .log-chooser input:focus:not(.browser-default) {
45+
border-bottom: none;
46+
margin-bottom: 0;
47+
}
48+
49+
.build-logs-section .small-screen,
50+
.build-logs-section .fa-close {
51+
display: none;
52+
}
53+
54+
.form-fields {
55+
margin: auto;
56+
margin-right: 0;
57+
width: 60%;
58+
padding-top: 10px;
59+
}
60+
61+
.search-field {
62+
width: 60%;
63+
min-width: 180px;
64+
}
65+
66+
.section-header {
67+
display: flex;
68+
align-items: center;
69+
}
70+
71+
.section-header form {
72+
display: flex;
73+
}
74+
75+
@media only screen and (max-width: 660px) {
76+
.build-logs-section .search-field {
77+
display: none;
78+
}
79+
.build-logs-section .small-screen {
80+
display: flex;
81+
align-items: center;
82+
margin: auto;
83+
margin-right: 3px;
84+
font-size: 2em;
85+
}
86+
}

0 commit comments

Comments
 (0)