2014-10-23 15:25:22 +02:00
|
|
|
#!/usr/bin/env python
|
2012-05-04 11:40:30 +02:00
|
|
|
# coding: utf-8
|
|
|
|
#
|
2015-10-05 06:17:10 +02:00
|
|
|
# Copyright © 2012-2015 Ejwa Software. All rights reserved.
|
2012-05-04 11:40:30 +02:00
|
|
|
#
|
|
|
|
# This file is part of gitinspector.
|
|
|
|
#
|
|
|
|
# gitinspector is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# gitinspector is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-05-25 16:42:29 +02:00
|
|
|
from __future__ import print_function
|
2013-06-25 16:37:18 +02:00
|
|
|
from __future__ import unicode_literals
|
2013-06-25 14:38:40 +02:00
|
|
|
|
|
|
|
import localization
|
|
|
|
localization.init()
|
|
|
|
|
2014-01-21 12:14:13 +01:00
|
|
|
import atexit
|
2014-02-20 03:49:16 +01:00
|
|
|
import basedir
|
2012-05-04 11:40:30 +02:00
|
|
|
import blame
|
|
|
|
import changes
|
2014-01-21 12:14:13 +01:00
|
|
|
import clone
|
2013-06-30 20:58:30 +02:00
|
|
|
import config
|
2012-05-04 11:40:30 +02:00
|
|
|
import extensions
|
2012-05-22 17:57:44 +02:00
|
|
|
import filtering
|
2012-10-12 12:52:35 +02:00
|
|
|
import format
|
2012-05-04 11:40:30 +02:00
|
|
|
import help
|
2013-05-01 23:09:10 +02:00
|
|
|
import interval
|
2013-07-14 00:07:36 +02:00
|
|
|
import getopt
|
2012-05-14 15:24:45 +02:00
|
|
|
import metrics
|
2012-05-20 22:02:08 +02:00
|
|
|
import os
|
2013-07-09 12:40:59 +02:00
|
|
|
import optval
|
2013-03-11 00:23:50 +01:00
|
|
|
import outputable
|
2012-05-25 14:27:28 +02:00
|
|
|
import responsibilities
|
2012-05-04 11:40:30 +02:00
|
|
|
import sys
|
|
|
|
import terminal
|
|
|
|
import timeline
|
|
|
|
import version
|
|
|
|
|
|
|
|
class Runner:
|
2013-07-14 00:07:36 +02:00
|
|
|
def __init__(self):
|
|
|
|
self.hard = False
|
|
|
|
self.include_metrics = False
|
|
|
|
self.list_file_types = False
|
|
|
|
self.localize_output = False
|
2012-05-04 11:40:30 +02:00
|
|
|
self.repo = "."
|
2013-07-14 00:07:36 +02:00
|
|
|
self.responsibilities = False
|
|
|
|
self.grading = False
|
|
|
|
self.timeline = False
|
|
|
|
self.useweeks = False
|
2012-05-04 11:40:30 +02:00
|
|
|
|
|
|
|
def output(self):
|
2013-07-14 00:07:36 +02:00
|
|
|
if not self.localize_output:
|
|
|
|
localization.disable()
|
|
|
|
|
2012-05-05 10:26:02 +02:00
|
|
|
terminal.skip_escapes(not sys.stdout.isatty())
|
2013-05-20 01:48:17 +02:00
|
|
|
terminal.set_stdout_encoding()
|
2012-05-20 22:02:08 +02:00
|
|
|
previous_directory = os.getcwd()
|
2013-07-10 14:23:11 +02:00
|
|
|
|
2012-05-20 22:02:08 +02:00
|
|
|
os.chdir(self.repo)
|
2014-02-20 03:49:16 +01:00
|
|
|
absolute_path = basedir.get_basedir_git()
|
|
|
|
os.chdir(absolute_path)
|
2012-10-18 16:59:52 +02:00
|
|
|
format.output_header()
|
2013-07-14 00:07:36 +02:00
|
|
|
outputable.output(changes.ChangesOutput(self.hard))
|
2012-05-04 11:40:30 +02:00
|
|
|
|
2013-07-14 00:07:36 +02:00
|
|
|
if changes.get(self.hard).get_commits():
|
2015-10-05 06:17:10 +02:00
|
|
|
outputable.output(blame.BlameOutput(changes.get(self.hard), self.hard, self.useweeks))
|
2012-05-04 11:40:30 +02:00
|
|
|
|
2013-07-14 00:07:36 +02:00
|
|
|
if self.timeline:
|
|
|
|
outputable.output(timeline.Timeline(changes.get(self.hard), self.useweeks))
|
2012-05-04 11:40:30 +02:00
|
|
|
|
2013-07-14 00:07:36 +02:00
|
|
|
if self.include_metrics:
|
2013-03-11 00:23:50 +01:00
|
|
|
outputable.output(metrics.Metrics())
|
2012-05-14 15:24:45 +02:00
|
|
|
|
2013-07-14 00:07:36 +02:00
|
|
|
if self.responsibilities:
|
2014-02-14 05:25:14 +01:00
|
|
|
outputable.output(responsibilities.ResponsibilitiesOutput(self.hard, self.useweeks))
|
2012-05-25 14:27:28 +02:00
|
|
|
|
2013-03-11 00:23:50 +01:00
|
|
|
outputable.output(filtering.Filtering())
|
2012-05-07 09:38:11 +02:00
|
|
|
|
2013-07-14 00:07:36 +02:00
|
|
|
if self.list_file_types:
|
2013-03-11 00:23:50 +01:00
|
|
|
outputable.output(extensions.Extensions())
|
2012-05-04 11:40:30 +02:00
|
|
|
|
2012-10-18 16:59:52 +02:00
|
|
|
format.output_footer()
|
2012-05-20 22:02:08 +02:00
|
|
|
os.chdir(previous_directory)
|
|
|
|
|
2013-06-05 01:50:29 +02:00
|
|
|
def __check_python_version__():
|
2013-06-06 03:05:30 +02:00
|
|
|
if sys.version_info < (2, 6):
|
2013-06-05 01:50:29 +02:00
|
|
|
python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1])
|
2013-07-25 08:52:52 +02:00
|
|
|
sys.exit(_("gitinspector requires at least Python 2.6 to run (version {0} was found).").format(python_version))
|
2013-06-05 01:50:29 +02:00
|
|
|
|
2013-06-14 03:11:56 +02:00
|
|
|
def main():
|
2014-01-08 06:05:10 +01:00
|
|
|
terminal.check_terminal_encoding()
|
|
|
|
terminal.set_stdin_encoding()
|
2013-07-14 03:10:00 +02:00
|
|
|
argv = terminal.convert_command_line_to_utf8()
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__ = Runner()
|
2012-05-04 11:40:30 +02:00
|
|
|
|
|
|
|
try:
|
2013-08-03 10:30:43 +02:00
|
|
|
__opts__, __args__ = optval.gnu_getopt(argv[1:], "f:F:hHlLmrTwx:", ["exclude=", "file-types=", "format=",
|
|
|
|
"hard:true", "help", "list-file-types:true",
|
|
|
|
"localize-output:true", "metrics:true", "responsibilities:true",
|
|
|
|
"since=", "grading:true", "timeline:true", "until=", "version",
|
2013-07-14 03:10:00 +02:00
|
|
|
"weeks:true"])
|
2013-07-14 00:07:36 +02:00
|
|
|
for arg in __args__:
|
2013-07-01 01:38:19 +02:00
|
|
|
__run__.repo = arg
|
|
|
|
|
2014-01-21 12:14:13 +01:00
|
|
|
#Try to clone the repo or return the same directory and bail out.
|
|
|
|
__run__.repo = clone.create(__run__.repo)
|
|
|
|
|
2013-07-01 01:38:19 +02:00
|
|
|
#We need the repo above to be set before we read the git config.
|
|
|
|
config.init(__run__)
|
2013-07-14 04:29:00 +02:00
|
|
|
clear_x_on_next_pass = True
|
2013-07-01 01:38:19 +02:00
|
|
|
|
2013-07-14 00:07:36 +02:00
|
|
|
for o, a in __opts__:
|
2013-08-03 10:30:43 +02:00
|
|
|
if o in("-h", "--help"):
|
2013-07-14 00:07:36 +02:00
|
|
|
help.output()
|
|
|
|
sys.exit(0)
|
|
|
|
elif o in("-f", "--file-types"):
|
|
|
|
extensions.define(a)
|
|
|
|
elif o in("-F", "--format"):
|
|
|
|
if not format.select(a):
|
|
|
|
raise format.InvalidFormatError(_("specified output format not supported."))
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "-H":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.hard = True
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "--hard":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.hard = optval.get_boolean_argument(a)
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "-l":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.list_file_types = True
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "--list-file-types":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.list_file_types = optval.get_boolean_argument(a)
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "-L":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.localize_output = True
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "--localize-output":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.localize_output = optval.get_boolean_argument(a)
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "-m":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.include_metrics = True
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "--metrics":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.include_metrics = optval.get_boolean_argument(a)
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "-r":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.responsibilities = True
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "--responsibilities":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.responsibilities = optval.get_boolean_argument(a)
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "--since":
|
2013-07-14 00:07:36 +02:00
|
|
|
interval.set_since(a)
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "--version":
|
2013-07-14 00:07:36 +02:00
|
|
|
version.output()
|
|
|
|
sys.exit(0)
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "--grading":
|
2013-07-14 00:07:36 +02:00
|
|
|
grading = optval.get_boolean_argument(a)
|
|
|
|
__run__.include_metrics = grading
|
|
|
|
__run__.list_file_types = grading
|
|
|
|
__run__.responsibilities = grading
|
|
|
|
__run__.grading = grading
|
|
|
|
__run__.hard = grading
|
|
|
|
__run__.timeline = grading
|
|
|
|
__run__.useweeks = grading
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "-T":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.timeline = True
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "--timeline":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.timeline = optval.get_boolean_argument(a)
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "--until":
|
2013-07-14 00:07:36 +02:00
|
|
|
interval.set_until(a)
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "-w":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.useweeks = True
|
2013-07-24 09:06:30 +02:00
|
|
|
elif o == "--weeks":
|
2013-07-14 00:07:36 +02:00
|
|
|
__run__.useweeks = optval.get_boolean_argument(a)
|
|
|
|
elif o in("-x", "--exclude"):
|
2013-07-14 04:29:00 +02:00
|
|
|
if clear_x_on_next_pass:
|
|
|
|
clear_x_on_next_pass = False
|
|
|
|
filtering.clear()
|
2013-07-14 00:07:36 +02:00
|
|
|
filtering.add(a)
|
|
|
|
|
2013-07-14 12:19:31 +02:00
|
|
|
__check_python_version__()
|
|
|
|
__run__.output()
|
|
|
|
|
|
|
|
except (filtering.InvalidRegExpError, format.InvalidFormatError, optval.InvalidOptionArgument, getopt.error) as exception:
|
2013-07-15 04:48:25 +02:00
|
|
|
print(sys.argv[0], "\b:", exception.msg, file=sys.stderr)
|
|
|
|
print(_("Try `{0} --help' for more information.").format(sys.argv[0]), file=sys.stderr)
|
2012-05-04 11:40:30 +02:00
|
|
|
sys.exit(2)
|
|
|
|
|
2014-01-21 12:14:13 +01:00
|
|
|
@atexit.register
|
|
|
|
def cleanup():
|
|
|
|
clone.delete()
|
|
|
|
|
2013-06-14 03:11:56 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|