-
Notifications
You must be signed in to change notification settings - Fork 0
/
Analysis.py
100 lines (73 loc) · 3.05 KB
/
Analysis.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
from Helpers import CommandLine, File
import lizard
import radon
import re
class Sonar:
def __init__(self):
pass
@staticmethod
def sonar_analysis(repo_dir, version):
CommandLine.execute_cmd_print(
"cd " + repo_dir + "; sonar-scanner -Dsonar.sources=. -Dsonar.projectKey=" + repo_dir +
" -Dsonar.projectVersion=" + str(version))
@staticmethod
def purge_repo_analysis(project):
pass
class Lizard:
def __init__(self):
pass
@staticmethod
def get_cyclomatic_complexity(repo):
results = lizard.analyze("./" + repo, None, 2)
print(results.__dict__)
class Radon:
def __init__(self):
pass
@staticmethod
def analyse_code(repo):
result = CommandLine.execute_cmd_get_result("cd " + repo + "; radon cc *").decode(
"utf-8").split("\n")
return result[len(result) - 1]
@staticmethod
def get_cyclomatic_complexity(repo, commit, iteration, max_iteration):
results = CommandLine.execute_cmd_get_result("cd " + repo + "; radon cc * -s -j").decode("utf-8").split("\n")
metrics = list()
metrics.append(File.get_commit_details(repo, commit, iteration, max_iteration))
metrics.append(File.get_json_from_cmd(results))
return metrics
@staticmethod
def get_file_cyclomatic_complexity(file):
results = CommandLine.execute_cmd_get_result("radon cc -s -j ./" + file).decode("utf-8").split("\n")
metrics = list()
metrics.append(File.get_json_from_cmd(results))
return metrics
@staticmethod
def get_raw_metrics(repo, commit, index, max_iteration):
results = CommandLine.execute_cmd_get_result("cd " + repo + "; radon raw * -j").decode("utf-8").split("\n")
metrics = list()
metrics.append(File.get_commit_details(repo, commit, index, max_iteration))
metrics.append(File.get_json_from_cmd(results))
return metrics
@staticmethod
def get_maintainability_index(repo, commit, index, max_iterations):
results = CommandLine.execute_cmd_get_result("cd " + repo + "; radon mi * -j").decode("utf-8").split("\n")
metrics = list()
metrics.append(File.get_commit_details(repo, commit, index, max_iterations))
metrics.append(File.get_json_from_cmd(results))
return metrics
@staticmethod
def get_file_maintainability_index(file):
results = CommandLine.execute_cmd_get_result("radon mi -j " + file).decode("utf-8").split("\n")
metrics = list()
metrics.append(File.get_json_from_cmd(results))
return metrics
@staticmethod
def get_average_complexity(repo, commit):
results = CommandLine.execute_cmd_get_result("cd " + repo + "; radon cc * --total-average").decode(
"utf-8").split("\n")
complexity = results[len(results) - 1]
complexity = re.search("\d+\.?\d*", complexity).group(0)
metrics = list()
metrics.append({"commit_head": commit[1]})
metrics[0]["avg_complexity"] = complexity
return metrics