mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-09-27 18:01:30 +02:00
Implemented support for XML output in the changes module.
This commit is contained in:
parent
ed92376d35
commit
e11606bcaf
40
changes.py
40
changes.py
@ -24,6 +24,7 @@ import re
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import terminal
|
import terminal
|
||||||
|
import textwrap
|
||||||
|
|
||||||
class FileDiff:
|
class FileDiff:
|
||||||
def __init__(self, string):
|
def __init__(self, string):
|
||||||
@ -149,7 +150,12 @@ def get(hard):
|
|||||||
|
|
||||||
return __changes__
|
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()
|
authorinfo_list = get(hard).get_authorinfo_list()
|
||||||
total_changes = 0.0
|
total_changes = 0.0
|
||||||
|
|
||||||
@ -158,8 +164,7 @@ def output(hard):
|
|||||||
total_changes += authorinfo_list.get(i).deletions
|
total_changes += authorinfo_list.get(i).deletions
|
||||||
|
|
||||||
if authorinfo_list:
|
if authorinfo_list:
|
||||||
print("The following historical commit information, by author, was found in")
|
print(textwrap.fill(__historical_info_text__, width=terminal.get_size()[0]))
|
||||||
print("the repository:\n")
|
|
||||||
terminal.printb("Author".ljust(21) + "Commits " + "Insertions " + "Deletions " + "% of changes")
|
terminal.printb("Author".ljust(21) + "Commits " + "Insertions " + "Deletions " + "% of changes")
|
||||||
|
|
||||||
for i in sorted(authorinfo_list):
|
for i in sorted(authorinfo_list):
|
||||||
@ -173,3 +178,32 @@ def output(hard):
|
|||||||
print("{0:.2f}".format(percentage).rjust(14))
|
print("{0:.2f}".format(percentage).rjust(14))
|
||||||
else:
|
else:
|
||||||
print("No commited files with the specified extensions were found.")
|
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<message>" + __historical_info_text__ + "</message>\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<name>" + i + "</name>\n"
|
||||||
|
commits_xml = "\t\t\t\t<commits>" + str(authorinfo.commits) + "</commits>\n"
|
||||||
|
insertions_xml = "\t\t\t\t<insertions>" + str(authorinfo.insertions) + "</insertions>\n"
|
||||||
|
deletions_xml = "\t\t\t\t<deletions>" + str(authorinfo.deletions) + "</deletions>\n"
|
||||||
|
percentage_xml = "\t\t\t\t<percentage-of-changes>" + "{0:.2f}".format(percentage) + "</percentage-of-changes>\n"
|
||||||
|
|
||||||
|
changes_xml += ("\t\t\t<author>\n" + name_xml + commits_xml + insertions_xml +
|
||||||
|
deletions_xml + percentage_xml + "\t\t\t</author>\n")
|
||||||
|
|
||||||
|
print(string.format("\n\t<changes>\n" + message_xml + "\t\t<authors>\n" + changes_xml + "\t\t</authors>\n\t</changes>\n"))
|
||||||
|
else:
|
||||||
|
print(string.format("<changes>" + "No commited files with the specified extensions were found." + "</changes>"))
|
||||||
|
@ -50,7 +50,7 @@ class Runner:
|
|||||||
terminal.skip_escapes(not sys.stdout.isatty())
|
terminal.skip_escapes(not sys.stdout.isatty())
|
||||||
previous_directory = os.getcwd()
|
previous_directory = os.getcwd()
|
||||||
os.chdir(self.repo)
|
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():
|
if changes.get(self.hard).get_commits():
|
||||||
blame.output(self.hard)
|
blame.output(self.hard)
|
||||||
|
Loading…
Reference in New Issue
Block a user