From 61005add0dbe4d5e028be4b6c8f271117d22dfb9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 13 Sep 2019 10:28:26 +0530 Subject: [PATCH] Add support for run-local to calibre restart and run_calibre_debug --- setup/installers.py | 2 +- src/calibre/debug.py | 20 ++++++++++++++------ src/calibre/gui2/main.py | 14 +++++++++++--- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/setup/installers.py b/setup/installers.py index 0e0b8d65d5..30778e6353 100644 --- a/setup/installers.py +++ b/setup/installers.py @@ -233,7 +233,7 @@ class ExtDev(Command): 'import sys, json, binascii, os, subprocess; cmd = json.loads(binascii.unhexlify(sys.argv[-1]));' 'env = os.environ.copy();' '''env[str('CALIBRE_DEVELOP_FROM')] = str(os.path.abspath('calibre-src/src'));''' - 'from calibre.debug import get_debug_executable; exe_dir = os.path.dirname(get_debug_executable());' + 'from calibre.debug import get_debug_executable; exe_dir = os.path.dirname(get_debug_executable()[0]);' 'cmd[0] = os.path.join(exe_dir, cmd[0]); ret = subprocess.Popen(cmd, env=env).wait();' 'sys.stdout.flush(); sys.stderr.flush(); sys.exit(ret)' '"', enc] diff --git a/src/calibre/debug.py b/src/calibre/debug.py index 594b332b61..59a51c7124 100644 --- a/src/calibre/debug.py +++ b/src/calibre/debug.py @@ -15,12 +15,21 @@ from polyglot.builtins import exec_path, raw_input, unicode_type, getcwd def get_debug_executable(): + exe_name = 'calibre-debug' + ('.exe' if iswindows else '') if hasattr(sys, 'frameworks_dir'): base = os.path.dirname(sys.frameworks_dir) - return os.path.join(base, 'MacOS', 'calibre-debug') - if getattr(sys, 'frozen', False): - return os.path.join(os.path.dirname(os.path.abspath(sys.executable)), 'calibre-debug' + ('.exe' if iswindows else '')) - return 'calibre-debug' + return [os.path.join(base, 'MacOS', exe_name)] + if getattr(sys, 'run_local', None): + return [sys.run_local, exe_name] + nearby = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), exe_name) + if getattr(sys, 'frozen', False) or os.path.exists(nearby): + return [nearby] + exloc = getattr(sys, 'executables_location', None) + if exloc: + ans = os.path.join(exloc, exe_name) + if os.path.exists(ans): + return ans + return exe_name def run_calibre_debug(*args, **kw): @@ -29,8 +38,7 @@ def run_calibre_debug(*args, **kw): if iswindows: import win32process creationflags = win32process.CREATE_NO_WINDOW - exe = get_debug_executable() - cmd = [exe] + list(args) + cmd = get_debug_executable() + list(args) kw['creationflags'] = creationflags return subprocess.Popen(cmd, **kw) diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 9e95a3b76a..3cb2202ccb 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -406,9 +406,17 @@ def run_gui(opts, args, listener, app, gui_debug=None): os.environ['CALIBRE_RESTARTING_FROM_GUI'] = environ_item('1') if iswindows and hasattr(winutil, 'prepare_for_restart'): winutil.prepare_for_restart() - args = ['-g'] if os.path.splitext(e)[0].endswith('-debug') else [] - prints('Restarting with:', ' '.join([e] + args)) - subprocess.Popen([e] + args) + if hasattr(sys, 'run_local'): + cmd = [sys.run_local] + if DEBUG: + cmd += ['calibre-debug', '-g'] + else: + cmd.append('calibre') + else: + args = ['-g'] if os.path.splitext(e)[0].endswith('-debug') else [] + cmd = [e] + args + prints('Restarting with:', ' '.join(cmd)) + subprocess.Popen(cmd) else: if iswindows: try: