mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-12-22 21:52:15 +01:00
The basedir module is no longer persistent (doesn't remember state).
This is required in order for it to be callable multiple times for multiple repositories (Needed for #24).
This commit is contained in:
parent
258eefa1e7
commit
109a94e1e7
3 changed files with 25 additions and 28 deletions
|
@ -27,31 +27,28 @@ def get_basedir():
|
|||
else:
|
||||
return os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
__git_basedir__ = None
|
||||
|
||||
def get_basedir_git():
|
||||
global __git_basedir__
|
||||
bare_command = subprocess.Popen(["git", "rev-parse", "--is-bare-repository"], bufsize=1,
|
||||
stdout=subprocess.PIPE, stderr=open(os.devnull, "w"))
|
||||
|
||||
if not __git_basedir__:
|
||||
bare_command = subprocess.Popen(["git", "rev-parse", "--is-bare-repository"], bufsize=1,
|
||||
stdout=subprocess.PIPE, stderr=open(os.devnull, "w"))
|
||||
isbare = bare_command.stdout.readlines()
|
||||
bare_command.wait()
|
||||
if bare_command.returncode != 0:
|
||||
sys.exit(_("Error processing git repository at \"%s\"." % os.getcwd()))
|
||||
isbare = (isbare[0].decode("utf-8", "replace").strip() == "true")
|
||||
absolute_path = None
|
||||
isbare = bare_command.stdout.readlines()
|
||||
bare_command.wait()
|
||||
|
||||
if isbare:
|
||||
absolute_path = subprocess.Popen(["git", "rev-parse", "--git-dir"], bufsize=1, stdout=subprocess.PIPE).stdout
|
||||
else:
|
||||
absolute_path = subprocess.Popen(["git", "rev-parse", "--show-toplevel"], bufsize=1,
|
||||
stdout=subprocess.PIPE).stdout
|
||||
if bare_command.returncode != 0:
|
||||
sys.exit(_("Error processing git repository at \"%s\"." % os.getcwd()))
|
||||
|
||||
absolute_path = absolute_path.readlines()
|
||||
if len(absolute_path) == 0:
|
||||
sys.exit(_("Unable to determine absolute path of git repository."))
|
||||
isbare = (isbare[0].decode("utf-8", "replace").strip() == "true")
|
||||
absolute_path = None
|
||||
|
||||
__git_basedir__ = absolute_path[0].decode("utf-8", "replace").strip()
|
||||
if isbare:
|
||||
absolute_path = subprocess.Popen(["git", "rev-parse", "--git-dir"], bufsize=1, stdout=subprocess.PIPE).stdout
|
||||
else:
|
||||
absolute_path = subprocess.Popen(["git", "rev-parse", "--show-toplevel"], bufsize=1,
|
||||
stdout=subprocess.PIPE).stdout
|
||||
|
||||
return __git_basedir__
|
||||
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()
|
||||
|
|
|
@ -59,7 +59,7 @@ def __get_zip_file_content__(name, file_name="/html/flot.zip"):
|
|||
zip_file.close()
|
||||
return content.decode("utf-8", "replace")
|
||||
|
||||
def output_header():
|
||||
def output_header(repo):
|
||||
if __selected_format__ == "html" or __selected_format__ == "htmlembedded":
|
||||
base = basedir.get_basedir()
|
||||
html_header = __output_html_template__(base + "/html/html.header")
|
||||
|
@ -80,7 +80,7 @@ def output_header():
|
|||
else:
|
||||
jquery_js = " src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js\">"
|
||||
|
||||
print(html_header.format(title=_("Repository statistics for {0}").format(os.path.basename(basedir.get_basedir_git())),
|
||||
print(html_header.format(title=_("Repository statistics for {0}").format(os.path.basename(repo)),
|
||||
jquery=jquery_js,
|
||||
jquery_tablesorter=tablesorter_js,
|
||||
jquery_flot=flot_js,
|
||||
|
@ -92,7 +92,7 @@ def output_header():
|
|||
"<a href=\"https://github.com/ejwa/gitinspector\">gitinspector</a>",
|
||||
version.__version__),
|
||||
repo_text=_("Statistical information for the repository '{0}' was gathered on {1}.").format(
|
||||
os.path.basename(basedir. get_basedir_git()), localization.get_date()),
|
||||
os.path.basename(repo), localization.get_date()),
|
||||
show_minor_authors=_("Show minor authors"),
|
||||
hide_minor_authors=_("Hide minor authors"),
|
||||
show_minor_rows=_("Show rows with minor work"),
|
||||
|
@ -102,11 +102,11 @@ def output_header():
|
|||
elif __selected_format__ == "xml":
|
||||
print("<gitinspector>")
|
||||
print("\t<version>" + version.__version__ + "</version>")
|
||||
print("\t<repository>" + os.path.basename(basedir. get_basedir_git()) + "</repository>")
|
||||
print("\t<repository>" + os.path.basename(repo) + "</repository>")
|
||||
print("\t<report-date>" + time.strftime("%Y/%m/%d") + "</report-date>")
|
||||
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]))
|
||||
os.path.basename(repo), localization.get_date()), width=terminal.get_size()[0]))
|
||||
|
||||
def output_footer():
|
||||
if __selected_format__ == "html" or __selected_format__ == "htmlembedded":
|
||||
|
|
|
@ -63,8 +63,8 @@ class Runner(object):
|
|||
os.chdir(self.repo)
|
||||
absolute_path = basedir.get_basedir_git()
|
||||
os.chdir(absolute_path)
|
||||
format.output_header()
|
||||
|
||||
format.output_header(absolute_path)
|
||||
changes = Changes(self.hard)
|
||||
outputable.output(ChangesOutput(changes))
|
||||
|
||||
|
|
Loading…
Reference in a new issue