Remove most references to the old library.cli module

Still have to remove the module and port the test for the check command
This commit is contained in:
Kovid Goyal 2017-05-02 00:30:43 +05:30
parent 433987c7e2
commit 008658f399
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 32 additions and 25 deletions

View File

@ -15,11 +15,14 @@ from calibre.linux import entry_points, cli_index_strings
from epub import EPUBHelpBuilder
from latex import LaTeXHelpBuilder
def substitute(app, doctree):
pass
include_pat = re.compile(r'^.. include:: (\S+.rst)', re.M)
def source_read_handler(app, docname, source):
src = source[0]
if app.builder.name != 'gettext' and app.config.language != 'en':
@ -32,6 +35,7 @@ def source_read_handler(app, docname, source):
src = src[:m.start()] + ss[0] + src[m.end():]
source[0] = src
CLI_INDEX='''
.. _cli:
@ -72,15 +76,16 @@ CLI_PREAMBLE='''\
{usage}
'''
def titlecase(app, x):
if x and app.config.language == 'en':
from calibre.utils.titlecase import titlecase as tc
x = tc(x)
return x
def generate_calibredb_help(preamble, app):
from calibre.library.cli import COMMANDS, get_parser
import calibre.library.cli as cli
from calibre.db.cli.main import COMMANDS, option_parser_for, get_parser
preamble = preamble[:preamble.find('\n\n\n', preamble.find('code-block'))]
preamble += textwrap.dedent('''
@ -98,12 +103,7 @@ def generate_calibredb_help(preamble, app):
lines = []
for cmd in COMMANDS:
args = []
if cmd == 'catalog':
args = [['doc.xml', '-h']]
parser = getattr(cli, cmd+'_option_parser')(*args)
if cmd == 'catalog':
parser = parser[0]
parser = option_parser_for(cmd)()
lines += ['.. _calibredb-%s-%s:' % (app.config.language, cmd), '']
lines += [cmd, '~'*20, '']
usage = parser.usage.strip()
@ -126,6 +126,7 @@ def generate_calibredb_help(preamble, app):
raw = preamble + '\n\n'+'.. contents::\n :local:'+ '\n\n' + global_options+'\n\n'+'\n'.join(lines)
update_cli_doc('calibredb', raw, app)
def generate_ebook_convert_help(preamble, app):
from calibre.ebooks.conversion.cli import create_option_parser, manual_index_strings
from calibre.customize.ui import input_format_plugins, output_format_plugins
@ -161,6 +162,7 @@ def generate_ebook_convert_help(preamble, app):
update_cli_doc('ebook-convert', raw, app)
def update_cli_doc(name, raw, app):
if isinstance(raw, unicode):
raw = raw.encode('utf-8')
@ -180,6 +182,7 @@ def update_cli_doc(name, raw, app):
os.makedirs(p)
open(path, 'wb').write(raw)
def render_options(cmd, groups, options_header=True, add_program=True, header_level='~'):
lines = ['']
if options_header:
@ -204,8 +207,10 @@ def render_options(cmd, groups, options_header=True, add_program=True, header_le
lines.extend([opt, '', ' '+help, ''])
return lines
def mark_options(raw):
raw = re.sub(r'(\s+)--(\s+)', r'\1``--``\2', raw)
def sub(m):
opt = m.group()
a, b = opt.partition('=')[::2]
@ -217,6 +222,7 @@ def mark_options(raw):
raw = re.sub(r'(--[|()a-zA-Z0-9_=,-]+)', sub, raw)
return raw
def cli_docs(app):
info = app.builder.info
info(bold('creating CLI documentation...'))
@ -269,15 +275,18 @@ def cli_docs(app):
raw += '\n'+'\n'.join(lines)
update_cli_doc(cmd, raw, app)
def generate_docs(app):
cli_docs(app)
template_docs(app)
def template_docs(app):
from template_ref_generate import generate_template_language_help
raw = generate_template_language_help(app.config.language)
update_cli_doc('template_ref', raw, app)
def localized_path(app, langcode, pagename):
href = app.builder.get_target_uri(pagename)
href = re.sub(r'generated/[a-z]+/', 'generated/%s/' % langcode, href)
@ -286,10 +295,12 @@ def localized_path(app, langcode, pagename):
prefix += langcode + '/'
return prefix + href
def add_html_context(app, pagename, templatename, context, *args):
context['localized_path'] = partial(localized_path, app)
context['change_language_text'] = cli_index_strings()[5]
def setup(app):
app.add_builder(EPUBHelpBuilder)
app.add_builder(LaTeXHelpBuilder)
@ -299,7 +310,6 @@ def setup(app):
app.connect('html-page-context', add_html_context)
app.connect('build-finished', finished)
def finished(app, exception):
pass

View File

@ -485,7 +485,7 @@ class CatalogPlugin(Plugin): # {{{
#: dest = 'catalog_title',
#: help = (_('Title of generated catalog. \nDefault:') + " '" +
#: '%default' + "'"))]
#: cli_options parsed in library.cli:catalog_option_parser()
#: cli_options parsed in calibre.db.cli.cmd_catalog:option_parser()
cli_options = []
def _field_sorter(self, key):

View File

@ -20,10 +20,11 @@ from calibre.utils.serialize import MSGPACK_MIME
COMMANDS = (
'list', 'add', 'remove', 'add_format', 'remove_format', 'show_metadata',
'set_metadata', 'export', 'catalog', 'saved_searches', 'add_custom_column',
'custom_columns', 'remove_custom_column', 'set_custom', 'restore_database',
'check_library', 'list_categories', 'backup_metadata', 'clone', 'embed_metadata',
'search'
'set_metadata', 'export', 'catalog',
# 'saved_searches', 'add_custom_column',
# 'custom_columns', 'remove_custom_column', 'set_custom', 'restore_database',
# 'check_library', 'list_categories', 'backup_metadata', 'clone', 'embed_metadata',
# 'search'
)

View File

@ -331,7 +331,7 @@ def generate_catalog(parent, dbspec, ids, device_manager, db): # {{{
out = PersistentTemporaryFile(suffix='_catalog_out.'+d.catalog_format.lower())
# Profile the connected device
# Parallel initialization in calibre.library.cli:command_catalog()
# Parallel initialization in calibre.db.cli.cmd_catalog
connected_device = {
'is_device_connected': device_manager.is_device_present,
'kind': device_manager.connected_device_kind,

View File

@ -44,7 +44,7 @@ class CatalogBuilder(object):
Flow of control:
gui2.actions.catalog:generate_catalog()
gui2.tools:generate_catalog() or library.cli:command_catalog()
gui2.tools:generate_catalog() or db.cli.cmd_catalog
called from gui2.convert.gui_conversion:gui_catalog()
catalog = Catalog(notification=Reporter())
catalog.build_sources()

View File

@ -26,7 +26,7 @@ entry_points = {
'lrf2lrs = calibre.ebooks.lrf.lrfparser:main',
'lrs2lrf = calibre.ebooks.lrf.lrs.convert_from:main',
'calibre-debug = calibre.debug:main',
'calibredb = calibre.library.cli:main',
'calibredb = calibre.db.cli.main:main',
'calibre-parallel = calibre.utils.ipc.worker:main',
'calibre-customize = calibre.customize.ui:main',
'calibre-complete = calibre.utils.complete:main',
@ -402,15 +402,11 @@ _ebook_edit() {
''' % (opt_lines, '|'.join(tweakable_fmts)) + '\n\n').encode('utf-8'))
def do_calibredb(self, f):
import calibre.library.cli as cli
from calibre.db.cli.main import COMMANDS, option_parser_for
from calibre.customize.ui import available_catalog_formats
parsers, descs = {}, {}
for command in cli.COMMANDS:
op = getattr(cli, '%s_option_parser'%command)
args = [['t.epub']] if command == 'catalog' else []
p = op(*args)
if isinstance(p, tuple):
p = p[0]
for command in COMMANDS:
p = option_parser_for(command)()
parsers[command] = p
lines = [x.strip().partition('.')[0] for x in p.usage.splitlines() if x.strip() and
not x.strip().startswith('%prog')]