mirror of
https://github.com/ejwa/gitinspector.git
synced 2025-03-26 02:01:27 +01:00
add csv format with combine change and blame
add csv format with combine change and blame
This commit is contained in:
parent
6d77989e34
commit
89d80214b3
4 changed files with 61 additions and 18 deletions
gitinspector
|
@ -27,12 +27,14 @@ import zipfile
|
|||
from .localization import N_
|
||||
from . import basedir, localization, terminal, version
|
||||
|
||||
__available_formats__ = ["html", "htmlembedded", "json", "text", "xml"]
|
||||
__available_formats__ = ["html", "htmlembedded", "json", "text", "xml", "csv"]
|
||||
|
||||
DEFAULT_FORMAT = __available_formats__[3]
|
||||
|
||||
__selected_format__ = DEFAULT_FORMAT
|
||||
|
||||
__selected_format_tag__ = ""
|
||||
|
||||
class InvalidFormatError(Exception):
|
||||
def __init__(self, msg):
|
||||
super(InvalidFormatError, self).__init__(msg)
|
||||
|
@ -47,6 +49,17 @@ def select(format):
|
|||
def get_selected():
|
||||
return __selected_format__
|
||||
|
||||
|
||||
def set_tag(format):
|
||||
global __selected_format_tag__
|
||||
__selected_format_tag__ = format
|
||||
|
||||
|
||||
def get_tag():
|
||||
return __selected_format_tag__
|
||||
|
||||
|
||||
|
||||
def is_interactive_format():
|
||||
return __selected_format__ == "text"
|
||||
|
||||
|
|
44
gitinspector/gitinspector.py
Normal file → Executable file
44
gitinspector/gitinspector.py
Normal file → Executable file
|
@ -32,6 +32,7 @@ from . import (basedir, clone, extensions, filtering, format, help, interval,
|
|||
from .output import outputable
|
||||
from .output.blameoutput import BlameOutput
|
||||
from .output.changesoutput import ChangesOutput
|
||||
from .output.changesblameoutput import ChangesBlameOutput
|
||||
from .output.extensionsoutput import ExtensionsOutput
|
||||
from .output.filteringoutput import FilteringOutput
|
||||
from .output.metricsoutput import MetricsOutput
|
||||
|
@ -79,29 +80,34 @@ class Runner(object):
|
|||
else:
|
||||
os.chdir(previous_directory)
|
||||
|
||||
format.output_header(repos)
|
||||
outputable.output(ChangesOutput(summed_changes))
|
||||
# print("current format: " + format.get_selected())
|
||||
if format.get_selected() == "csv":
|
||||
# print("output format: " + format.get_selected())
|
||||
outputable.output(ChangesBlameOutput(summed_changes, summed_blames))
|
||||
else:
|
||||
format.output_header(repos)
|
||||
outputable.output(ChangesOutput(summed_changes))
|
||||
|
||||
if summed_changes.get_commits():
|
||||
outputable.output(BlameOutput(summed_changes, summed_blames))
|
||||
if summed_changes.get_commits():
|
||||
outputable.output(BlameOutput(summed_changes, summed_blames))
|
||||
|
||||
if self.timeline:
|
||||
outputable.output(TimelineOutput(summed_changes, self.useweeks))
|
||||
if self.timeline:
|
||||
outputable.output(TimelineOutput(summed_changes, self.useweeks))
|
||||
|
||||
if self.include_metrics:
|
||||
outputable.output(MetricsOutput(summed_metrics))
|
||||
if self.include_metrics:
|
||||
outputable.output(MetricsOutput(summed_metrics))
|
||||
|
||||
if self.responsibilities:
|
||||
outputable.output(ResponsibilitiesOutput(summed_changes, summed_blames))
|
||||
if self.responsibilities:
|
||||
outputable.output(ResponsibilitiesOutput(summed_changes, summed_blames))
|
||||
|
||||
outputable.output(FilteringOutput())
|
||||
outputable.output(FilteringOutput())
|
||||
|
||||
if self.list_file_types:
|
||||
outputable.output(ExtensionsOutput())
|
||||
|
||||
format.output_footer()
|
||||
if self.list_file_types:
|
||||
outputable.output(ExtensionsOutput())
|
||||
format.output_footer()
|
||||
os.chdir(previous_directory)
|
||||
|
||||
|
||||
def __check_python_version__():
|
||||
if sys.version_info < (2, 6):
|
||||
python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1])
|
||||
|
@ -133,12 +139,13 @@ def main():
|
|||
repos = []
|
||||
|
||||
try:
|
||||
opts, args = optval.gnu_getopt(argv[1:], "f:F:hHlLmrTwx:", ["exclude=", "file-types=", "format=",
|
||||
opts, args = optval.gnu_getopt(argv[1:], "f:t:F:hHlLmrTwx:", ["exclude=", "file-types=", "tag=" ,"format=",
|
||||
"hard:true", "help", "list-file-types:true", "localize-output:true",
|
||||
"metrics:true", "responsibilities:true", "since=", "grading:true",
|
||||
"timeline:true", "until=", "version", "weeks:true"])
|
||||
# print("begin git clone")
|
||||
repos = __get_validated_git_repos__(set(args))
|
||||
|
||||
# print("end git clone")
|
||||
#We need the repos above to be set before we read the git config.
|
||||
GitConfig(run, repos[-1].location).read()
|
||||
clear_x_on_next_pass = True
|
||||
|
@ -149,6 +156,8 @@ def main():
|
|||
sys.exit(0)
|
||||
elif o in("-f", "--file-types"):
|
||||
extensions.define(a)
|
||||
elif o in("-t", "--tag"):
|
||||
format.set_tag(a)
|
||||
elif o in("-F", "--format"):
|
||||
if not format.select(a):
|
||||
raise format.InvalidFormatError(_("specified output format not supported."))
|
||||
|
@ -213,6 +222,7 @@ def main():
|
|||
@atexit.register
|
||||
def cleanup():
|
||||
clone.delete()
|
||||
# pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -119,3 +119,18 @@ class FilteringOutput(Outputable):
|
|||
FilteringOutput.__output_xml_section__(_(FILTERING_EMAIL_INFO_TEXT), __filters__["email"][1], "emails")
|
||||
FilteringOutput.__output_xml_section__(_(FILTERING_COMMIT_INFO_TEXT), __filters__["revision"][1], "revision")
|
||||
print("\t</filtering>")
|
||||
|
||||
@staticmethod
|
||||
def __output_csv_section__(info_string, filtered):
|
||||
if filtered:
|
||||
print("\n" + textwrap.fill(info_string + ":", width=terminal.get_size()[0]))
|
||||
|
||||
for i in filtered:
|
||||
(width, _unused) = terminal.get_size()
|
||||
print("...%s" % i[-width+3:] if len(i) > width else i)
|
||||
|
||||
def output_csv(self):
|
||||
FilteringOutput.__output_csv_section__(_(FILTERING_INFO_TEXT), __filters__["file"][1])
|
||||
FilteringOutput.__output_csv_section__(_(FILTERING_AUTHOR_INFO_TEXT), __filters__["author"][1])
|
||||
FilteringOutput.__output_csv_section__(_(FILTERING_EMAIL_INFO_TEXT), __filters__["email"][1])
|
||||
FilteringOutput.__output_csv_section__(_(FILTERING_COMMIT_INFO_TEXT), __filters__["revision"][1])
|
|
@ -34,6 +34,9 @@ class Outputable(object):
|
|||
def output_xml(self):
|
||||
raise NotImplementedError(_("XML output not yet supported in") + " \"" + self.__class__.__name__ + "\".")
|
||||
|
||||
def output_csv(self):
|
||||
raise NotImplementedError(_("CSV output not yet supported in") + " \"" + self.__class__.__name__ + "\".")
|
||||
|
||||
def output(outputable):
|
||||
if format.get_selected() == "html" or format.get_selected() == "htmlembedded":
|
||||
outputable.output_html()
|
||||
|
@ -41,5 +44,7 @@ def output(outputable):
|
|||
outputable.output_json()
|
||||
elif format.get_selected() == "text":
|
||||
outputable.output_text()
|
||||
elif format.get_selected() == "csv":
|
||||
outputable.output_csv()
|
||||
else:
|
||||
outputable.output_xml()
|
||||
|
|
Loading…
Add table
Reference in a new issue