From e841b4c94dcddbcf708a6b755c4e37ec46a22f56 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 1 Oct 2023 08:40:42 +0530 Subject: [PATCH] DRYer --- src/calibre/utils/ipc/launch.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/calibre/utils/ipc/launch.py b/src/calibre/utils/ipc/launch.py index ba81f92387..533bc7eba5 100644 --- a/src/calibre/utils/ipc/launch.py +++ b/src/calibre/utils/ipc/launch.py @@ -29,11 +29,21 @@ def renice(niceness): pass +def macos_viewer_bundle_path(): + base = os.path.dirname(sys.executables_location) + return os.path.join(base, 'ebook-viewer.app/Contents/MacOS/') + + def macos_edit_book_bundle_path(): base = os.path.dirname(sys.executables_location) return os.path.join(base, 'ebook-viewer.app/Contents/ebook-edit.app/Contents/MacOS/') +def macos_headless_bundle_path(): + base = os.path.dirname(sys.executables_location) + return os.path.join(base, 'ebook-viewer.app/Contents/ebook-edit.app/Contents/headless.app/Contents/MacOS/') + + def exe_path(exe_name): if hasattr(sys, 'running_from_setup'): return [sys.executable, os.path.join(sys.setup_dir, 'run-calibre-worker.py')] @@ -74,16 +84,14 @@ class Worker: @property def executable(self): if ismacos and not hasattr(sys, 'running_from_setup'): - base = os.path.dirname(sys.executables_location) - return os.path.join(base, 'ebook-viewer.app/Contents/ebook-edit.app/Contents/headless.app/Contents/MacOS', self.exe_name) + return os.path.join(macos_headless_bundle_path(), self.exe_name) return exe_path(self.exe_name) @property def gui_executable(self): if ismacos and not hasattr(sys, 'running_from_setup'): if self.job_name == 'ebook-viewer': - base = os.path.dirname(sys.executables_location) - return os.path.join(base, 'ebook-viewer.app/Contents/MacOS/', self.exe_name) + return os.path.join(macos_viewer_bundle_path(), self.exe_name) if self.job_name == 'ebook-edit': return os.path.join(macos_edit_book_bundle_path(), self.exe_name)