mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-21 19:37:39 +03:00
Consolidate handling of data resource path.
This commit is contained in:
parent
4d37889bbd
commit
2cd52e8377
10
config.py
10
config.py
@ -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))
|
||||
|
17
eddb.py
17
eddb.py
@ -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__":
|
||||
|
21
hotkey.py
21
hotkey.py
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user