-
Notifications
You must be signed in to change notification settings - Fork 45
Create build logs webapge #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KVGarg
wants to merge
1
commit into
coala:master
Choose a base branch
from
KVGarg:create-build-logs-webapge
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ packages: | |
- gci | ||
- gsoc | ||
- gamification | ||
- log | ||
- ci_build | ||
- meta_review | ||
- model | ||
- unassigned_issues | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import re | ||
import json | ||
import os | ||
import sys | ||
|
||
from django.views.generic import TemplateView | ||
|
||
from community.views import get_header_and_footer | ||
from community.git import ( | ||
get_org_name, | ||
get_owner, | ||
get_deploy_url, | ||
get_upstream_deploy_url | ||
) | ||
|
||
|
||
class BuildLogsView(TemplateView): | ||
template_name = 'build_logs.html' | ||
|
||
def copy_build_logs_json(self, ci_build_jsons): | ||
""" | ||
Copy the build logs detailed JSON file from ./_site directory to | ||
./static and ./public directories | ||
:param ci_build_jsons: A dict of directories path | ||
:return: A boolean, whether the build file is copied | ||
""" | ||
if os.path.isfile(ci_build_jsons['public_path']): | ||
if sys.platform == 'linux': | ||
os.popen('cp {} {}'.format( | ||
ci_build_jsons['site_path'], | ||
ci_build_jsons['public_path'])) | ||
os.popen('cp {} {}'.format( | ||
ci_build_jsons['site_path'], | ||
ci_build_jsons['static_path'])) | ||
else: | ||
os.popen('copy {} {}'.format( | ||
ci_build_jsons['site_path'], | ||
ci_build_jsons['public_path'])) | ||
os.popen('copy {} {}'.format( | ||
ci_build_jsons['site_path'], | ||
ci_build_jsons['static_path'])) | ||
return True | ||
return False | ||
|
||
def create_and_copy_build_logs_json(self, logs, level_specific_logs): | ||
""" | ||
Create a build logs detailed json file in ./_site directory and copy | ||
that file in the ./static and ./public/static directories | ||
:param logs: A list of all lines in build log file | ||
:param level_specific_logs: A dict containing logs divided in their | ||
respective categories | ||
:return: A boolean, whether the files were copied or not | ||
""" | ||
ci_build_jsons = { | ||
'site_path': './_site/ci-build-detailed-logs.json', | ||
'public_path': './public/static/ci-build-detailed-logs.json', | ||
'static_path': './static/ci-build-detailed-logs.json' | ||
} | ||
with open(ci_build_jsons['site_path'], 'w+') as build_logs_file: | ||
data = { | ||
'logs': logs, | ||
'logs_level_Specific': level_specific_logs | ||
} | ||
json.dump(data, build_logs_file, indent=4) | ||
return self.copy_build_logs_json(ci_build_jsons) | ||
|
||
def get_build_logs(self, log_file_path): | ||
KVGarg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
:param log_file_path: build logs file path | ||
:return: a tuple of two where the first element in tuple refers to | ||
a list of build logs in the file, and the second element is a dict | ||
which categorizes the build logs into 5 categories - INFO, DEBUG, | ||
WARNING, ERROR nad CRITICAL | ||
""" | ||
log_lines = [] | ||
log_level_specific_lines = { | ||
'INFO': [], | ||
'DEBUG': [], | ||
'WARNING': [], | ||
'ERROR': [], | ||
'CRITICAL': [] | ||
} | ||
with open(log_file_path) as log_file: | ||
previous_found_level = None | ||
for line in log_file: | ||
log_lines.append(line) | ||
levels = re.findall(r'\[[A-Z]+]', line) | ||
if levels: | ||
level = levels[0] | ||
level = previous_found_level = level[1:-1] | ||
log_level_specific_lines[level].append(line) | ||
elif previous_found_level: | ||
log_level_specific_lines[previous_found_level].append( | ||
line) | ||
return log_lines, log_level_specific_lines | ||
|
||
def check_build_logs_stored(self): | ||
""" | ||
Check whether the build logs json file is copied to _site and public | ||
directories or not | ||
:return: A Boolean | ||
""" | ||
log_file_path = './_site/community.log' | ||
log_file_exists = os.path.isfile(log_file_path) | ||
if log_file_exists: | ||
logs, level_specific_logs = self.get_build_logs(log_file_path) | ||
return self.create_and_copy_build_logs_json(logs, | ||
level_specific_logs) | ||
return False | ||
|
||
def get_build_info(self): | ||
""" | ||
Get the information about build, like who deployed the website i.e. | ||
owner, name of the organization or user etc. | ||
:return: A dict having information about build related details | ||
""" | ||
data = { | ||
'Org name': get_org_name(), | ||
'Owner': get_owner(), | ||
'Deploy URL': get_deploy_url(), | ||
} | ||
try: | ||
data['Upstream deploy URL'] = get_upstream_deploy_url() | ||
except RuntimeError: | ||
data['Upstream deploy URL'] = 'Not found' | ||
return data | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
context = get_header_and_footer(context) | ||
context['build_info'] = self.get_build_info() | ||
context['logs_stored'] = self.check_build_logs_stored() | ||
return context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
.build-info-section section, | ||
.build-logs-section section { | ||
min-width: 300px; | ||
width: 80%; | ||
} | ||
|
||
.build-information, | ||
.build-logs { | ||
background-color: black; | ||
padding-left: 10px; | ||
font-weight: bold; | ||
color: white; | ||
} | ||
|
||
.build-information p { | ||
font-size: 1.5em; | ||
margin: 0; | ||
} | ||
|
||
.build-logs { | ||
max-height: 900px; | ||
overflow: scroll; | ||
overflow-x: hidden; | ||
overflow-y: auto; | ||
} | ||
|
||
.build-logs p { | ||
margin: 0; | ||
} | ||
|
||
.build-logs-section .log-chooser { | ||
width: 25%; | ||
min-width: 150px; | ||
border-radius: 100px; | ||
box-shadow: 0 0 25px 2px black; | ||
color: #454343; | ||
background-color: #c7da99; | ||
padding-left: 10px; | ||
margin: auto 0 auto auto; | ||
} | ||
|
||
.build-logs-section .log-chooser input, | ||
.build-logs-section .log-chooser input:focus:not(.browser-default) { | ||
border-bottom: none; | ||
margin-bottom: 0; | ||
} | ||
|
||
.build-logs-section .small-screen, | ||
.build-logs-section .fa-close { | ||
display: none; | ||
} | ||
|
||
.form-fields { | ||
margin: auto 0 auto auto; | ||
width: 60%; | ||
padding-top: 10px; | ||
} | ||
|
||
.search-field { | ||
width: 60%; | ||
min-width: 180px; | ||
} | ||
|
||
.section-header { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.section-header form { | ||
display: flex; | ||
} | ||
|
||
@media only screen and (max-width: 660px) { | ||
.build-logs-section .search-field { | ||
display: none; | ||
} | ||
.build-logs-section .small-screen { | ||
display: flex; | ||
align-items: center; | ||
margin: auto; | ||
margin-right: 3px; | ||
font-size: 2em; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.