Simplify code to find path to calibre-debug

This commit is contained in:
Kovid Goyal 2017-05-03 14:11:06 +05:30
parent 235227c544
commit ebe67702fd
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -13,21 +13,14 @@ from calibre import prints
def get_debug_executable(): def get_debug_executable():
e = sys.executable if getattr(sys, 'frozen', False) else sys.argv[0]
if hasattr(sys, 'frameworks_dir'): if hasattr(sys, 'frameworks_dir'):
base = os.path.dirname(sys.frameworks_dir) base = os.path.dirname(sys.frameworks_dir)
if 'calibre-debug.app' not in base: if 'calibre-debug.app' not in base:
base = os.path.join(base, 'calibre-debug.app', 'Contents') base = os.path.join(base, 'calibre-debug.app', 'Contents')
exe = os.path.basename(e) return os.path.join(base, 'MacOS', 'calibre-debug')
if '-debug' not in exe: if getattr(sys, 'frozen', False):
exe += '-debug' return os.path.join(os.path.dirname(os.path.abspath(sys.executable)), 'calibre-debug' + ('.exe' if iswindows else ''))
exe = os.path.join(base, 'MacOS', exe) return 'calibre-debug'
else:
exe = e
if '-debug' not in exe:
base, ext = os.path.splitext(e)
exe = base + '-debug' + ext
return exe
def run_calibre_debug(*args, **kw): def run_calibre_debug(*args, **kw):
@ -39,7 +32,7 @@ def run_calibre_debug(*args, **kw):
exe = get_debug_executable() exe = get_debug_executable()
cmd = [exe] + list(args) cmd = [exe] + list(args)
kw['creationflags'] = creationflags kw['creationflags'] = creationflags
subprocess.Popen(cmd, **kw) return subprocess.Popen(cmd, **kw)
def option_parser(): def option_parser():