From 929bd8268499a467d99effca5325d2ba9e36a8e2 Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Sat, 19 Aug 2017 15:43:06 +0100 Subject: [PATCH] Allow executable and plugins to be run from non-ASCII paths Fixes #234 --- config.py | 8 ++++---- l10n.py | 4 ++-- plug.py | 4 ++-- update.py | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/config.py b/config.py index d4abbedd..eb59d359 100644 --- a/config.py +++ b/config.py @@ -123,7 +123,7 @@ class Config: if not isdir(self.plugin_dir): mkdir(self.plugin_dir) - self.internal_plugin_dir = getattr(sys, 'frozen', False) and normpath(join(dirname(sys.executable), pardir, 'Library', 'plugins')) or join(dirname(__file__), 'plugins') + self.internal_plugin_dir = getattr(sys, 'frozen', False) and normpath(join(dirname(sys.executable.decode(sys.getfilesystemencoding())), pardir, 'Library', 'plugins')) or join(dirname(__file__), 'plugins') self.default_journal_dir = join(NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], 'Frontier Developments', 'Elite Dangerous') @@ -131,7 +131,7 @@ class Config: self.home = expanduser('~') - self.respath = getattr(sys, 'frozen', False) and normpath(join(dirname(sys.executable), pardir, 'Resources')) or dirname(__file__) + self.respath = getattr(sys, 'frozen', False) and normpath(join(dirname(sys.executable.decode(sys.getfilesystemencoding())), pardir, 'Resources')) or dirname(__file__) if not getattr(sys, 'frozen', False): # Don't use Python's settings if interactive @@ -185,7 +185,7 @@ class Config: if not isdir(self.plugin_dir): mkdir(self.plugin_dir) - self.internal_plugin_dir = join(dirname(getattr(sys, 'frozen', False) and sys.executable or __file__), 'plugins') + self.internal_plugin_dir = join(dirname(getattr(sys, 'frozen', False) and sys.executable.decode(sys.getfilesystemencoding()) or __file__), u'plugins') # expanduser in Python 2 on Windows doesn't handle non-ASCII - http://bugs.python.org/issue13207 self.home = KnownFolderPath(FOLDERID_Profile) or u'\\' @@ -195,7 +195,7 @@ class Config: self.default_interaction_dir = join(KnownFolderPath(FOLDERID_LocalAppData), 'Frontier Developments', 'Elite Dangerous', 'CommanderHistory') - self.respath = dirname(getattr(sys, 'frozen', False) and sys.executable or __file__) + self.respath = dirname(getattr(sys, 'frozen', False) and sys.executable.decode(sys.getfilesystemencoding()) or __file__) self.identifier = applongname diff --git a/l10n.py b/l10n.py index c988007f..ee4d7177 100755 --- a/l10n.py +++ b/l10n.py @@ -127,9 +127,9 @@ class Translations: def respath(self): if getattr(sys, 'frozen', False): if platform=='darwin': - return normpath(join(dirname(sys.executable), os.pardir, 'Resources')) + return normpath(join(dirname(sys.executable.decode(sys.getfilesystemencoding())), os.pardir, 'Resources')) else: - return join(dirname(sys.executable), 'L10n') + return join(dirname(sys.executable.decode(sys.getfilesystemencoding())), 'L10n') elif __file__: return join(dirname(__file__), 'L10n') else: diff --git a/plug.py b/plug.py index d4f6ada6..224b089b 100644 --- a/plug.py +++ b/plug.py @@ -39,9 +39,9 @@ class Plugin(object): self.module = None # None for disabled plugins. if loadfile: - sys.stdout.write('loading plugin %s from "%s"\n' % (name, loadfile.encode('utf-8'))) + sys.stdout.write(('loading plugin %s from "%s"\n' % (name, loadfile)).encode('utf-8')) with open(loadfile, 'rb') as plugfile: - module = imp.load_module('plugin_%s' % name, plugfile, loadfile.encode(sys.getfilesystemencoding()), + module = imp.load_module('plugin_%s' % name.encode('ascii', 'replace'), plugfile, loadfile.encode(sys.getfilesystemencoding()), ('.py', 'r', imp.PY_SOURCE)) newname = module.plugin_start() self.name = newname and unicode(newname) or name diff --git a/update.py b/update.py index 60b08c67..1cbf187a 100644 --- a/update.py +++ b/update.py @@ -50,7 +50,7 @@ elif sys.platform=='darwin': def __init__(self, master): try: - objc.loadBundle('Sparkle', globals(), join(dirname(sys.executable), os.pardir, 'Frameworks', 'Sparkle.framework')) + objc.loadBundle('Sparkle', globals(), join(dirname(sys.executable.decode(sys.getfilesystemencoding())), os.pardir, 'Frameworks', 'Sparkle.framework')) self.updater = SUUpdater.sharedUpdater() except: # can't load framework - not frozen or not included in app bundle?