Re-factored the changes module and made it more independent.

This will make it easier to add support for the merging of statistics from
multiple repositories (as discussed in issue #24).
This commit is contained in:
Adam Waldenberg 2015-10-29 03:09:46 +01:00
parent fa04eb57f3
commit 1ed9b5e3cf
5 changed files with 29 additions and 29 deletions

View file

@ -211,6 +211,9 @@ class Changes(object):
self.last_commit_date = datetime.date(int(self.commits[-1].date[0:4]), int(self.commits[-1].date[5:7]),
int(self.commits[-1].date[8:10]))
def __add__(self, other):
pass # TODO
def get_commits(self):
return self.commits
@ -249,13 +252,3 @@ class Changes(object):
def get_latest_email_by_author(self, name):
return self.emails_by_author[name]
__changes__ = None
def get(hard):
global __changes__
if __changes__ == None:
__changes__ = Changes(hard)
return __changes__

View file

@ -23,7 +23,8 @@ import atexit
import getopt
import os
import sys
from . import (basedir, changes, clone, config, extensions, filtering, format, help, interval,
from .changes import Changes
from . import (basedir, clone, config, extensions, filtering, format, help, interval,
localization, optval, terminal, version)
from .output import outputable
from .output.blameoutput import BlameOutput
@ -62,19 +63,21 @@ class Runner(object):
absolute_path = basedir.get_basedir_git()
os.chdir(absolute_path)
format.output_header()
outputable.output(ChangesOutput(self.hard))
if changes.get(self.hard).get_commits():
outputable.output(BlameOutput(changes.get(self.hard), self.hard, self.useweeks))
changes = Changes(self.hard)
outputable.output(ChangesOutput(changes))
if changes.get_commits():
outputable.output(BlameOutput(changes, self.hard, self.useweeks))
if self.timeline:
outputable.output(TimelineOutput(changes.get(self.hard), self.useweeks))
outputable.output(TimelineOutput(changes, self.useweeks))
if self.include_metrics:
outputable.output(MetricsOutput())
if self.responsibilities:
outputable.output(ResponsibilitiesOutput(self.hard, self.useweeks))
outputable.output(ResponsibilitiesOutput(changes, self.hard, self.useweeks))
outputable.output(FilteringOutput())

View file

@ -22,15 +22,15 @@ from __future__ import unicode_literals
import json
import textwrap
from ..localization import N_
from .. import changes, format, gravatar, terminal
from .. import format, gravatar, terminal
from .outputable import Outputable
HISTORICAL_INFO_TEXT = N_("The following historical commit information, by author, was found in the repository")
NO_COMMITED_FILES_TEXT = N_("No commited files with the specified extensions were found")
class ChangesOutput(Outputable):
def __init__(self, hard):
self.changes = changes.get(hard)
def __init__(self, changes):
self.changes = changes
Outputable.__init__(self)
def output_html(self):

View file

@ -21,7 +21,7 @@ from __future__ import print_function
from __future__ import unicode_literals
import textwrap
from ..localization import N_
from .. import blame, changes, format, gravatar, terminal
from .. import blame, format, gravatar, terminal
from .. import responsibilities as resp
from .outputable import Outputable
@ -31,17 +31,18 @@ RESPONSIBILITIES_INFO_TEXT = N_("The following responsibilities, by author, were
MOSTLY_RESPONSIBLE_FOR_TEXT = N_("is mostly responsible for")
class ResponsibilitiesOutput(Outputable):
def __init__(self, hard, useweeks):
def __init__(self, changes, hard, useweeks):
self.changes = changes
self.hard = hard
self.useweeks = useweeks
Outputable.__init__(self)
self.changes = changes.get(hard)
def output_text(self):
print("\n" + textwrap.fill(_(RESPONSIBILITIES_INFO_TEXT) + ":", width=terminal.get_size()[0]))
for i in sorted(set(i[0] for i in blame.get(self.hard, self.useweeks, self.changes).blames)):
responsibilities = sorted(((i[1], i[0]) for i in resp.Responsibilities.get(self.hard, self.useweeks, i)), reverse=True)
responsibilities = sorted(((i[1], i[0]) for i in resp.Responsibilities.get(self.changes,
self.hard, self.useweeks, i)), reverse=True)
if responsibilities:
print("\n" + i, _(MOSTLY_RESPONSIBLE_FOR_TEXT) + ":")
@ -60,7 +61,8 @@ class ResponsibilitiesOutput(Outputable):
resp_xml += "<p>" + _(RESPONSIBILITIES_INFO_TEXT) + ".</p>"
for i in sorted(set(i[0] for i in blame.get(self.hard, self.useweeks, self.changes).blames)):
responsibilities = sorted(((i[1], i[0]) for i in resp.Responsibilities.get(self.hard, self.useweeks, i)), reverse=True)
responsibilities = sorted(((i[1], i[0]) for i in resp.Responsibilities.get(self.changes,
self.hard, self.useweeks, i)), reverse=True)
if responsibilities:
resp_xml += "<div>"
@ -86,7 +88,8 @@ class ResponsibilitiesOutput(Outputable):
resp_xml = ""
for i in sorted(set(i[0] for i in blame.get(self.hard, self.useweeks, self.changes).blames)):
responsibilities = sorted(((i[1], i[0]) for i in resp.Responsibilities.get(self.hard, self.useweeks, i)), reverse=True)
responsibilities = sorted(((i[1], i[0]) for i in resp.Responsibilities.get(self.changes,
self.hard, self.useweeks, i)), reverse=True)
if responsibilities:
author_email = self.changes.get_latest_email_by_author(i)
@ -116,7 +119,8 @@ class ResponsibilitiesOutput(Outputable):
resp_xml = ""
for i in sorted(set(i[0] for i in blame.get(self.hard, self.useweeks, self.changes).blames)):
responsibilities = sorted(((i[1], i[0]) for i in resp.Responsibilities.get(self.hard, self.useweeks, i)), reverse=True)
responsibilities = sorted(((i[1], i[0]) for i in resp.Responsibilities.get(self.changes,
self.hard, self.useweeks, i)), reverse=True)
if responsibilities:
author_email = self.changes.get_latest_email_by_author(i)

View file

@ -19,17 +19,17 @@
from __future__ import print_function
from __future__ import unicode_literals
from . import blame, changes
from . import blame
class ResponsibiltyEntry(object):
blames = {}
class Responsibilities(object):
@staticmethod
def get(hard, useweeks, author_name):
def get(changes, hard, useweeks, author_name):
author_blames = {}
for i in blame.get(hard, useweeks, changes.get(hard)).blames.items():
for i in blame.get(hard, useweeks, changes).blames.items():
if author_name == i[0][0]:
total_rows = i[1].rows - i[1].comments
if total_rows > 0: