From 25cc1dc287272bc0f2ce970f49621ca45bcaf18a Mon Sep 17 00:00:00 2001 From: mailchuck Date: Fri, 13 Nov 2015 12:25:50 +0100 Subject: [PATCH] Unified code for finding source code location It is already used in 3 places so I put it into a function --- src/bitmessageqt/__init__.py | 8 +------- src/proofofwork.py | 12 +++--------- src/shared.py | 9 +++++++++ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 7c579918..8cd8cbda 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -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) diff --git a/src/proofofwork.py b/src/proofofwork.py index 04e07af3..fc779467 100644 --- a/src/proofofwork.py +++ b/src/proofofwork.py @@ -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: diff --git a/src/shared.py b/src/shared.py index 92868a3c..4877ce13 100644 --- a/src/shared.py +++ b/src/shared.py @@ -217,6 +217,15 @@ def lookupAppdataFolder(): pass 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(