From 3bd987ffcf7809e9b52410e32dcf9c73d7e33588 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Sun, 23 Aug 2015 20:53:43 -0400 Subject: [PATCH] Show PyInstaller DEBUG output when run with verbose option. Use debug bootloader when building devel version. Add ssl hook and runtime hook to include certificates for Mac OS X(OS X). Fix release app version(OS X). Fix converting bytes to megabytes(OS X). Fix argument to cp command(OS X). --- osx/macosx-builder.py | 42 ++++++++++++++++++++------------- pyinstaller-hooks/hook-ssl.py | 10 ++++++++ pyinstaller-hooks/rthook_ssl.py | 5 ++++ windows/windows-builder.py | 33 ++++++++++++++++---------- 4 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 pyinstaller-hooks/hook-ssl.py create mode 100644 pyinstaller-hooks/rthook_ssl.py diff --git a/osx/macosx-builder.py b/osx/macosx-builder.py index 92a9916..652baaf 100644 --- a/osx/macosx-builder.py +++ b/osx/macosx-builder.py @@ -322,20 +322,25 @@ class MacosxBuilder(object): """ self._print('Running PyInstaller...') os.chdir(self.work_path) - pyinstaller = Popen((self.python, - self.pyinstaller, - '--noconfirm', - '--windowed', - '--noupx', - '--additional-hooks-dir', self.hooks_path, - '--runtime-hook', os.path.join(self.hooks_path, 'rthook_openlp_pyqt4.py'), - '--log-level=ERROR', - # '--distpath', self.branch_path, - # '-i', self.mac_icon, - '-p', self.work_path, - '-n', 'OpenLP', - self.openlp_script), - stdout=PIPE) + cmd = [self.python, + self.pyinstaller, + '--clean', + '--noconfirm', + '--windowed', + '--noupx', + '--additional-hooks-dir', self.hooks_path, + '--runtime-hook', os.path.join(self.hooks_path, 'rthook_openlp_pyqt4.py'), + '-i', self.mac_icon, + '-p', self.work_path, + '-n', 'OpenLP', + self.openlp_script] + if not self.args.verbose: + cmd.append('--log-level=ERROR') + else: + cmd.append('--log-level=DEBUG') + if self.args.devel: + cmd.append('-d') + pyinstaller = Popen(cmd, stdout=PIPE) output = pyinstaller.communicate()[0] code = pyinstaller.wait() if code != 0: @@ -433,7 +438,10 @@ class MacosxBuilder(object): fr = open(self.bundle_info, 'r') fw = open(os.path.join(self.dist_app_path, 'Contents', os.path.basename(self.bundle_info)), 'w') text = fr.read() - text = text % {'openlp_version': self.version_string} + if self.args.devel: + text = text % {'openlp_version': self.version_string} + else: + text = text % {'openlp_version': self.version_tag} fw.write(text) fr.close() fw.close() @@ -584,7 +592,7 @@ class MacosxBuilder(object): os.remove(dmg_file) # Create empty dmg file. size = self._get_directory_size(self.dist_app_path) # in bytes. - size = size / (1024 * 1024) # Convert to megabytes. + size = size / (1000 * 1000) # Convert to megabytes. size += 10 # Additional space in .dmg for other files. self._print('... dmg disk size: %s' % size) self._run_command([self.hdiutil, 'create', dmg_file, '-ov', '-megabytes', str(size), '-fs', 'HFS+', '-volname', @@ -602,7 +610,7 @@ class MacosxBuilder(object): # Copy OpenLP.app and other files to .dmg # TODO more reliable way to determine dmg_volume_path self._print('... Copying the app to the dmg: ' + dmg_volume_path) - self._run_command(['cp', '-r', self.dist_app_path, dmg_volume_path], + self._run_command(['cp', '-R', self.dist_app_path, dmg_volume_path], 'Could not copy app bundle, dmg creation failed.') # Set icon for dmg file. diff --git a/pyinstaller-hooks/hook-ssl.py b/pyinstaller-hooks/hook-ssl.py new file mode 100644 index 0000000..29aa55e --- /dev/null +++ b/pyinstaller-hooks/hook-ssl.py @@ -0,0 +1,10 @@ +from PyInstaller.compat import is_darwin +from PyInstaller.utils.hooks.hookutils import exec_statement + +if is_darwin: # TODO check if this is needed on linux + datas = [] + files = exec_statement(""" +import ssl +print(ssl.get_default_verify_paths().cafile)""").strip().split() + for file in files: + datas.append((file, 'lib')) # TODO find a way to make sure the bundled cafile is always named 'cert.pem' diff --git a/pyinstaller-hooks/rthook_ssl.py b/pyinstaller-hooks/rthook_ssl.py new file mode 100644 index 0000000..db0e3e5 --- /dev/null +++ b/pyinstaller-hooks/rthook_ssl.py @@ -0,0 +1,5 @@ +import os +import sys + +if sys.platform == 'darwin': # TODO check if this is needed on linux + os.environ['SSL_CERT_FILE'] = os.path.join(sys._MEIPASS, 'lib', 'cert.pem') diff --git a/windows/windows-builder.py b/windows/windows-builder.py index b16809b..6f8ef75 100644 --- a/windows/windows-builder.py +++ b/windows/windows-builder.py @@ -289,19 +289,26 @@ class WindowsBuilder(object): """ self._print('Running PyInstaller...') os.chdir(self.branch_path) - pyinstaller = Popen((self.python, self.pyinstaller, - '--noconfirm', - '--windowed', - '--noupx', - '--additional-hooks-dir', self.hooks_path, - '--runtime-hook', os.path.join(self.hooks_path, 'rthook_openlp_pyqt4.py'), - '--log-level=DEBUG', - '--distpath', self.dist_path_pyinst_arg, - '-i', self.win32_icon, - '-p', self.branch_path, - '-n', 'OpenLP', - self.openlp_script), - stdout=PIPE) + cmd = [self.python, + self.pyinstaller, + '--clean', + '--noconfirm', + '--windowed', + '--noupx', + '--additional-hooks-dir', self.hooks_path, + '--runtime-hook', os.path.join(self.hooks_path, 'rthook_openlp_pyqt4.py'), + '--distpath', self.dist_path_pyinst_arg, + '-i', self.win32_icon, + '-p', self.branch_path, + '-n', 'OpenLP', + self.openlp_script] + if not self.args.verbose: + cmd.append('--log-level=ERROR') + else: + cmd.append('--log-level=DEBUG') + if self.args.devel: + cmd.append('-d') + pyinstaller = Popen(cmd, stdout=PIPE) output = pyinstaller.communicate()[0] code = pyinstaller.wait() if code != 0: