Consolidate handling of data resource path.

This commit is contained in:
Jonathan Harris committed 2016-01-22 04:59:31 +00:00
1 parent 87cf3d707e
commit f685cecc85
4 files changed
+16 -33

No files matched your search

+8 -2
View File
@@ -1,6 +1,6 @@
import sys
from os import getenv, makedirs, mkdir
from os.path import expanduser, dirname, isdir, join
from os import getenv, makedirs, mkdir, pardir
from os.path import expanduser, dirname, isdir, join, normpath
from sys import platform
@@ -94,6 +94,8 @@ class Config:
self.home = expanduser('~')
self.respath = getattr(sys, 'frozen', False) and normpath(join(dirname(sys.executable), pardir, 'Resources')) or dirname(__file__)
if not getattr(sys, 'frozen', False):
# Don't use Python's settings if interactive
self.bundle = 'uk.org.marginal.%s' % appname.lower()
@@ -145,6 +147,8 @@ class Config:
ctypes.windll.shell32.SHGetSpecialFolderPathW(0, buf, CSIDL_PROFILE, 0)
self.home = buf.value
self.respath = dirname(getattr(sys, 'frozen', False) and sys.executable or __file__)
self.hkey = HKEY()
disposition = DWORD()
if RegCreateKeyEx(HKEY_CURRENT_USER, r'Software\Marginal\EDMarketConnector', 0, None, 0, KEY_ALL_ACCESS, None, ctypes.byref(self.hkey), ctypes.byref(disposition)):
@@ -225,6 +229,8 @@ class Config:
self.home = expanduser('~')
self.respath = dirname(__file__)
self.filename = join(getenv('XDG_CONFIG_HOME', expanduser('~/.config')), appname, '%s.ini' % appname)
if not isdir(dirname(self.filename)):
makedirs(dirname(self.filename))
+4 -13
View File
@@ -9,6 +9,8 @@ from os.path import dirname, join, normpath
import sys
from sys import platform
from config import config
class EDDB:
HAS_MARKET = 1
@@ -16,8 +18,8 @@ class EDDB:
HAS_SHIPYARD = 4
def __init__(self):
self.system_ids = cPickle.load(open(join(self.respath(), 'systems.p'), 'rb'))
self.station_ids = cPickle.load(open(join(self.respath(), 'stations.p'), 'rb'))
self.system_ids = cPickle.load(open(join(config.respath, 'systems.p'), 'rb'))
self.station_ids = cPickle.load(open(join(config.respath, 'stations.p'), 'rb'))
# system_name -> system_id or 0
def system(self, system_name):
@@ -28,17 +30,6 @@ class EDDB:
(station_id, flags) = self.station_ids.get((self.system_ids.get(system_name), station_name), (0,0))
return (station_id, bool(flags & EDDB.HAS_MARKET), bool(flags & EDDB.HAS_OUTFITTING), bool(flags & EDDB.HAS_SHIPYARD))
def respath(self):
if getattr(sys, 'frozen', False):
if platform=='darwin':
return normpath(join(dirname(sys.executable), os.pardir, 'Resources'))
else:
return dirname(sys.executable)
elif __file__:
return dirname(__file__)
else:
return '.'
# build system & station database from files systems.json and stations.json from http://eddb.io/api
if __name__ == "__main__":
+4 -17
View File
@@ -42,14 +42,8 @@ if platform == 'darwin':
self.tkProcessKeyEvent_old = None
if getattr(sys, 'frozen', False):
respath = normpath(join(dirname(sys.executable), os.pardir, 'Resources'))
elif __file__:
respath = dirname(__file__)
else:
respath = '.'
self.snd_good = NSSound.alloc().initWithContentsOfFile_byReference_(join(respath, 'snd_good.wav'), False)
self.snd_bad = NSSound.alloc().initWithContentsOfFile_byReference_(join(respath, 'snd_bad.wav'), False)
self.snd_good = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath, 'snd_good.wav'), False)
self.snd_bad = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath, 'snd_bad.wav'), False)
def register(self, root, keycode, modifiers):
self.root = root
@@ -289,15 +283,8 @@ elif platform == 'win32':
def __init__(self):
self.root = None
self.thread = None
if getattr(sys, 'frozen', False):
respath = dirname(sys.executable)
elif __file__:
respath = dirname(__file__)
else:
respath = '.'
self.snd_good = open(join(respath, 'snd_good.wav'), 'rb').read()
self.snd_bad = open(join(respath, 'snd_bad.wav'), 'rb').read()
self.snd_good = open(join(config.respath, 'snd_good.wav'), 'rb').read()
self.snd_bad = open(join(config.respath, 'snd_bad.wav'), 'rb').read()
def register(self, root, keycode, modifiers):
self.root = root
-1
View File
@@ -24,7 +24,6 @@ class Translations:
__builtin__.__dict__['_'] = lambda x: unicode(x).replace(u'{CR}', u'\n') # Promote strings to Unicode for consistency
def install(self):
path = join(self.respath(), 'L10n')
available = self.available()
available.add(Translations.FALLBACK)