mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-11-13 07:11:08 +01:00
Added a metrics module together with a new -m option.
The metrics module currently only includes a very simple ELOC (estimated lines of code) metric, but will be expanded eventually with some other metrics.
This commit is contained in:
parent
82700b38c2
commit
134d8d43a1
3 changed files with 85 additions and 5 deletions
|
@ -23,6 +23,7 @@ import changes
|
|||
import extensions
|
||||
import getopt
|
||||
import help
|
||||
import metrics
|
||||
import missing
|
||||
import sys
|
||||
import terminal
|
||||
|
@ -32,6 +33,7 @@ import version
|
|||
class Runner:
|
||||
def __init__(self):
|
||||
self.hard = False
|
||||
self.include_metrics = False
|
||||
self.list_file_types = False
|
||||
self.repo = "."
|
||||
self.tda367 = False
|
||||
|
@ -45,12 +47,15 @@ class Runner:
|
|||
if changes.get(self.repo, self.hard).get_commits():
|
||||
blame.output(self.repo, self.hard)
|
||||
|
||||
if self.timeline == True:
|
||||
if self.timeline:
|
||||
timeline.output(changes.get(self.repo, self.hard), self.useweeks)
|
||||
|
||||
if self.include_metrics:
|
||||
metrics.output(self.repo, self.hard)
|
||||
|
||||
missing.output()
|
||||
|
||||
if self.list_file_types == True:
|
||||
if self.list_file_types:
|
||||
ex = extensions.get_located()
|
||||
if (ex):
|
||||
print "\nThe extensions below were found in the repository history:"
|
||||
|
@ -61,8 +66,9 @@ if __name__ == "__main__":
|
|||
__run__ = Runner()
|
||||
|
||||
try:
|
||||
__opts__, __args__ = getopt.gnu_getopt(sys.argv[1:], "cf:hHlTw", ["checkout-missing", "file-types=", "hard",
|
||||
"help", "list-file-types", "tda367", "timeline", "version"])
|
||||
__opts__, __args__ = getopt.gnu_getopt(sys.argv[1:], "cf:hHlmTw", ["checkout-missing", "file-types=", "hard",
|
||||
"help", "list-file-types", "metrics","tda367", "timeline",
|
||||
"version"])
|
||||
except getopt.error, msg:
|
||||
print sys.argv[0], "\b:", msg
|
||||
print "Try `", sys.argv[0], "--help' for more information."
|
||||
|
@ -79,10 +85,13 @@ if __name__ == "__main__":
|
|||
__run__.hard = True
|
||||
elif o in("-l", "--list-file-types"):
|
||||
__run__.list_file_types = True
|
||||
elif o in("-m", "--metrics"):
|
||||
__run__.include_metrics = True
|
||||
elif o in("--version"):
|
||||
version.output()
|
||||
sys.exit(0)
|
||||
elif o in("--tda367"):
|
||||
__run__.include_metrics = True
|
||||
__run__.list_file_types = True
|
||||
__run__.tda367 = True
|
||||
__run__.timeline = True
|
||||
|
|
4
help.py
4
help.py
|
@ -31,10 +31,12 @@ Mandatory arguments to long options are mandatory for short options too.
|
|||
-H, --hard look harder for duplicates of rows and files
|
||||
-l, --list-file-types list all the file extensions available in the
|
||||
current branch of the repository
|
||||
-m --metrics include checks for certain metrics during the
|
||||
analysis of commits.
|
||||
-T, --timeline show commit timeline, including author names
|
||||
--tda367 show statistics and information in a way that
|
||||
is formatted for the course TDA367/DIT211
|
||||
this is currently the same as -lTw, but
|
||||
this is currently the same as -lmTw, but
|
||||
will later include some additional searches
|
||||
for things such as documentation (RAD/SDD)
|
||||
-w show all statistical information in weeks
|
||||
|
|
69
metrics.py
Normal file
69
metrics.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
# coding: utf-8
|
||||
#
|
||||
# Copyright © 2012 Ejwa Software. All rights reserved.
|
||||
#
|
||||
# This file is part of gitinspector.
|
||||
#
|
||||
# gitinspector is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# gitinspector is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from changes import FileDiff
|
||||
import comment
|
||||
import missing
|
||||
import os
|
||||
import system
|
||||
|
||||
__metric_eloc__ = {"java": 500, "c": 500, "cpp": 500, "h": 300, "hpp": 300, "py": 500, "glsl": 1000,
|
||||
"rb": 500, "js": 500, "sql": 1000, "xml": 1000}
|
||||
|
||||
class Metrics:
|
||||
def __init__(self, repo, hard):
|
||||
self.eloc = {}
|
||||
ls_tree_r = system.run(repo, "git ls-tree --name-only -r HEAD")
|
||||
|
||||
for i in ls_tree_r.readlines():
|
||||
if FileDiff.is_valid_extension(i):
|
||||
if not missing.add(repo, i.strip()):
|
||||
file_r = system.open_file(repo, i.strip())
|
||||
extension = FileDiff.get_extension(i)
|
||||
lines = Metrics.get_eloc(file_r, extension)
|
||||
|
||||
if __metric_eloc__[extension] < lines:
|
||||
self.eloc[i.strip()] = lines
|
||||
|
||||
@staticmethod
|
||||
def get_eloc(file_r, extension):
|
||||
is_inside_comment = False
|
||||
eloc_counter = 0
|
||||
|
||||
for j in file_r.readlines():
|
||||
if comment.is_comment_begining(extension, j):
|
||||
is_inside_comment = True
|
||||
|
||||
if not comment.is_comment(extension, j) and not is_inside_comment:
|
||||
eloc_counter += 1
|
||||
|
||||
if comment.is_comment_end(extension, j):
|
||||
is_inside_comment = False
|
||||
|
||||
return eloc_counter
|
||||
|
||||
def output(repo, hard):
|
||||
metrics = Metrics(repo, hard)
|
||||
|
||||
if not metrics.eloc:
|
||||
print "\nNo metrics violations were found the repository."
|
||||
else:
|
||||
print "\nThe following files are suspiciously big (in order of severity):"
|
||||
for i in sorted(set([(j, i) for (i, j) in metrics.eloc.items()]), reverse = True):
|
||||
print i[1] + " (" + str(i[0]) + " eloc)"
|
Loading…
Reference in a new issue