Properly handle resource loading and sys.frozen.

This commit is contained in:
Dmitri Bogomolov 2020-07-10 18:56:23 +03:00
parent c0c40a7680
commit 6b6666c618
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
4 changed files with 33 additions and 16 deletions

View File

@ -1,11 +1,21 @@
from qtpy import uic import os
import os.path from io import BytesIO
import paths
from qtpy import QtCore, uic
from pybitmessage import paths
def resource_path(resFile): def resource_path(resFile):
baseDir = paths.codePath() 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) path = os.path.join(baseDir, subDir, resFile)
if os.path.isfile(path): if os.path.isfile(path):
return path return path

View File

@ -7,10 +7,11 @@ import socket
import ssl import ssl
import sys import sys
import network.asyncore_pollchoose as asyncore import asyncore_pollchoose as asyncore
import paths from pybitmessage import paths
from network.advanceddispatcher import AdvancedDispatcher from pybitmessage.queues import receiveDataQueue
from queues import receiveDataQueue from advanceddispatcher import AdvancedDispatcher
logger = logging.getLogger('default') logger = logging.getLogger('default')
@ -47,14 +48,15 @@ class TLSDispatcher(AdvancedDispatcher):
def __init__(self, _=None, sock=None, certfile=None, keyfile=None, def __init__(self, _=None, sock=None, certfile=None, keyfile=None,
server_side=False, ciphers=sslProtocolCiphers): server_side=False, ciphers=sslProtocolCiphers):
self.want_read = self.want_write = True 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( self.certfile = os.path.join(
paths.codePath(), 'sslkeys', 'cert.pem') code_path, 'sslkeys', 'cert.pem')
else: else:
self.certfile = certfile self.certfile = certfile
if keyfile is None: if keyfile is None and code_path:
self.keyfile = os.path.join( self.keyfile = os.path.join(
paths.codePath(), 'sslkeys', 'key.pem') code_path, 'sslkeys', 'key.pem')
else: else:
self.keyfile = keyfile self.keyfile = keyfile
self.server_side = server_side self.server_side = server_side

View File

@ -76,10 +76,13 @@ def codePath():
"""Returns path to the program sources""" """Returns path to the program sources"""
if not frozen: if not frozen:
return os.path.dirname(__file__) return os.path.dirname(__file__)
return ( if frozen == "macosx_app":
os.environ.get('RESOURCEPATH') return os.getenv('RESOURCEPATH')
# pylint: disable=protected-access else:
if frozen == "macosx_app" else sys._MEIPASS) try: # pylint: disable=protected-access
return sys._MEIPASS
except AttributeError:
return None
def tail(f, lines=20): def tail(f, lines=20):

View File

@ -758,6 +758,8 @@ def loadOpenSSL():
environ['RESOURCEPATH'], '..', environ['RESOURCEPATH'], '..',
'Frameworks', 'libcrypto.0.9.8.dylib'), 'Frameworks', 'libcrypto.0.9.8.dylib'),
]) ])
elif not getattr(sys, '_MEIPASS', None):
pass
elif 'win32' in sys.platform or 'win64' in sys.platform: elif 'win32' in sys.platform or 'win64' in sys.platform:
libdir.append(path.join(sys._MEIPASS, 'libeay32.dll')) libdir.append(path.join(sys._MEIPASS, 'libeay32.dll'))
else: else: