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]));'
|
'import sys, json, binascii, os, subprocess; cmd = json.loads(binascii.unhexlify(sys.argv[-1]));'
|
||||||
'env = os.environ.copy();'
|
'env = os.environ.copy();'
|
||||||
'''env[str('CALIBRE_DEVELOP_FROM')] = str(os.path.abspath('calibre-src/src'));'''
|
'''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();'
|
'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)'
|
'sys.stdout.flush(); sys.stderr.flush(); sys.exit(ret)'
|
||||||
'"', enc]
|
'"', enc]
|
||||||
|
@ -15,12 +15,21 @@ from polyglot.builtins import exec_path, raw_input, unicode_type, getcwd
|
|||||||
|
|
||||||
|
|
||||||
def get_debug_executable():
|
def get_debug_executable():
|
||||||
|
exe_name = 'calibre-debug' + ('.exe' if iswindows else '')
|
||||||
if hasattr(sys, 'frameworks_dir'):
|
if hasattr(sys, 'frameworks_dir'):
|
||||||
base = os.path.dirname(sys.frameworks_dir)
|
base = os.path.dirname(sys.frameworks_dir)
|
||||||
return os.path.join(base, 'MacOS', 'calibre-debug')
|
return [os.path.join(base, 'MacOS', exe_name)]
|
||||||
if getattr(sys, 'frozen', False):
|
if getattr(sys, 'run_local', None):
|
||||||
return os.path.join(os.path.dirname(os.path.abspath(sys.executable)), 'calibre-debug' + ('.exe' if iswindows else ''))
|
return [sys.run_local, exe_name]
|
||||||
return 'calibre-debug'
|
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):
|
def run_calibre_debug(*args, **kw):
|
||||||
@ -29,8 +38,7 @@ def run_calibre_debug(*args, **kw):
|
|||||||
if iswindows:
|
if iswindows:
|
||||||
import win32process
|
import win32process
|
||||||
creationflags = win32process.CREATE_NO_WINDOW
|
creationflags = win32process.CREATE_NO_WINDOW
|
||||||
exe = get_debug_executable()
|
cmd = get_debug_executable() + list(args)
|
||||||
cmd = [exe] + list(args)
|
|
||||||
kw['creationflags'] = creationflags
|
kw['creationflags'] = creationflags
|
||||||
return subprocess.Popen(cmd, **kw)
|
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')
|
os.environ['CALIBRE_RESTARTING_FROM_GUI'] = environ_item('1')
|
||||||
if iswindows and hasattr(winutil, 'prepare_for_restart'):
|
if iswindows and hasattr(winutil, 'prepare_for_restart'):
|
||||||
winutil.prepare_for_restart()
|
winutil.prepare_for_restart()
|
||||||
|
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 []
|
args = ['-g'] if os.path.splitext(e)[0].endswith('-debug') else []
|
||||||
prints('Restarting with:', ' '.join([e] + args))
|
cmd = [e] + args
|
||||||
subprocess.Popen([e] + args)
|
prints('Restarting with:', ' '.join(cmd))
|
||||||
|
subprocess.Popen(cmd)
|
||||||
else:
|
else:
|
||||||
if iswindows:
|
if iswindows:
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user