mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-11-16 00:28:25 +01:00
Implemented support for XML output in the timeline module.
This commit is contained in:
parent
4170c00c03
commit
a72a29212a
2 changed files with 42 additions and 5 deletions
|
@ -57,7 +57,8 @@ class Runner:
|
|||
format.call_output_function(blame.output_html, blame.output_text, blame.output_xml, self.hard)
|
||||
|
||||
if self.timeline:
|
||||
timeline.output(changes.get(self.hard), self.useweeks)
|
||||
format.call_output_function(timeline.output_html, timeline.output_text, timeline.output_xml,
|
||||
changes.get(self.hard), self.useweeks)
|
||||
|
||||
if self.include_metrics:
|
||||
metrics.output()
|
||||
|
|
44
timeline.py
44
timeline.py
|
@ -20,6 +20,7 @@
|
|||
from __future__ import print_function
|
||||
import datetime
|
||||
import terminal
|
||||
import textwrap
|
||||
|
||||
class TimelineData:
|
||||
def __init__(self, changes, useweeks):
|
||||
|
@ -90,7 +91,12 @@ class TimelineData:
|
|||
def is_author_in_period(self, period, author):
|
||||
return self.entries.get((author, period), None) != None
|
||||
|
||||
def __output_row__(timeline_data, periods, names):
|
||||
__timeline_info_text__ = "The following history timeline has been gathered from the repository"
|
||||
|
||||
def output_html(changes, useweeks):
|
||||
print("HTML output not yet supported.")
|
||||
|
||||
def __output_row__text__(timeline_data, periods, names):
|
||||
print("\n" + terminal.__bold__ + "Author".ljust(20), end=" ")
|
||||
|
||||
for period in periods:
|
||||
|
@ -108,9 +114,9 @@ def __output_row__(timeline_data, periods, names):
|
|||
len(signs_str) == 0 else signs_str).rjust(10), end=" ")
|
||||
print("")
|
||||
|
||||
def output(changes, useweeks):
|
||||
def output_text(changes, useweeks):
|
||||
if changes.get_commits():
|
||||
print("\nThe following history timeline has been gathered from the repository:")
|
||||
print("\n" + textwrap.fill(__timeline_info_text__ + ":", width=terminal.get_size()[0]))
|
||||
|
||||
timeline_data = TimelineData(changes, useweeks)
|
||||
periods = timeline_data.get_periods()
|
||||
|
@ -119,4 +125,34 @@ def output(changes, useweeks):
|
|||
max_periods_per_row = int((width - 21) / 11)
|
||||
|
||||
for i in range(0, len(periods), max_periods_per_row):
|
||||
__output_row__(timeline_data, periods[i:i+max_periods_per_row], names)
|
||||
__output_row__text__(timeline_data, periods[i:i+max_periods_per_row], names)
|
||||
|
||||
def output_xml(changes, useweeks):
|
||||
if changes.get_commits():
|
||||
message_xml = "\t\t<message>" + __timeline_info_text__ + "</message>\n"
|
||||
timeline_xml = ""
|
||||
periods_xml = "\t\t<periods length=\"{0}\">\n".format("week" if useweeks else "month")
|
||||
|
||||
timeline_data = TimelineData(changes, useweeks)
|
||||
periods = timeline_data.get_periods()
|
||||
names = timeline_data.get_authors()
|
||||
|
||||
for period in periods:
|
||||
name_xml = "\t\t\t\t<name>" + str(period) + "</name>\n"
|
||||
authors_xml = ""
|
||||
|
||||
for name in names:
|
||||
authors_xml += "\t\t\t\t<authors>\n"
|
||||
multiplier = timeline_data.get_multiplier(period, 24)
|
||||
signs = timeline_data.get_author_signs_in_period(name, period, multiplier)
|
||||
signs_str = (signs[1] * "-" + signs[0] * "+")
|
||||
|
||||
if not len(signs_str) == 0:
|
||||
authors_xml += "\t\t\t\t\t<author>\n\t\t\t\t\t\t<name>" + name + "</name>\n"
|
||||
authors_xml += "\t\t\t\t\t\t<work>" + signs_str + "</work>\n\t\t\t\t\t</author>\n"
|
||||
|
||||
authors_xml += "\t\t\t\t</authors>\n"
|
||||
|
||||
timeline_xml += "\t\t\t<period>\n" + name_xml + authors_xml + "\t\t\t</period>\n"
|
||||
|
||||
print("\t<timeline>\n" + message_xml + periods_xml + timeline_xml + "\t\t</periods>\n\t</timeline>")
|
||||
|
|
Loading…
Reference in a new issue