mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-09-27 18:01:30 +02: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
@ -27,31 +27,28 @@ def get_basedir():
|
|||||||
else:
|
else:
|
||||||
return os.path.dirname(os.path.realpath(__file__))
|
return os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
__git_basedir__ = None
|
|
||||||
|
|
||||||
def get_basedir_git():
|
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__:
|
isbare = bare_command.stdout.readlines()
|
||||||
bare_command = subprocess.Popen(["git", "rev-parse", "--is-bare-repository"], bufsize=1,
|
bare_command.wait()
|
||||||
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
|
|
||||||
|
|
||||||
if isbare:
|
if bare_command.returncode != 0:
|
||||||
absolute_path = subprocess.Popen(["git", "rev-parse", "--git-dir"], bufsize=1, stdout=subprocess.PIPE).stdout
|
sys.exit(_("Error processing git repository at \"%s\"." % os.getcwd()))
|
||||||
else:
|
|
||||||
absolute_path = subprocess.Popen(["git", "rev-parse", "--show-toplevel"], bufsize=1,
|
|
||||||
stdout=subprocess.PIPE).stdout
|
|
||||||
|
|
||||||
absolute_path = absolute_path.readlines()
|
isbare = (isbare[0].decode("utf-8", "replace").strip() == "true")
|
||||||
if len(absolute_path) == 0:
|
absolute_path = None
|
||||||
sys.exit(_("Unable to determine absolute path of git repository."))
|
|
||||||
|
|
||||||
__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()
|
zip_file.close()
|
||||||
return content.decode("utf-8", "replace")
|
return content.decode("utf-8", "replace")
|
||||||
|
|
||||||
def output_header():
|
def output_header(repo):
|
||||||
if __selected_format__ == "html" or __selected_format__ == "htmlembedded":
|
if __selected_format__ == "html" or __selected_format__ == "htmlembedded":
|
||||||
base = basedir.get_basedir()
|
base = basedir.get_basedir()
|
||||||
html_header = __output_html_template__(base + "/html/html.header")
|
html_header = __output_html_template__(base + "/html/html.header")
|
||||||
@ -80,7 +80,7 @@ def output_header():
|
|||||||
else:
|
else:
|
||||||
jquery_js = " src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js\">"
|
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=jquery_js,
|
||||||
jquery_tablesorter=tablesorter_js,
|
jquery_tablesorter=tablesorter_js,
|
||||||
jquery_flot=flot_js,
|
jquery_flot=flot_js,
|
||||||
@ -92,7 +92,7 @@ def output_header():
|
|||||||
"<a href=\"https://github.com/ejwa/gitinspector\">gitinspector</a>",
|
"<a href=\"https://github.com/ejwa/gitinspector\">gitinspector</a>",
|
||||||
version.__version__),
|
version.__version__),
|
||||||
repo_text=_("Statistical information for the repository '{0}' was gathered on {1}.").format(
|
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"),
|
show_minor_authors=_("Show minor authors"),
|
||||||
hide_minor_authors=_("Hide minor authors"),
|
hide_minor_authors=_("Hide minor authors"),
|
||||||
show_minor_rows=_("Show rows with minor work"),
|
show_minor_rows=_("Show rows with minor work"),
|
||||||
@ -102,11 +102,11 @@ def output_header():
|
|||||||
elif __selected_format__ == "xml":
|
elif __selected_format__ == "xml":
|
||||||
print("<gitinspector>")
|
print("<gitinspector>")
|
||||||
print("\t<version>" + version.__version__ + "</version>")
|
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>")
|
print("\t<report-date>" + time.strftime("%Y/%m/%d") + "</report-date>")
|
||||||
else:
|
else:
|
||||||
print(textwrap.fill(_("Statistical information for the repository '{0}' was gathered on {1}.").format(
|
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():
|
def output_footer():
|
||||||
if __selected_format__ == "html" or __selected_format__ == "htmlembedded":
|
if __selected_format__ == "html" or __selected_format__ == "htmlembedded":
|
||||||
|
@ -63,8 +63,8 @@ class Runner(object):
|
|||||||
os.chdir(self.repo)
|
os.chdir(self.repo)
|
||||||
absolute_path = basedir.get_basedir_git()
|
absolute_path = basedir.get_basedir_git()
|
||||||
os.chdir(absolute_path)
|
os.chdir(absolute_path)
|
||||||
format.output_header()
|
|
||||||
|
|
||||||
|
format.output_header(absolute_path)
|
||||||
changes = Changes(self.hard)
|
changes = Changes(self.hard)
|
||||||
outputable.output(ChangesOutput(changes))
|
outputable.output(ChangesOutput(changes))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user