mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Allow running plugins from the cli with calibre-debug easily
This commit is contained in:
parent
4ef2f1a2f8
commit
4e67c9bf59
@ -293,6 +293,14 @@ class Plugin(object): # {{{
|
||||
if hasattr(it, '__exit__'):
|
||||
it.__exit__(*args)
|
||||
|
||||
def cli_main(self, args):
|
||||
'''
|
||||
This method is the main entry point for your plugins command line
|
||||
interface. It is called when the user does: calibre-debug
|
||||
'''
|
||||
raise NotImplementedError('The %s plugin has no command line interface'
|
||||
%self.name)
|
||||
|
||||
# }}}
|
||||
|
||||
class FileTypePlugin(Plugin): # {{{
|
||||
|
@ -75,9 +75,12 @@ Everything after the -- is passed to the script.
|
||||
help=_('Cause a running calibre instance, if any, to be'
|
||||
' shutdown. Note that if there are running jobs, they '
|
||||
'will be silently aborted, so use with care.'))
|
||||
|
||||
parser.add_option('--test-build', help='Test binary modules in build',
|
||||
action='store_true', default=False)
|
||||
parser.add_option('-r', '--run-plugin', help=_(
|
||||
'Run a plugin that provides a command line interface. For example:\n'
|
||||
'calibre-debug -r "Add Books" -- file1 --option1\n'
|
||||
'Everything after the -- will be passed to the plugin as arguments.'))
|
||||
|
||||
return parser
|
||||
|
||||
@ -262,6 +265,13 @@ def main(args=sys.argv):
|
||||
main(['subset-font']+[opts.subset_font]+args[1:])
|
||||
elif opts.exec_file:
|
||||
run_script(opts.exec_file, args[1:])
|
||||
elif opts.run_plugin:
|
||||
from calibre.customize.ui import find_plugin
|
||||
plugin = find_plugin(opts.run_plugin)
|
||||
if plugin is None:
|
||||
prints(_('No plugin named %s found')%opts.run_plugin)
|
||||
raise SystemExit(1)
|
||||
plugin.cli_main([plugin.name] + args[1:])
|
||||
elif len(args) >= 2 and args[1].rpartition('.')[-1] in {'py', 'recipe'}:
|
||||
run_script(args[1], args[2:])
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user