Moved absolute path detection into the basedir module.

The base name of the returned absolute path is also the name of the
repository from which the statistics were gathered. We will use this in
the generated reports.
This commit is contained in:
Adam Waldenberg 2014-02-20 03:49:16 +01:00
parent 0447da1933
commit 12e08daf72
2 changed files with 25 additions and 21 deletions

View File

@ -1,6 +1,6 @@
# coding: utf-8 # 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. # This file is part of gitinspector.
# #
@ -18,6 +18,7 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import os import os
import subprocess
import sys import sys
def get_basedir(): def get_basedir():
@ -25,3 +26,23 @@ def get_basedir():
return sys.prefix return sys.prefix
else: else:
return os.path.dirname(os.path.realpath(__file__)) return os.path.dirname(os.path.realpath(__file__))
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 = ""
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."))
return absolute_path[0].decode("utf-8", "replace").strip()

View File

@ -25,6 +25,7 @@ import localization
localization.init() localization.init()
import atexit import atexit
import basedir
import blame import blame
import changes import changes
import clone import clone
@ -40,7 +41,6 @@ import os
import optval import optval
import outputable import outputable
import responsibilities import responsibilities
import subprocess
import sys import sys
import terminal import terminal
import timeline import timeline
@ -57,7 +57,6 @@ class Runner:
self.grading = False self.grading = False
self.timeline = False self.timeline = False
self.useweeks = False self.useweeks = False
self.isbare = False
def output(self): def output(self):
if not self.localize_output: if not self.localize_output:
@ -68,24 +67,8 @@ class Runner:
previous_directory = os.getcwd() previous_directory = os.getcwd()
os.chdir(self.repo) os.chdir(self.repo)
isbare = subprocess.Popen("git rev-parse --is-bare-repository", shell=True, bufsize=1, absolute_path = basedir.get_basedir_git()
stdout=subprocess.PIPE).stdout os.chdir(absolute_path)
isbare = isbare.readlines()
self.isbare = (isbare[0].decode("utf-8", "replace").strip() == "true")
absolute_path = ""
if self.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."))
os.chdir(absolute_path[0].decode("utf-8", "replace").strip())
format.output_header() format.output_header()
outputable.output(changes.ChangesOutput(self.hard)) outputable.output(changes.ChangesOutput(self.hard))