From b583589849030f03a75a2bece3e6408aa901db3f Mon Sep 17 00:00:00 2001 From: blitzman Date: Sun, 19 Feb 2017 00:59:10 -0500 Subject: [PATCH 1/2] Remove unicode path fixes for now to better test original problems --- config.py | 37 +++++++++++++++++++++++-------------- gui/bitmapLoader.py | 7 +++---- gui/graphFrame.py | 3 +-- gui/itemStats.py | 2 +- service/pycrest/eve.py | 2 +- service/settings.py | 4 ++-- 6 files changed, 31 insertions(+), 24 deletions(-) diff --git a/config.py b/config.py index 784e2cf54..199869b20 100644 --- a/config.py +++ b/config.py @@ -58,6 +58,13 @@ def __createDirs(path): os.makedirs(path) +def getPyfaRoot(): + base = getattr(sys.modules['__main__'], "__file__", sys.executable) if isFrozen() else sys.argv[0] + root = os.path.dirname(os.path.realpath(os.path.abspath(base))) + root = unicode(root, sys.getfilesystemencoding()) + return root + + def defPaths(customSavePath): global debug global pyfaPath @@ -75,32 +82,33 @@ def defPaths(customSavePath): # Python 2.X uses ANSI by default, so we need to convert the character encoding pyfaPath = getattr(configforced, "pyfaPath", pyfaPath) if pyfaPath is None: - pyfaPath = getPyfaPath() + pyfaPath = getPyfaRoot() # Where we store the saved fits etc, default is the current users home directory if saveInRoot is True: savePath = getattr(configforced, "savePath", None) if savePath is None: - savePath = getPyfaPath("saveddata") + savePath = os.path.join(pyfaPath, "saveddata") else: savePath = getattr(configforced, "savePath", None) if savePath is None: if customSavePath is None: # customSavePath is not overriden - savePath = os.path.expanduser(os.path.join("~", ".pyfa")) + savePath = unicode(os.path.expanduser(os.path.join("~", ".pyfa")), + sys.getfilesystemencoding()) else: savePath = customSavePath __createDirs(savePath) if isFrozen(): - certName = "cacert.pem" - os.environ["REQUESTS_CA_BUNDLE"] = getPyfaPath(certName).encode('utf8') - os.environ["SSL_CERT_FILE"] = getPyfaPath(certName).encode('utf8') + os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(pyfaPath, "cacert.pem") + os.environ["SSL_CERT_FILE"] = os.path.join(pyfaPath, "cacert.pem") - loggingFormat = '%(asctime)s %(name)-24s %(levelname)-8s %(message)s' - logging.basicConfig(format=loggingFormat, level=logLevel) - handler = logging.handlers.RotatingFileHandler(getSavePath("log.txt"), maxBytes=1000000, backupCount=3) - formatter = logging.Formatter(loggingFormat) + _format = '%(asctime)s %(name)-24s %(levelname)-8s %(message)s' + logging.basicConfig(format=_format, level=logLevel) + handler = logging.handlers.RotatingFileHandler(os.path.join(savePath, "log.txt"), maxBytes=1000000, + backupCount=3) + formatter = logging.Formatter(_format) handler.setFormatter(formatter) logging.getLogger('').addHandler(handler) @@ -117,14 +125,14 @@ def defPaths(customSavePath): # sys.stderr = sl # The database where we store all the fits etc - saveDB = getSavePath("saveddata.db") + saveDB = os.path.join(savePath, "saveddata.db") # The database where the static EVE data from the datadump is kept. # This is not the standard sqlite datadump but a modified version created by eos # maintenance script - gameDB = getPyfaPath("eve.db") + gameDB = os.path.join(pyfaPath, "eve.db") - # DON'T MODIFY ANYTHING BELOW! + ## DON'T MODIFY ANYTHING BELOW ## import eos.config # Caching modifiers, disable all gamedata caching, its unneeded. @@ -133,7 +141,7 @@ def defPaths(customSavePath): eos.config.saveddata_connectionstring = "sqlite:///" + saveDB + "?check_same_thread=False" eos.config.gamedata_connectionstring = "sqlite:///" + gameDB + "?check_same_thread=False" - +''' def getPyfaPath(Append=None): base = getattr(sys.modules['__main__'], "__file__", sys.executable) if isFrozen() else sys.argv[0] root = os.path.dirname(os.path.realpath(os.path.abspath(base))) @@ -170,3 +178,4 @@ def parsePath(root, Append=None): path = path.decode('windows-1252') return path +''' \ No newline at end of file diff --git a/gui/bitmapLoader.py b/gui/bitmapLoader.py index cb47e24bd..9a6639481 100644 --- a/gui/bitmapLoader.py +++ b/gui/bitmapLoader.py @@ -20,7 +20,6 @@ import cStringIO import os.path import zipfile -from config import parsePath # noinspection PyPackageRequirements import wx @@ -35,7 +34,7 @@ except ImportError: class BitmapLoader(object): try: - archive = zipfile.ZipFile(config.getPyfaPath('imgs.zip'), 'r') + archive = zipfile.ZipFile(os.path.join(config.pyfaPath, 'imgs.zip', 'r')) except IOError: archive = None @@ -78,7 +77,7 @@ class BitmapLoader(object): filename = "{0}.png".format(name) if cls.archive: - path = parsePath(location, filename) + path = os.path.join(location, filename) if os.sep != "/" and os.sep in path: path = path.replace(os.sep, "/") @@ -89,7 +88,7 @@ class BitmapLoader(object): except KeyError: print("Missing icon file from zip: {0}".format(path)) else: - path = config.getPyfaPath('imgs' + os.sep + location + os.sep + filename) + path = os.path.join(config.pyfaPath, 'imgs' + os.sep + location + os.sep + filename) if os.path.exists(path): return wx.Image(path) diff --git a/gui/graphFrame.py b/gui/graphFrame.py index 25e203371..44ed641bf 100644 --- a/gui/graphFrame.py +++ b/gui/graphFrame.py @@ -29,7 +29,6 @@ import gui.mainFrame import gui.globalEvents as GE from gui.graph import Graph from gui.bitmapLoader import BitmapLoader -from config import parsePath try: import matplotlib as mpl @@ -74,7 +73,7 @@ class GraphFrame(wx.Frame): except: cache_dir = os.path.expanduser(os.path.join("~", ".matplotlib")) - cache_file = parsePath(cache_dir, 'fontList.cache') + cache_file = path = os.path.join(cache_dir, 'fontList.cache') if os.access(cache_dir, os.W_OK | os.X_OK) and os.path.isfile(cache_file): # remove matplotlib font cache, see #234 diff --git a/gui/itemStats.py b/gui/itemStats.py index e305f1133..65fb3765e 100644 --- a/gui/itemStats.py +++ b/gui/itemStats.py @@ -849,7 +849,7 @@ class ItemEffects(wx.Panel): If effect file does not exist, create it """ - file_ = config.getPyfaPath(os.path.join("eos", "effects", "%s.py" % event.GetText().lower())) + file_ = os.path.join(config.pyfaPath, "eos", "effects", "%s.py" % event.GetText().lower()) if not os.path.isfile(file_): open(file_, 'a').close() diff --git a/service/pycrest/eve.py b/service/pycrest/eve.py index c96a10885..367c0e1f9 100644 --- a/service/pycrest/eve.py +++ b/service/pycrest/eve.py @@ -43,7 +43,7 @@ class FileCache(APICache): os.mkdir(self.path, 0o700) def _getpath(self, key): - return config.parsePath(self.path, str(hash(key)) + '.cache') + return os.path.join(self.path, str(hash(key)) + '.cache') def put(self, key, value): with open(self._getpath(key), 'wb') as f: diff --git a/service/settings.py b/service/settings.py index cf4b67b1e..d3f28e0a4 100644 --- a/service/settings.py +++ b/service/settings.py @@ -25,7 +25,7 @@ import config class SettingsProvider(object): - BASE_PATH = config.getSavePath("settings") + BASE_PATH = os.path.join(config.savePath, 'settings') settings = {} _instance = None @@ -44,7 +44,7 @@ class SettingsProvider(object): s = self.settings.get(area) if s is None: - p = config.parsePath(self.BASE_PATH, area) + p = os.path.join(self.BASE_PATH, area) if not os.path.exists(p): info = {} From 6e643d7579de8bcc5a112851197f615a837d6500 Mon Sep 17 00:00:00 2001 From: blitzman Date: Thu, 23 Feb 2017 23:53:57 -0500 Subject: [PATCH 2/2] Encode the SSL paths for frozen environments (to fix #548) --- config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 199869b20..2e857217d 100644 --- a/config.py +++ b/config.py @@ -101,8 +101,8 @@ def defPaths(customSavePath): __createDirs(savePath) if isFrozen(): - os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(pyfaPath, "cacert.pem") - os.environ["SSL_CERT_FILE"] = os.path.join(pyfaPath, "cacert.pem") + os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(pyfaPath, "cacert.pem").encode('utf8') + os.environ["SSL_CERT_FILE"] = os.path.join(pyfaPath, "cacert.pem").encode('utf8') _format = '%(asctime)s %(name)-24s %(levelname)-8s %(message)s' logging.basicConfig(format=_format, level=logLevel) @@ -141,6 +141,7 @@ def defPaths(customSavePath): eos.config.saveddata_connectionstring = "sqlite:///" + saveDB + "?check_same_thread=False" eos.config.gamedata_connectionstring = "sqlite:///" + gameDB + "?check_same_thread=False" +# Keeping disabled code here for now until we can determine with decent certainty that this isn't needed ''' def getPyfaPath(Append=None): base = getattr(sys.modules['__main__'], "__file__", sys.executable) if isFrozen() else sys.argv[0]