Commit 2673c2f0 authored by unknown's avatar unknown

code quality

parent 7ec9c514
Pipeline #3309 passed with stage
in 28 seconds
......@@ -19,7 +19,8 @@ class File:
def __init__(self, folder_id, create_directory=True):
self.id = folder_id
self.main_directory_identifier = os.path.join(os.getcwd(), 'uploaded_files', folder_id)
self.main_directory_identifier = os.path.join(
os.getcwd(), 'uploaded_files', folder_id)
if os.path.isdir(self.main_directory_identifier):
self.main_directory = folder_id
......@@ -100,7 +101,8 @@ class File:
try:
for index, folder in enumerate(folders):
file_path = os.path.join(self.main_directory_identifier, folder)
file_path = os.path.join(
self.main_directory_identifier, folder)
files = os.listdir(file_path)
source_files = []
......
......@@ -53,15 +53,18 @@ class Core:
file.process(uploaded_files)
self.__bundled_source = file.export_sources()
except Exception as f_e:
Logger.error.log('Error occurred while parsing file: {}'.format(f_e))
Logger.error.log(
'Error occurred while parsing file: {}'.format(f_e))
self.__choose_tool(form)
try:
self.__tool.parse()
except Exception as p_e:
Logger.error.log('Error occurred while parsing report: {}'.format(p_e))
Logger.error.log(
'Error occurred while parsing report: {}'.format(p_e))
try:
file.save_unified_report(self.__tool.internal_structure.get(clear=True))
file.save_unified_report(
self.__tool.internal_structure.get(clear=True))
except Exception as f_e:
Logger.error.log('Error while creating json file: {}'.format(f_e))
......@@ -79,7 +82,8 @@ class Core:
chosen_tool = GenericParser.get_tool_by_name(tool)
class_to_instantiate = self.__registered_base_classes.get(chosen_tool)
try:
self.__tool = class_to_instantiate(self.__bundled_source.get('report'))
self.__tool = class_to_instantiate(
self.__bundled_source.get('report'))
except TypeError:
raise Exception('Cannot instantiate class')
if self.__tool is None:
......@@ -95,7 +99,8 @@ class Core:
for _, name, _ in iter_modules(['parse']):
import_module('.' + name, 'parse')
except TypeError as t_e:
Logger.error.log(message='Problem occurred while importing classes: {}'.format(t_e), f_exit=True)
Logger.error.log(
message='Problem occurred while importing classes: {}'.format(t_e), f_exit=True)
print(str(t_e))
self.__registered_base_classes = {cls.__name__: cls for cls in GenericParser.__subclasses__() if
......@@ -106,7 +111,8 @@ class Core:
for method in required_methods:
if not hasattr(tool, method) or not callable(getattr(tool, method)):
Logger.error.log(
message='Class {} must implement {} method!'.format(tool.__name__, method),
message='Class {} must implement {} method!'.format(
tool.__name__, method),
f_exit=True,
f_print=True
)
......
......@@ -40,8 +40,10 @@ class Guesser():
chosen_tool = tool
break
except Exception:
raise NameError('Cannot guess tool. Please select parsing tool manually')
raise NameError(
'Cannot guess tool. Please select parsing tool manually')
if chosen_tool.tool is None:
raise NameError('Cannot guess tool. Please select parsing tool manually')
raise NameError(
'Cannot guess tool. Please select parsing tool manually')
return chosen_tool.tool.name
......@@ -19,7 +19,6 @@ if '__main__' == __name__:
FUNCTION = r"function\s'([a-zA-Z]*)'"
a()
# t_LETTER = r'[a-zA-Z]'
# def t_DIGIT(t):
......@@ -28,6 +27,7 @@ if '__main__' == __name__:
# return t
# Error handling rule
def t_error(t):
print('Illegal character {}'.format(t[0]))
t.lexer.skip(1)
......
......@@ -21,6 +21,7 @@ class GenericParser(object):
Decorator for report tools registration
@return:
"""
def wrapper(self):
self.tool = Tool()
f(self)
......@@ -77,7 +78,8 @@ class GenericParser(object):
arr.append('Backtrace' + ('.Backtrace' * i))
for r, i in zip(range(n), arr):
self.set_object_property(rep, i, self.internal_structure.create_new_report())
self.set_object_property(
rep, i, self.internal_structure.create_new_report())
# set first index to emtpy string because in regex loop we need something and this index
# but we dont want to use it
......
......@@ -24,7 +24,6 @@ class HelgrindParser(GenericParser):
file = r'\s\((?P<file>.*:)'
line = r'\((.*:)(?P<lino>[\d]*)'
@GenericParser.register_tool
def register(self):
"""
......@@ -50,17 +49,23 @@ class HelgrindParser(GenericParser):
for report in final_iter:
general = re.search(self.general_info, report)
found_expression = re.finditer(self.concrete_traceback, report)
number_of_matches = len(re.findall(self.concrete_traceback, report))
number_of_matches = len(re.findall(
self.concrete_traceback, report))
new_report, nested_level = self.init_backtrace(self.internal_structure.create_new_report(),
number_of_matches - 1)
message = general.group('message')
thread = general.group('thread')
for match, traceback in zip(found_expression, nested_level):
self.set_object_property(new_report, traceback + '.Meaning', match.group('function'))
self.set_object_property(new_report, traceback + '.File', match.group('file'))
self.set_object_property(new_report, traceback + '.Line', match.group('lino'))
self.set_object_property(new_report, traceback + '.Message', message)
self.set_object_property(new_report, traceback + '.Thread', thread)
self.set_object_property(
new_report, traceback + '.Meaning', match.group('function'))
self.set_object_property(
new_report, traceback + '.File', match.group('file'))
self.set_object_property(
new_report, traceback + '.Line', match.group('lino'))
self.set_object_property(
new_report, traceback + '.Message', message)
self.set_object_property(
new_report, traceback + '.Thread', thread)
self.internal_structure.add_report_to_set(new_report)
......@@ -39,17 +39,23 @@ class JavaParser(GenericParser):
thread = re.search(self.CONTEXT_PATTERN, self.report).group('thread')
found_expressions = list(re.finditer(self.TRACEBACK_PATTERN, self.report))
found_expressions = list(re.finditer(
self.TRACEBACK_PATTERN, self.report))
found_expressions.reverse()
number_of_matches = len(re.findall(self.TRACEBACK_PATTERN, self.report))
number_of_matches = len(re.findall(
self.TRACEBACK_PATTERN, self.report))
new_report, nested_level = self.init_backtrace(self.internal_structure.create_new_report(),
number_of_matches - 1)
for match, backtrace in zip(found_expressions, nested_level):
self.set_object_property(new_report, backtrace + '.File', match.group('file'))
self.set_object_property(new_report, backtrace + '.Meaning', match.group('function'))
self.set_object_property(new_report, backtrace + '.Line', match.group('lino'))
self.set_object_property(new_report, backtrace + '.Message', message)
self.set_object_property(
new_report, backtrace + '.File', match.group('file'))
self.set_object_property(
new_report, backtrace + '.Meaning', match.group('function'))
self.set_object_property(
new_report, backtrace + '.Line', match.group('lino'))
self.set_object_property(
new_report, backtrace + '.Message', message)
self.set_object_property(new_report, backtrace + '.Thread', thread)
self.internal_structure.add_report_to_set(new_report)
......@@ -35,9 +35,13 @@ class PythonParser(GenericParser):
number_of_matches - 1)
for match, backtrace in zip(found_expressions, nested_level):
self.set_object_property(new_report, backtrace + '.File', match.group('file'))
self.set_object_property(new_report, backtrace + '.Line', match.group('line'))
self.set_object_property(new_report, backtrace + '.Meaning', match.group('function'))
self.set_object_property(new_report, backtrace + '.Message', message)
self.set_object_property(
new_report, backtrace + '.File', match.group('file'))
self.set_object_property(
new_report, backtrace + '.Line', match.group('line'))
self.set_object_property(
new_report, backtrace + '.Meaning', match.group('function'))
self.set_object_property(
new_report, backtrace + '.Message', message)
self.internal_structure.add_report_to_set(new_report)
......@@ -100,7 +100,8 @@ class Report:
d = dict()
for attr, val in cls_props:
if isinstance(val, Report):
d[self.GET_PROPERTY.search(attr).group('property')] = self.export_to_dict(val)
d[self.GET_PROPERTY.search(attr).group(
'property')] = self.export_to_dict(val)
else:
d[self.GET_PROPERTY.search(attr).group('property')] = val
......
......@@ -52,6 +52,7 @@ class ReportSet:
Clears report set
@return: empty report set
"""
def clean_set(self):
f(self)
......
......@@ -17,7 +17,7 @@ class Tool:
# class name of tool, which will be instantiated
class_name: str = None
# string regex pattern to guess tool
# string regex pattern to automatically select tool
guess_pattern: str = None
def __init__(self):
......
......@@ -52,16 +52,22 @@ class ValgrindParser(GenericParser):
general_message = self.report.split('\n', 1)[0]
found_expression = list(re.finditer(self.STACK_TRACE_PATTERN, first_trace))
number_of_matches = len(re.findall(self.STACK_TRACE_PATTERN, first_trace))
found_expression = list(re.finditer(
self.STACK_TRACE_PATTERN, first_trace))
number_of_matches = len(re.findall(
self.STACK_TRACE_PATTERN, first_trace))
new_report, nested_level = self.init_backtrace(self.internal_structure.create_new_report(),
number_of_matches - 1)
found_expression.reverse()
for match, traceback in zip(found_expression, nested_level):
self.set_object_property(new_report, traceback + '.Meaning', match.group('function'))
self.set_object_property(new_report, traceback + '.File', match.group('file'))
self.set_object_property(new_report, traceback + '.Line', match.group('lino'))
self.set_object_property(new_report, traceback + '.Message', general_message)
self.set_object_property(
new_report, traceback + '.Meaning', match.group('function'))
self.set_object_property(
new_report, traceback + '.File', match.group('file'))
self.set_object_property(
new_report, traceback + '.Line', match.group('lino'))
self.set_object_property(
new_report, traceback + '.Message', general_message)
self.internal_structure.add_report_to_set(new_report)
......@@ -39,16 +39,20 @@ class RepViewInterface:
base_route = '/api/' + cls.version
cls.__validate_route(base_route)
cls.api.add_resource(File, base_route + '/file/<string:id>/<string:folder>', resource_class_kwargs=cls.kwargs)
cls.api.add_resource(Files, base_route + '/files/<string:id>/<string:folder>', base_route + '/files/<string:id>', base_route + '/files',
base_route + '/files/', resource_class_kwargs=cls.kwargs)
cls.api.add_resource(Tools, base_route + '/tools', resource_class_kwargs=cls.kwargs)
cls.api.add_resource(Report, base_route + '/report/<string:id>/<string:folder>', resource_class_kwargs=cls.kwargs)
cls.api.add_resource(Version, base_route + '/version', endpoint='version', resource_class_kwargs=cls.kwargs)
cls.api.add_resource(
File, base_route + '/file/<string:id>/<string:folder>', resource_class_kwargs=cls.kwargs)
cls.api.add_resource(Files, base_route + '/files/<string:id>/<string:folder>', base_route +
'/files/<string:id>', base_route + '/files', base_route + '/files/',
resource_class_kwargs=cls.kwargs)
cls.api.add_resource(Tools, base_route + '/tools',
resource_class_kwargs=cls.kwargs)
cls.api.add_resource(
Report, base_route + '/report/<string:id>/<string:folder>', resource_class_kwargs=cls.kwargs)
cls.api.add_resource(Version, base_route + '/version',
endpoint='version', resource_class_kwargs=cls.kwargs)
@classmethod
def __validate_route(cls, base)-> None:
def __validate_route(cls, base) -> None:
"""
Base api route validator
@param base: base api url
......
......@@ -34,7 +34,8 @@ class Files(BaseEndpoint):
@return: object containing raw report, uploaded files, parsed report, created directory
"""
try:
self.core.process_request(uploaded_files=request.files, form=request.form)
self.core.process_request(
uploaded_files=request.files, form=request.form)
return_bundle = self.core.export()
except NameError as ne:
response = make_response(json.dumps({
......@@ -60,7 +61,8 @@ class Files(BaseEndpoint):
@param folder: folder identifier (date, when folder were created)
"""
if folder is not None:
folder_to_delete = os.path.join(os.getcwd(), 'uploaded_files', id, folder)
folder_to_delete = os.path.join(
os.getcwd(), 'uploaded_files', id, folder)
if not os.path.isdir(folder_to_delete):
response = make_response(json.dumps({
'message': 'Directory does not exists!',
......@@ -75,10 +77,11 @@ class Files(BaseEndpoint):
folders = os.listdir(folder_to_delete)
for folder in folders:
shutil.rmtree(os.path.join(folder_to_delete, folder), ignore_errors=True)
shutil.rmtree(os.path.join(folder_to_delete, folder),
ignore_errors=True)
@staticmethod
def put( id, folder):
def put(id, folder):
"""
Rename folder name
@param id: string specifying concrete user
......@@ -102,8 +105,10 @@ class Files(BaseEndpoint):
return response
try:
old_folder = os.path.join(os.getcwd(), 'uploaded_files', id, folder)
new_folder = os.path.join(os.getcwd(), 'uploaded_files', id, folder_name)
old_folder = os.path.join(
os.getcwd(), 'uploaded_files', id, folder)
new_folder = os.path.join(
os.getcwd(), 'uploaded_files', id, folder_name)
except:
response = make_response((json.dumps({
'message': 'Renaming folder was not successful!'
......
......@@ -13,6 +13,7 @@ class Report(BaseEndpoint):
"""
Report editing endpoint
"""
def put(self, id=None, folder=None):
"""
Updates report
......
......@@ -66,30 +66,35 @@ class Injector:
def get_gcc(self):
my_module = importlib.import_module('parse.GccParser')
sets = my_module.GccParser.internal_structure.__dict__['_ReportSet__set']
sets = my_module.GccParser.internal_structure.__dict__[
'_ReportSet__set']
sets.clear()
return my_module.GccParser
def get_python(self):
my_module = importlib.import_module('parse.PythonParser')
sets = my_module.PythonParser.internal_structure.__dict__['_ReportSet__set']
sets = my_module.PythonParser.internal_structure.__dict__[
'_ReportSet__set']
sets.clear()
return my_module.PythonParser
def get_helgrind(self):
my_module = importlib.import_module('parse.HelgrindParser')
sets = my_module.HelgrindParser.internal_structure.__dict__['_ReportSet__set']
sets = my_module.HelgrindParser.internal_structure.__dict__[
'_ReportSet__set']
sets.clear()
return my_module.HelgrindParser
def get_java(self):
my_module = importlib.import_module('parse.JavaParser')
sets = my_module.JavaParser.internal_structure.__dict__['_ReportSet__set']
sets = my_module.JavaParser.internal_structure.__dict__[
'_ReportSet__set']
sets.clear()
return my_module.JavaParser
def get_valgrind(self):
my_module = importlib.import_module('parse.ValgrindParser')
sets = my_module.ValgrindParser.internal_structure.__dict__['_ReportSet__set']
sets = my_module.ValgrindParser.internal_structure.__dict__[
'_ReportSet__set']
sets.clear()
return my_module.ValgrindParser
......@@ -232,6 +232,8 @@
/*
* --------------------------------------------------------
* History component
* Main purpose of this component is to hold information about uploaded files
* and allow user to perform specific action
*
* Author: Jakub Dolejsi
* --------------------------------------------------------
......@@ -247,7 +249,7 @@ export default {
data () {
return {
// lsw: new LocalStorageWrapper(),
filesList: [], // this will be in local storage
filesList: [],
fileIndex: 0,
canContinue: true,
selected: {
......@@ -323,6 +325,9 @@ export default {
this.showNotiff('First load folder to editor using LOAD button to show this file', 5000, 'info', 'info', 'black')
}
},
/*
* Validate new folder name
*/
validateFolderName () {
const pattern = '^\\w+$'
const res = this.editData.match(pattern)
......@@ -334,14 +339,23 @@ export default {
this.validateOk = true
return true
},
/*
* Rename folder
*/
rename (folderName) {
this.modal = !this.modal
this.editData = folderName
this.originalFolder = folderName
},
/*
* Create new object
*/
newObj (obj) {
return Object.assign({}, obj)
},
/*
* Remove all uploaded files by concrete user
*/
removeAll () {
if (this.filesList.length === 0) {
this.showNotiff('Nothing to delete', 3000, 'negative', 'warning')
......@@ -363,6 +377,9 @@ export default {
})
// this.lsw.set(this.filesList, local_storage_target, 24);)
},
/*
* Remove concrete folder from user history
*/
removeElement (index) {
const deleted = this.filesList.splice(index, 1)
const deletedFolder = deleted[0].bundle.dir
......@@ -386,15 +403,24 @@ export default {
this.showNotiff(err.message, 3000, 'negative', 'warning')
})
},
/*
* Synchronize history component with backend
*/
syncAndLoad () {
this.synchronizeFromBackend()
// this.$emit('to-editor', this.selected.item)
},
/*
* Load folder content to SouceWrapper component
*/
load (index, item) {
this.select(index)
this.$emit('to-editor', item)
},
/*
* Select concrete folder
*/
select (index, isFileNew = false) {
if (isFileNew) {
this.$nextTick(() => {
......@@ -412,6 +438,9 @@ export default {
})
}
},
/*
* Synchronize content with local storage
*/
synchronizeFromLocalStorage (cached) {
const arr = []
const cachedLength = cached.length
......@@ -424,6 +453,9 @@ export default {
this.fileIndex = cachedLength
this.filesList = arr
},
/*
* Get all uploaded files from backend
*/
synchronizeFromBackend () {
this.$emit('ajax-start')
const id = window.location.pathname.substr(1)
......@@ -471,6 +503,9 @@ export default {
removeBundle () {
},
/*
* Show user notification
*/
showNotiff (text, tm, color, type, textColor = 'white') {
this.$q.notify({
color: color,
......@@ -481,39 +516,66 @@ export default {
textColor: textColor
})
},
/*
* Check if folder is active (loaded in editor)
*/
activeStyleHeader (item) {
return this.selected.index === item ? this.activeStyleHeaderBorder : ''
},
/*
* Check whether to display icon in active folder
*/
activeIcon (item) {
return this.selected.index === item
},
/*
* Save new folder name
*/
closeSave () {
if (!this.validateOk) return
this.saveName()
},
/*
* Add event listener when modal dialog is displayed
*/
onShow () {
this.target = document.getElementById('dragWrapper')
this.nodeDragg = document.getElementById('draggable')
this.nodeDragg.addEventListener('mousedown', this.onGrab)
},
/*
* Remove event listener when modal dialog is closed
*/
onHide () {
document.removeEventListener('mousemove', this.onDrag)
document.removeEventListener('mouseup', this.onLeave)
this.nodeDragg.removeEventListener('mousedown', this.onGrab)
},
/*
* Compute position of modal dialog when it is dragged
*/
onDrag (e) {
const originalStyles = window.getComputedStyle(this.target)
this.target.style.left = parseInt(originalStyles.left) + e.movementX + 'px'
this.target.style.top = parseInt(originalStyles.top) + e.movementY + 'px'
},
/*
* Remove all events listener when modal dialog is closed
*/
onLeave () {
document.removeEventListener('mousemove', this.onDrag)
document.removeEventListener('mouseup', this.onLeave)
},
/*
* Add all event listener when modal dialog is grabbed
*/
onGrab () {
document.addEventListener('mousemove', this.onDrag)
document.addEventListener('mouseup', this.onLeave)
},
/*
* Save new folder name to backend
*/
saveName () {
this.loading = true
const id = window.location.pathname.substr(1)
......
......@@ -184,6 +184,9 @@ export default {
}
},
methods: {
/*
* Load report to modal dialog when user clicks on udpate report
*/
editReport () {
if (this.report === '') {
this.$q.notify({
......@@ -199,16 +202,25 @@ export default {
this.modal = !this.modal
this.editData = this.report
},
/*
* Save updated report
*/
save () {
const updated = this.compare()
if (updated) {
this.saveReport()
}
},
/*
* Close report modal dialog
*/
closeSave () {
this.modal = !this.modal
this.save()
},
/*
* Display notification about report saving
*/
saveNotify (color, message, type) {
this.$q.notify({
color: color,
......@@ -220,6 +232,9 @@ export default {
})
},
/*
* Compare updated report with non-updated report
*/
compare () {
return this.report.localeCompare(this.editData) !== 0
},
......@@ -246,6 +261,9 @@ export default {
document.addEventListener('mousemove', this.onDrag)
document.addEventListener('mouseup', this.onLeave)
},
/*
* Save report to backend service
*/
saveReport () {
const id = window.location.pathname.substr(1)
const folder = this.folder
......
......@@ -108,19 +108,30 @@ export default {
}
},
methods: {
/*
* Switch report tab
*/
switchFile (f) {
this.fileToSwitch = f
},
/*
* Remove all data from SourceCodeWRapper and Report component
*/
destroy () {
// TODO CAUSING ERROR
this.rawReport = ''
// this.uploaded_bundle = {};
this.unified_report = []
this.sourceFile = []
},
/*
* Set empty object to uploaded files
*/
updateBundle () {
this.uploaded_bundle = {}
},
/*
* Load data from Upload component
*/
loadFromUpload (grabbedData) {
this.rawReport = grabbedData.raw_report
this.sourceFile = grabbedData.getSourceFiles()
......@@ -128,6 +139,9 @@ export default {
this.uploaded_bundle = grabbedData
this.folder = grabbedData.dir
},
/*
* Load data from History component
*/
loadFromHistory (data) {
this.unified_report = data.unified_report
this.sourceFile = data.getSourceFiles()
......@@ -135,15 +149,27 @@ export default {