Unified code for finding source code location

It is already used in 3 places so I put it into a function
This commit is contained in:
mailchuck 2015-11-13 12:25:50 +01:00 committed by Peter Surda
parent ceda22ec94
commit 25cc1dc287
3 changed files with 13 additions and 16 deletions

View File

@ -67,13 +67,7 @@ def _translate(context, text):
def change_translation(locale):
global qtranslator
qtranslator = QtCore.QTranslator()
if shared.frozen == "macosx_app":
translationpath = os.environ.get("RESOURCEPATH")
elif shared.frozen: # windows
translationpath = sys._MEIPASS
else:
translationpath = os.path.dirname(os.path.dirname(__file__))
translationpath = os.path.join (translationpath, 'translations', 'bitmessage_' + locale)
translationpath = os.path.join (shared.codePath(), 'translations', 'bitmessage_' + locale)
qtranslator.load(translationpath)
QtGui.QApplication.installTranslator(qtranslator)

View File

@ -4,18 +4,12 @@
import hashlib
from struct import unpack, pack
import sys
from shared import config, frozen
from shared import config, frozen, codePath
import shared
import openclpow
import os
import ctypes
if frozen == "macosx_app":
curdir = os.environ.get("RESOURCEPATH")
elif frozen: # windows
curdir = sys._MEIPASS
else:
curdir = os.path.dirname(__file__)
bitmsglib = 'bitmsghash.so'
if "win32" == sys.platform:
if ctypes.sizeof(ctypes.c_voidp) == 4:
@ -23,12 +17,12 @@ if "win32" == sys.platform:
else:
bitmsglib = 'bitmsghash64.dll'
try:
bso = ctypes.WinDLL(os.path.join(curdir, "bitmsghash", bitmsglib))
bso = ctypes.WinDLL(os.path.join(codePath(), "bitmsghash", bitmsglib))
except:
bso = None
else:
try:
bso = ctypes.CDLL(os.path.join(curdir, "bitmsghash", bitmsglib))
bso = ctypes.CDLL(os.path.join(codePath(), "bitmsghash", bitmsglib))
except:
bso = None
if bso:

View File

@ -218,6 +218,15 @@ def lookupAppdataFolder():
dataFolder = dataFolder + '/'
return dataFolder
def codePath():
if frozen == "macosx_app":
codePath = os.environ.get("RESOURCEPATH")
elif frozen: # windows
codePath = sys._MEIPASS
else:
codePath = os.path.dirname(__file__)
return codePath
def isAddressInMyAddressBook(address):
queryreturn = sqlQuery(
'''select address from addressbook where address=?''',