Properly handle resource loading and sys.frozen.
This commit is contained in:
parent
c0c40a7680
commit
6b6666c618
|
@ -1,11 +1,21 @@
|
|||
from qtpy import uic
|
||||
import os.path
|
||||
import paths
|
||||
import os
|
||||
from io import BytesIO
|
||||
|
||||
from qtpy import QtCore, uic
|
||||
|
||||
from pybitmessage import paths
|
||||
|
||||
|
||||
def resource_path(resFile):
|
||||
baseDir = paths.codePath()
|
||||
for subDir in ("ui", "bitmessageqt"):
|
||||
if baseDir is None: # pyqtdeploy bundle
|
||||
resFile = QtCore.QFile(
|
||||
':/pybitmessage/bitmessageqt/{}'.format(resFile))
|
||||
resFile.open(QtCore.QIODevice.ReadOnly)
|
||||
data = resFile.readAll()
|
||||
resFile.close()
|
||||
return BytesIO(bytes(data))
|
||||
for subDir in ('bitmessageqt', 'ui'):
|
||||
path = os.path.join(baseDir, subDir, resFile)
|
||||
if os.path.isfile(path):
|
||||
return path
|
||||
|
|
|
@ -7,10 +7,11 @@ import socket
|
|||
import ssl
|
||||
import sys
|
||||
|
||||
import network.asyncore_pollchoose as asyncore
|
||||
import paths
|
||||
from network.advanceddispatcher import AdvancedDispatcher
|
||||
from queues import receiveDataQueue
|
||||
import asyncore_pollchoose as asyncore
|
||||
from pybitmessage import paths
|
||||
from pybitmessage.queues import receiveDataQueue
|
||||
from advanceddispatcher import AdvancedDispatcher
|
||||
|
||||
|
||||
logger = logging.getLogger('default')
|
||||
|
||||
|
@ -47,14 +48,15 @@ class TLSDispatcher(AdvancedDispatcher):
|
|||
def __init__(self, _=None, sock=None, certfile=None, keyfile=None,
|
||||
server_side=False, ciphers=sslProtocolCiphers):
|
||||
self.want_read = self.want_write = True
|
||||
if certfile is None:
|
||||
code_path = paths.codePath()
|
||||
if certfile is None and code_path:
|
||||
self.certfile = os.path.join(
|
||||
paths.codePath(), 'sslkeys', 'cert.pem')
|
||||
code_path, 'sslkeys', 'cert.pem')
|
||||
else:
|
||||
self.certfile = certfile
|
||||
if keyfile is None:
|
||||
if keyfile is None and code_path:
|
||||
self.keyfile = os.path.join(
|
||||
paths.codePath(), 'sslkeys', 'key.pem')
|
||||
code_path, 'sslkeys', 'key.pem')
|
||||
else:
|
||||
self.keyfile = keyfile
|
||||
self.server_side = server_side
|
||||
|
|
11
src/paths.py
11
src/paths.py
|
@ -76,10 +76,13 @@ def codePath():
|
|||
"""Returns path to the program sources"""
|
||||
if not frozen:
|
||||
return os.path.dirname(__file__)
|
||||
return (
|
||||
os.environ.get('RESOURCEPATH')
|
||||
# pylint: disable=protected-access
|
||||
if frozen == "macosx_app" else sys._MEIPASS)
|
||||
if frozen == "macosx_app":
|
||||
return os.getenv('RESOURCEPATH')
|
||||
else:
|
||||
try: # pylint: disable=protected-access
|
||||
return sys._MEIPASS
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
|
||||
def tail(f, lines=20):
|
||||
|
|
|
@ -758,6 +758,8 @@ def loadOpenSSL():
|
|||
environ['RESOURCEPATH'], '..',
|
||||
'Frameworks', 'libcrypto.0.9.8.dylib'),
|
||||
])
|
||||
elif not getattr(sys, '_MEIPASS', None):
|
||||
pass
|
||||
elif 'win32' in sys.platform or 'win64' in sys.platform:
|
||||
libdir.append(path.join(sys._MEIPASS, 'libeay32.dll'))
|
||||
else:
|
||||
|
|
Reference in New Issue
Block a user