From ac5c5ddb3176c0d7505cdd78e6444315a15b6237 Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Fri, 12 Oct 2012 12:52:35 +0200 Subject: [PATCH] Added format module with initial support for different formats. Currently this does nothing but will later enable us to output xml and html alongside the current support for text output. --- format.py | 37 ++++++++++++++++++++++ gitinspector.py | 82 ++++++++++++++++++++++++++----------------------- help.py | 6 +++- html.template | 8 +++++ 4 files changed, 94 insertions(+), 39 deletions(-) create mode 100644 format.py create mode 100644 html.template diff --git a/format.py b/format.py new file mode 100644 index 0000000..e880137 --- /dev/null +++ b/format.py @@ -0,0 +1,37 @@ +# coding: utf-8 +# +# Copyright © 2012 Ejwa Software. All rights reserved. +# +# 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 . + +from __future__ import print_function +import terminal + +__available_formats__ = ["html", "text", "xml"] +__default_format__ = __available_formats__[1] +__selected_format__ = __default_format__ + +class InvalidFormatError(Exception): + pass + +def select(format): + global __selected_format__ + __selected_format__ = format + + return format in __available_formats__ + +def output(): + print("Currently nothing") diff --git a/gitinspector.py b/gitinspector.py index 820853d..d510057 100755 --- a/gitinspector.py +++ b/gitinspector.py @@ -23,6 +23,7 @@ import blame import changes import extensions import filtering +import format import getopt import help import metrics @@ -75,46 +76,51 @@ if __name__ == "__main__": __run__ = Runner() try: - __opts__, __args__ = getopt.gnu_getopt(sys.argv[1:], "cf:hHlmrTwx:", ["checkout-missing", "exclude=", - "file-types=", "hard", "help", "list-file-types", "metrics", - "responsibilities", "grading", "timeline", "version"]) - except getopt.error as msg: + __opts__, __args__ = getopt.gnu_getopt(sys.argv[1:], "cf:F:hHlmrTwx:", ["checkout-missing", "exclude=", + "file-types=", "format=", "hard", "help", "list-file-types", + "metrics", "responsibilities", "grading", "timeline", + "version"]) + for o, a in __opts__: + if o in("-c", "--checkout-missing"): + missing.set_checkout_missing(True) + elif o in("-h", "--help"): + 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.") + elif o in("-H", "--hard"): + __run__.hard = True + elif o in("-l", "--list-file-types"): + __run__.list_file_types = True + elif o in("-m", "--metrics"): + __run__.include_metrics = True + elif o in("-r", "--responsibilities"): + __run__.responsibilities = True + elif o in("--version"): + version.output() + sys.exit(0) + elif o in("--grading"): + __run__.include_metrics = True + __run__.list_file_types = True + __run__.responsibilities = True + __run__.grading = True + __run__.timeline = True + __run__.useweeks = True + elif o in("-T", "--timeline"): + __run__.timeline = True + elif o in("-w"): + __run__.useweeks = True + elif o in("-x", "--exclude"): + filtering.add(a) + for arg in __args__: + __run__.repo = arg + + except (format.InvalidFormatError, getopt.error) as msg: print(sys.argv[0], "\b:", msg) print("Try `", sys.argv[0], "--help' for more information.") sys.exit(2) - for o, a in __opts__: - if o in("-c", "--checkout-missing"): - missing.set_checkout_missing(True) - elif o in("-h", "--help"): - help.output() - sys.exit(0) - elif o in("-f", "--file-types"): - extensions.define(a) - elif o in("-H", "--hard"): - __run__.hard = True - elif o in("-l", "--list-file-types"): - __run__.list_file_types = True - elif o in("-m", "--metrics"): - __run__.include_metrics = True - elif o in("-r", "--responsibilities"): - __run__.responsibilities = True - elif o in("--version"): - version.output() - sys.exit(0) - elif o in("--grading"): - __run__.include_metrics = True - __run__.list_file_types = True - __run__.responsibilities = True - __run__.grading = True - __run__.timeline = True - __run__.useweeks = True - elif o in("-T", "--timeline"): - __run__.timeline = True - elif o in("-w"): - __run__.useweeks = True - elif o in("-x", "--exclude"): - filtering.add(a) - for arg in __args__: - __run__.repo = arg __run__.output() diff --git a/help.py b/help.py index a22341f..c5dd3e8 100644 --- a/help.py +++ b/help.py @@ -28,6 +28,9 @@ Mandatory arguments to long options are mandatory for short options too. include when computing statistics. The default extensions used are: {1} + -F, --format=FORMAT define in which format output should be + generated; the default format is 'txt' and + the available formats are: {2} --grading show statistics and information in a way that is formatted for grading of student projects; this is the same as supplying -lmrTw @@ -57,7 +60,8 @@ Report gitinspector bugs to gitinspector@ejwa.se.""" from __future__ import print_function from extensions import __default_extensions__ +from format import __available_formats__ import sys def output(): - print(__doc__.format(sys.argv[0], ",".join(__default_extensions__))) + print(__doc__.format(sys.argv[0], ",".join(__default_extensions__), ",".join(__available_formats__))) diff --git a/html.template b/html.template new file mode 100644 index 0000000..d2ba1e3 --- /dev/null +++ b/html.template @@ -0,0 +1,8 @@ + + + {0} + + +

{0}

+ +