mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add support for run-local to calibre restart and run_calibre_debug
This commit is contained in:
parent
ac953dd2e6
commit
61005add0d
@ -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]
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user