mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow using calibre-debug to run scripts without using the -e option
This commit is contained in:
parent
1e6e0fa16e
commit
30828dfed9
@ -23,10 +23,9 @@ It also contains interfaces to various bits of calibre that do not have
|
|||||||
dedicated command line tools, such as font subsetting, tweaking ebooks and so
|
dedicated command line tools, such as font subsetting, tweaking ebooks and so
|
||||||
on.
|
on.
|
||||||
''')
|
''')
|
||||||
parser.add_option('-c', '--command', help='Run python code.', default=None)
|
parser.add_option('-c', '--command', help='Run python code.')
|
||||||
parser.add_option('-e', '--exec-file', default=None, help='Run the python code in file.')
|
parser.add_option('-e', '--exec-file', help='Run the python code in file.')
|
||||||
parser.add_option('-f', '--subset-font', default=False,
|
parser.add_option('-f', '--subset-font', help='Subset the specified font')
|
||||||
action='store_true', help='Subset the specified font')
|
|
||||||
parser.add_option('-d', '--debug-device-driver', default=False, action='store_true',
|
parser.add_option('-d', '--debug-device-driver', default=False, action='store_true',
|
||||||
help='Debug the specified device driver.')
|
help='Debug the specified device driver.')
|
||||||
parser.add_option('-g', '--gui', default=False, action='store_true',
|
parser.add_option('-g', '--gui', default=False, action='store_true',
|
||||||
@ -174,30 +173,24 @@ def run_debug_gui(logpath):
|
|||||||
from calibre.gui2.main import main
|
from calibre.gui2.main import main
|
||||||
main(['__CALIBRE_GUI_DEBUG__', logpath])
|
main(['__CALIBRE_GUI_DEBUG__', logpath])
|
||||||
|
|
||||||
def main(args=sys.argv):
|
def run_script(path, args):
|
||||||
from calibre.constants import debug
|
# Load all user defined plugins so the script can import from the
|
||||||
debug()
|
|
||||||
if len(args) > 2 and args[1] in ('-e', '--exec-file'):
|
|
||||||
|
|
||||||
# Load all plugins user defined plugins so the script can import from the
|
|
||||||
# calibre_plugins namespace
|
# calibre_plugins namespace
|
||||||
import calibre.customize.ui as dummy
|
import calibre.customize.ui as dummy
|
||||||
dummy
|
dummy
|
||||||
|
|
||||||
sys.argv = [args[2]] + args[3:]
|
sys.argv = [path] + args
|
||||||
ef = os.path.abspath(args[2])
|
ef = os.path.abspath(path)
|
||||||
base = os.path.dirname(ef)
|
base = os.path.dirname(ef)
|
||||||
sys.path.insert(0, base)
|
sys.path.insert(0, base)
|
||||||
g = globals()
|
g = globals()
|
||||||
g['__name__'] = '__main__'
|
g['__name__'] = '__main__'
|
||||||
g['__file__'] = ef
|
g['__file__'] = ef
|
||||||
execfile(ef, g)
|
execfile(ef, g)
|
||||||
return
|
|
||||||
|
|
||||||
if len(args) > 1 and args[1] in ('-f', '--subset-font'):
|
def main(args=sys.argv):
|
||||||
from calibre.utils.fonts.sfnt.subset import main
|
from calibre.constants import debug
|
||||||
main(['subset-font']+args[2:])
|
debug()
|
||||||
return
|
|
||||||
|
|
||||||
opts, args = option_parser().parse_args(args)
|
opts, args = option_parser().parse_args(args)
|
||||||
if opts.gui:
|
if opts.gui:
|
||||||
@ -258,6 +251,13 @@ def main(args=sys.argv):
|
|||||||
elif opts.shutdown_running_calibre:
|
elif opts.shutdown_running_calibre:
|
||||||
from calibre.gui2.main import shutdown_other
|
from calibre.gui2.main import shutdown_other
|
||||||
shutdown_other()
|
shutdown_other()
|
||||||
|
elif opts.subset_font:
|
||||||
|
from calibre.utils.fonts.sfnt.subset import main
|
||||||
|
main(['subset-font']+[opts.subset_font]+args[1:])
|
||||||
|
elif opts.exec_file:
|
||||||
|
run_script(opts.exec_file, args[1:])
|
||||||
|
elif len(args) >= 2 and args[1].rpartition('.')[-1] in {'py', 'recipe'}:
|
||||||
|
run_script(args[1], args[2:])
|
||||||
else:
|
else:
|
||||||
from calibre import ipython
|
from calibre import ipython
|
||||||
ipython()
|
ipython()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user