gitinspector can now be executed from another directory again.

This was broken when the loading of external resources for the HTML output
was added.

This fix should also improve compatibility with py2exe.
This commit is contained in:
Adam Waldenberg 2012-11-13 11:27:56 +01:00
parent 6ee7ad71ab
commit 527d47ecae
2 changed files with 32 additions and 3 deletions

27
basedir.py Normal file
View File

@ -0,0 +1,27 @@
# coding: utf-8
#
# Copyright © 2012 Ejwa Software. All rights reserved.
#
# This file is part of gitinspector.
#
# gitinspector is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# gitinspector is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
def get_basedir():
if hasattr(sys,'frozen'): # exists when running via py2exe
return sys.prefix
else:
return os.path.dirname(os.path.realpath(__file__))

View File

@ -19,6 +19,7 @@
from __future__ import print_function
import base64
import basedir
import os
import terminal
import version
@ -47,18 +48,19 @@ def __output_html_template__(name):
return file_r.read().decode("utf-8", "replace")
def __get_zip_file_content__(name):
zip_file = zipfile.ZipFile("html/flot.zip", "r")
zip_file = zipfile.ZipFile(basedir.get_basedir() + "/html/flot.zip", "r")
content = zip_file.read(name)
zip_file.close()
return content
def output_header():
if __selected_format__ == "html":
html_header = __output_html_template__("html/html.header")
base = basedir.get_basedir();
html_header = __output_html_template__(base + "/html/html.header")
jquery_js = __get_zip_file_content__("jquery.js")
flot_js = __get_zip_file_content__("jquery.flot.js")
logo_file = open("html/gitinspector_piclet.png", "rb")
logo_file = open(base + "/html/gitinspector_piclet.png", "rb")
logo = logo_file.read()
logo_file.close()
logo = base64.b64encode(logo)