From e11606bcafc3519059503ecbc957d700e13b76d7 Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Thu, 18 Oct 2012 15:35:23 +0200 Subject: [PATCH] Implemented support for XML output in the changes module. --- changes.py | 40 +++++++++++++++++++++++++++++++++++++--- gitinspector.py | 2 +- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/changes.py b/changes.py index a1051de..c0f2a73 100644 --- a/changes.py +++ b/changes.py @@ -24,6 +24,7 @@ import re import os import subprocess import terminal +import textwrap class FileDiff: def __init__(self, string): @@ -149,7 +150,12 @@ def get(hard): return __changes__ -def output(hard): +__historical_info_text__ = "The following historical commit information, by author, was found in the repository" + +def output_html(string, hard): + print("HTML output not yet supported.") + +def output_text(hard): authorinfo_list = get(hard).get_authorinfo_list() total_changes = 0.0 @@ -158,8 +164,7 @@ def output(hard): total_changes += authorinfo_list.get(i).deletions if authorinfo_list: - print("The following historical commit information, by author, was found in") - print("the repository:\n") + print(textwrap.fill(__historical_info_text__, width=terminal.get_size()[0])) terminal.printb("Author".ljust(21) + "Commits " + "Insertions " + "Deletions " + "% of changes") for i in sorted(authorinfo_list): @@ -173,3 +178,32 @@ def output(hard): print("{0:.2f}".format(percentage).rjust(14)) else: print("No commited files with the specified extensions were found.") + +def output_xml(string, hard): + authorinfo_list = get(hard).get_authorinfo_list() + total_changes = 0.0 + + for i in authorinfo_list: + total_changes += authorinfo_list.get(i).insertions + total_changes += authorinfo_list.get(i).deletions + + if authorinfo_list: + message_xml = "\t\t" + __historical_info_text__ + "\n" + changes_xml = "" + + for i in sorted(authorinfo_list): + authorinfo = authorinfo_list.get(i) + percentage = 0 if total_changes == 0 else (authorinfo.insertions + authorinfo.deletions) / total_changes * 100 + + name_xml = "\t\t\t\t" + i + "\n" + commits_xml = "\t\t\t\t" + str(authorinfo.commits) + "\n" + insertions_xml = "\t\t\t\t" + str(authorinfo.insertions) + "\n" + deletions_xml = "\t\t\t\t" + str(authorinfo.deletions) + "\n" + percentage_xml = "\t\t\t\t" + "{0:.2f}".format(percentage) + "\n" + + changes_xml += ("\t\t\t\n" + name_xml + commits_xml + insertions_xml + + deletions_xml + percentage_xml + "\t\t\t\n") + + print(string.format("\n\t\n" + message_xml + "\t\t\n" + changes_xml + "\t\t\n\t\n")) + else: + print(string.format("" + "No commited files with the specified extensions were found." + "")) diff --git a/gitinspector.py b/gitinspector.py index 413464a..d80beaa 100755 --- a/gitinspector.py +++ b/gitinspector.py @@ -50,7 +50,7 @@ class Runner: terminal.skip_escapes(not sys.stdout.isatty()) previous_directory = os.getcwd() os.chdir(self.repo) - changes.output(self.hard) + format.call_output_function(changes.output_html, changes.output_text, changes.output_xml, self.hard) if changes.get(self.hard).get_commits(): blame.output(self.hard)