diff --git a/gitinspector/gitinspector.py b/gitinspector/gitinspector.py index e9ad743..ad4aff3 100644 --- a/gitinspector/gitinspector.py +++ b/gitinspector/gitinspector.py @@ -26,6 +26,7 @@ import sys from .blame import Blame from .changes import Changes from .config import GitConfig +from .metrics import MetricsLogic from . import (basedir, clone, extensions, filtering, format, help, interval, localization, optval, terminal, version) from .output import outputable @@ -59,8 +60,10 @@ class Runner(object): terminal.skip_escapes(not sys.stdout.isatty()) terminal.set_stdout_encoding() previous_directory = os.getcwd() + summed_blames = None summed_changes = None + summed_metrics = None for repo in repos: os.chdir(previous_directory) @@ -70,6 +73,9 @@ class Runner(object): summed_blames = Blame(self.hard, self.useweeks, changes) + summed_blames summed_changes = changes + summed_changes + if self.include_metrics: + summed_metrics = MetricsLogic() + summed_metrics + if sys.stdout.isatty() and format.is_interactive_format(): terminal.clear_row() @@ -85,7 +91,7 @@ class Runner(object): outputable.output(TimelineOutput(summed_changes, self.useweeks)) if self.include_metrics: - outputable.output(MetricsOutput()) + outputable.output(MetricsOutput(summed_metrics)) if self.responsibilities: outputable.output(ResponsibilitiesOutput(summed_changes, summed_blames)) diff --git a/gitinspector/metrics.py b/gitinspector/metrics.py index 8a35084..d683e28 100644 --- a/gitinspector/metrics.py +++ b/gitinspector/metrics.py @@ -69,6 +69,15 @@ class MetricsLogic(object): if lines > 0 and METRIC_CYCLOMATIC_COMPLEXITY_DENSITY_THRESHOLD < cycc / float(lines): self.cyclomatic_complexity_density[i.strip()] = cycc / float(lines) + def __add__(self, other): + if other == None: + return self + + self.eloc.update(other.eloc) + self.cyclomatic_complexity.update(other.cyclomatic_complexity) + self.cyclomatic_complexity_density.update(other.cyclomatic_complexity_density) + return self + @staticmethod def get_cyclomatic_complexity(file_r, extension): is_inside_comment = False diff --git a/gitinspector/output/metricsoutput.py b/gitinspector/output/metricsoutput.py index 3f69348..af6b7ac 100644 --- a/gitinspector/output/metricsoutput.py +++ b/gitinspector/output/metricsoutput.py @@ -21,7 +21,7 @@ from __future__ import print_function from __future__ import unicode_literals from ..changes import FileDiff from ..localization import N_ -from .. import metrics +from ..metrics import (__metric_eloc__, METRIC_CYCLOMATIC_COMPLEXITY_THRESHOLD, METRIC_CYCLOMATIC_COMPLEXITY_DENSITY_THRESHOLD) from .outputable import Outputable ELOC_INFO_TEXT = N_("The following files are suspiciously big (in order of severity)") @@ -38,54 +38,55 @@ def __get_metrics_score__(ceiling, value): return i[1] class MetricsOutput(Outputable): - def output_text(self): - metrics_logic = metrics.MetricsLogic() + def __init__(self, metrics): + self.metrics = metrics + Outputable.__init__(self) - if not metrics_logic.eloc and not metrics_logic.cyclomatic_complexity and not metrics_logic.cyclomatic_complexity_density: + def output_text(self): + if not self.metrics.eloc and not self.metrics.cyclomatic_complexity and not self.metrics.cyclomatic_complexity_density: print("\n" + _(METRICS_MISSING_INFO_TEXT) + ".") - if metrics_logic.eloc: + if self.metrics.eloc: print("\n" + _(ELOC_INFO_TEXT) + ":") - for i in sorted(set([(j, i) for (i, j) in metrics_logic.eloc.items()]), reverse=True): + for i in sorted(set([(j, i) for (i, j) in self.metrics.eloc.items()]), reverse=True): print(_("{0} ({1} estimated lines of code)").format(i[1], str(i[0]))) - if metrics_logic.cyclomatic_complexity: + if self.metrics.cyclomatic_complexity: print("\n" + _(CYCLOMATIC_COMPLEXITY_TEXT) + ":") - for i in sorted(set([(j, i) for (i, j) in metrics_logic.cyclomatic_complexity.items()]), reverse=True): + for i in sorted(set([(j, i) for (i, j) in self.metrics.cyclomatic_complexity.items()]), reverse=True): print(_("{0} ({1} in cyclomatic complexity)").format(i[1], str(i[0]))) - if metrics_logic.cyclomatic_complexity_density: + if self.metrics.cyclomatic_complexity_density: print("\n" + _(CYCLOMATIC_COMPLEXITY_DENSITY_TEXT) + ":") - for i in sorted(set([(j, i) for (i, j) in metrics_logic.cyclomatic_complexity_density.items()]), reverse=True): + for i in sorted(set([(j, i) for (i, j) in self.metrics.cyclomatic_complexity_density.items()]), reverse=True): print(_("{0} ({1:.3f} in cyclomatic complexity density)").format(i[1], i[0])) def output_html(self): - metrics_logic = metrics.MetricsLogic() metrics_xml = "
" + _(METRICS_MISSING_INFO_TEXT) + ".
" - if metrics_logic.eloc: + if self.metrics.eloc: metrics_xml += "