From c3ad473b3e9d6a050245b5bf3f14a3ed8520fed6 Mon Sep 17 00:00:00 2001 From: "Alan@int3ll3ct" Date: Sat, 8 Apr 2017 13:28:24 -0400 Subject: [PATCH] utils.py now misbehaving on Windows. Changed to include os dependency in execution to support Linux, reverted to 1.2.0a9 code for Windows/Mac. --- openroast/utils.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/openroast/utils.py b/openroast/utils.py index 44dfeb3..6e3e799 100644 --- a/openroast/utils.py +++ b/openroast/utils.py @@ -8,17 +8,28 @@ def get_resource_filename(resname): but tries to avoid loading pkg_resources unless we're actually in an egg. """ - # Commented out the below, as it prevents a 'py3.5 -mpip install -e .' - # from working properly in Linux. - # path = os.path.dirname(os.path.abspath(__file__)) - # path = os.path.join(path,resname) - # if os.path.exists(path): - # return path + # for a Linux source install, just force the use of pkg_resources + if sys.platform == "linux" or sys.platform == "linux2": + # linux + import pkg_resources + try: + path = pkg_resources.resource_filename("openroast",resname) + except KeyError: + pass + else: + path = os.path.abspath(path) + if os.path.exists(path): + return path + raise IOError( + "get_resource_filename - Could not locate resource '%s'" % (resname,)) + + # the Mac and Windows versions actually execute the following 4 lines. + # For Windows, pynsist does not 'freeze' the app, there is no "frozen" attr. + path = os.path.dirname(os.path.abspath(__file__)) + path = os.path.join(path,resname) + if os.path.exists(path): + return path if hasattr(sys, "frozen"): - path = os.path.dirname(os.path.abspath(__file__)) - path = os.path.join(path,resname) - if os.path.exists(path): - return path exe_path = sys.executable if not isinstance(exe_path, str): exe_path = str(exe_path,sys.getfilesystemencoding())