From 4e4d0a2ddbc4250fdc69f35da409c39b18b35ce1 Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Thu, 20 Feb 2014 04:06:47 +0100 Subject: [PATCH] The repository name and report date is now included in the generated text. --- gitinspector/basedir.py | 35 +++++++++++++++++++++-------------- gitinspector/format.py | 13 ++++++++++++- gitinspector/html/html.header | 2 +- gitinspector/localization.py | 21 +++++++++++++++++++-- 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/gitinspector/basedir.py b/gitinspector/basedir.py index dc1fcee..20bb3f6 100644 --- a/gitinspector/basedir.py +++ b/gitinspector/basedir.py @@ -27,22 +27,29 @@ def get_basedir(): else: return os.path.dirname(os.path.realpath(__file__)) +__git_basedir__ = None + def get_basedir_git(): - isbare = subprocess.Popen("git rev-parse --is-bare-repository", shell=True, bufsize=1, - stdout=subprocess.PIPE).stdout - isbare = isbare.readlines() - isbare = (isbare[0].decode("utf-8", "replace").strip() == "true") - absolute_path = "" + global __git_basedir__ - if isbare: - absolute_path = subprocess.Popen("git rev-parse --git-dir", shell=True, bufsize=1, - stdout=subprocess.PIPE).stdout - else: - absolute_path = subprocess.Popen("git rev-parse --show-toplevel", shell=True, bufsize=1, + if not __git_basedir__: + isbare = subprocess.Popen("git rev-parse --is-bare-repository", shell=True, bufsize=1, + stdout=subprocess.PIPE).stdout + isbare = isbare.readlines() + isbare = (isbare[0].decode("utf-8", "replace").strip() == "true") + absolute_path = "" + + if isbare: + absolute_path = subprocess.Popen("git rev-parse --git-dir", shell=True, bufsize=1, stdout=subprocess.PIPE).stdout + else: + absolute_path = subprocess.Popen("git rev-parse --show-toplevel", shell=True, bufsize=1, + stdout=subprocess.PIPE).stdout - absolute_path = absolute_path.readlines() - if len(absolute_path) == 0: - sys.exit(_("Unable to determine absolute path of git repository.")) + absolute_path = absolute_path.readlines() + if len(absolute_path) == 0: + sys.exit(_("Unable to determine absolute path of git repository.")) - return absolute_path[0].decode("utf-8", "replace").strip() + __git_basedir__ = absolute_path[0].decode("utf-8", "replace").strip() + + return __git_basedir__ diff --git a/gitinspector/format.py b/gitinspector/format.py index 29713ae..fb66bdc 100644 --- a/gitinspector/format.py +++ b/gitinspector/format.py @@ -1,6 +1,6 @@ # coding: utf-8 # -# Copyright © 2012-2013 Ejwa Software. All rights reserved. +# Copyright © 2012-2014 Ejwa Software. All rights reserved. # # This file is part of gitinspector. # @@ -19,10 +19,14 @@ from __future__ import print_function from __future__ import unicode_literals +import localization import version import base64 import basedir import os +import terminal +import textwrap +import time import zipfile __available_formats__ = ["html", "htmlembedded", "text", "xml"] @@ -88,6 +92,8 @@ def output_header(): logo_text = _("The output has been generated by {0}; the statistical analysis tool" " for git repositories.").format( "gitinspector"), + repo_text = _("Statistical information for the repository '{0}' was gathered on {1}.").format( + os.path.basename(basedir. get_basedir_git()), localization.get_date()), show_minor_authors = _("Show minor authors"), hide_minor_authors = _("Hide minor authors"), show_minor_rows = _("Show rows with minor work"), @@ -95,6 +101,11 @@ def output_header(): elif __selected_format__ == "xml": print("") print("\t" + version.__version__ + "") + print("\t" + os.path.basename(basedir. get_basedir_git()) + "") + print("\t" + time.strftime("%Y/%m/%d") + "") + else: + print(textwrap.fill(_("Statistical information for the repository '{0}' was gathered on {1}.").format( + os.path.basename(basedir. get_basedir_git()), localization.get_date()), width=terminal.get_size()[0])) def output_footer(): if __selected_format__ == "html": diff --git a/gitinspector/html/html.header b/gitinspector/html/html.header index 6036998..a6325e9 100644 --- a/gitinspector/html/html.header +++ b/gitinspector/html/html.header @@ -310,5 +310,5 @@
diff --git a/gitinspector/localization.py b/gitinspector/localization.py index db4d1c2..5bbdd78 100644 --- a/gitinspector/localization.py +++ b/gitinspector/localization.py @@ -1,6 +1,6 @@ # coding: utf-8 # -# Copyright © 2013 Ejwa Software. All rights reserved. +# Copyright © 2013-2014 Ejwa Software. All rights reserved. # # This file is part of gitinspector. # @@ -17,12 +17,15 @@ # You should have received a copy of the GNU General Public License # along with gitinspector. If not, see . +from __future__ import print_function from __future__ import unicode_literals import basedir import gettext import locale import os +import time +__enabled__ = False __installed__ = False __translation__ = None @@ -31,6 +34,7 @@ def N_(message): return message def init(): + global __enabled__ global __installed__ global __translation__ @@ -54,13 +58,26 @@ def init(): except IOError: __translation__ = gettext.NullTranslations() + __enabled__ = True __installed__ = True __translation__.install(True) +def get_date(): + if __enabled__ and isinstance(__translation__, gettext.GNUTranslations): + return time.strftime("%x") + else: + return time.strftime("%Y/%m/%d") + def enable(): - if __installed__ and type(__translation__) is not gettext.GNUTranslations: + if isinstance(__translation__, gettext.GNUTranslations): __translation__.install(True) + global __enabled__ + __enabled__ = True + def disable(): + global __enabled__ + __enabled__ = False + if __installed__: gettext.NullTranslations().install(True)