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
#
# Copyright © 2012-2013 Ejwa Software. All rights reserved.
# Copyright © 2012-2014 Ejwa Software. All rights reserved.
#
# This file is part of gitinspector.
#
@ -18,6 +18,7 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import os
import subprocess
import sys
def get_basedir():
@ -25,3 +26,23 @@ def get_basedir():
return sys.prefix
else:
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()
import atexit
import basedir
import blame
import changes
import clone
@ -40,7 +41,6 @@ import os
import optval
import outputable
import responsibilities
import subprocess
import sys
import terminal
import timeline
@ -57,7 +57,6 @@ class Runner:
self.grading = False
self.timeline = False
self.useweeks = False
self.isbare = False
def output(self):
if not self.localize_output:
@ -68,24 +67,8 @@ class Runner:
previous_directory = os.getcwd()
os.chdir(self.repo)
isbare = subprocess.Popen("git rev-parse --is-bare-repository", shell=True, bufsize=1,
stdout=subprocess.PIPE).stdout
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())
absolute_path = basedir.get_basedir_git()
os.chdir(absolute_path)
format.output_header()
outputable.output(changes.ChangesOutput(self.hard))