From 0669adc5601bd71f2176854e443d51dc76a6644e Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Tue, 23 Oct 2012 11:25:52 +0200 Subject: [PATCH] Implemented support for XML output in the metrics module. --- gitinspector.py | 2 +- metrics.py | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/gitinspector.py b/gitinspector.py index 31d8fe8..c729904 100755 --- a/gitinspector.py +++ b/gitinspector.py @@ -61,7 +61,7 @@ class Runner: changes.get(self.hard), self.useweeks) if self.include_metrics: - metrics.output() + format.call_output_function(metrics.output_html, metrics.output_text, metrics.output_xml) if self.responsibilities: responsibilities.output(self.hard) diff --git a/metrics.py b/metrics.py index a908ad1..442dd86 100644 --- a/metrics.py +++ b/metrics.py @@ -60,12 +60,34 @@ class Metrics: return eloc_counter -def output(): +__eloc_info_text__ = "The following files are suspiciously big (in order of severity)" +__metrics_missing_info_text__ = "No metrics violations were found in the repository" + +def output_html(): + print("HTML output not yet supported.") + +def output_text(): metrics = Metrics() if not metrics.eloc: - print("\nNo metrics violations were found in the repository.") + print("\n" + __metrics_missing_info_text__ + ".") else: - print("\nThe following files are suspiciously big (in order of severity):") + print("\n" + __eloc_info_text__ + ":") for i in sorted(set([(j, i) for (i, j) in metrics.eloc.items()]), reverse = True): print(i[1] + " (" + str(i[0]) + " eloc)") + +def output_xml(): + metrics = Metrics() + + if not metrics.eloc: + print("\t\n\t\t" + __metrics_missing_info_text__ + "\n\t") + else: + eloc_xml = "" + for i in sorted(set([(j, i) for (i, j) in metrics.eloc.items()]), reverse = True): + eloc_xml += "\t\t\t\t\t\n" + eloc_xml += "\t\t\t\t\t\t" + i[1] + "\n" + eloc_xml += "\t\t\t\t\t\t" + str(i[0]) + "\n" + eloc_xml += "\t\t\t\t\t\n" + + print("\t\t\n\t\t\t\n\t\t\t\t" + __eloc_info_text__ + + "\n\t\t\t\t\n" + eloc_xml + "\t\t\t\t\n\t\t\t\n\t\t")