From 3fff4da652dd242fbdeb52c8d5676043c02df7c4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 20 Sep 2010 21:32:29 -0600 Subject: [PATCH] Infrastructure changes to launch pyconsole interpreter process --- src/calibre/utils/ipc/launch.py | 21 ++++++++++++--------- src/calibre/utils/ipc/worker.py | 4 ++++ src/calibre/utils/pyconsole/console.py | 1 + 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/calibre/utils/ipc/launch.py b/src/calibre/utils/ipc/launch.py index 0de81ed644..aa93469119 100644 --- a/src/calibre/utils/ipc/launch.py +++ b/src/calibre/utils/ipc/launch.py @@ -22,13 +22,15 @@ class Worker(object): have the environment variable :envvar:`CALIBRE_WORKER` set. Useful attributes: ``is_alive``, ``returncode`` - usefule methods: ``kill`` + Useful methods: ``kill`` To launch child simply call the Worker object. By default, the child's output is redirected to an on disk file, the path to which is returned by the call. ''' + exe_name = 'calibre-parallel' + @property def osx_interpreter(self): exe = os.path.basename(sys.executable) @@ -41,32 +43,33 @@ class Worker(object): @property def executable(self): + e = self.exe_name if iswindows: return os.path.join(os.path.dirname(sys.executable), - 'calibre-parallel.exe' if isfrozen else \ - 'Scripts\\calibre-parallel.exe') + e+'.exe' if isfrozen else \ + 'Scripts\\%s.exe'%e) if isnewosx: - return os.path.join(sys.console_binaries_path, 'calibre-parallel') + return os.path.join(sys.console_binaries_path, e) if isosx: - if not isfrozen: return 'calibre-parallel' + if not isfrozen: return e contents = os.path.join(self.osx_contents_dir, 'console.app', 'Contents') return os.path.join(contents, 'MacOS', self.osx_interpreter) if isfrozen: - return os.path.join(getattr(sys, 'frozen_path'), 'calibre-parallel') + return os.path.join(getattr(sys, 'frozen_path'), e) - c = os.path.join(sys.executables_location, 'calibre-parallel') + c = os.path.join(sys.executables_location, e) if os.access(c, os.X_OK): return c - return 'calibre-parallel' + return e @property def gui_executable(self): if isnewosx: - return os.path.join(sys.binaries_path, 'calibre-parallel') + return os.path.join(sys.binaries_path, self.exe_name) if isfrozen and isosx: return os.path.join(self.osx_contents_dir, diff --git a/src/calibre/utils/ipc/worker.py b/src/calibre/utils/ipc/worker.py index 73233840fe..b7510426aa 100644 --- a/src/calibre/utils/ipc/worker.py +++ b/src/calibre/utils/ipc/worker.py @@ -80,8 +80,12 @@ def main(): if isosx and 'CALIBRE_WORKER_ADDRESS' not in os.environ: # On some OS X computers launchd apparently tries to # launch the last run process from the bundle + # so launch the gui as usual from calibre.gui2.main import main as gui_main return gui_main(['calibre']) + if 'CALIBRE_LAUNCH_INTERPRETER' in os.environ: + from calibre.utils.pyconsole.interpreter import main + return main() address = cPickle.loads(unhexlify(os.environ['CALIBRE_WORKER_ADDRESS'])) key = unhexlify(os.environ['CALIBRE_WORKER_KEY']) resultf = unhexlify(os.environ['CALIBRE_WORKER_RESULT']) diff --git a/src/calibre/utils/pyconsole/console.py b/src/calibre/utils/pyconsole/console.py index 251e8424a0..f741562f03 100644 --- a/src/calibre/utils/pyconsole/console.py +++ b/src/calibre/utils/pyconsole/console.py @@ -47,6 +47,7 @@ class Prepender(object): # {{{ self.console.cursor_pos = self.opos # }}} + class Console(QTextEdit): running = pyqtSignal()