mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
433987c7e2
commit
008658f399
@ -15,11 +15,14 @@ from calibre.linux import entry_points, cli_index_strings
|
|||||||
from epub import EPUBHelpBuilder
|
from epub import EPUBHelpBuilder
|
||||||
from latex import LaTeXHelpBuilder
|
from latex import LaTeXHelpBuilder
|
||||||
|
|
||||||
|
|
||||||
def substitute(app, doctree):
|
def substitute(app, doctree):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
include_pat = re.compile(r'^.. include:: (\S+.rst)', re.M)
|
include_pat = re.compile(r'^.. include:: (\S+.rst)', re.M)
|
||||||
|
|
||||||
|
|
||||||
def source_read_handler(app, docname, source):
|
def source_read_handler(app, docname, source):
|
||||||
src = source[0]
|
src = source[0]
|
||||||
if app.builder.name != 'gettext' and app.config.language != 'en':
|
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():]
|
src = src[:m.start()] + ss[0] + src[m.end():]
|
||||||
source[0] = src
|
source[0] = src
|
||||||
|
|
||||||
|
|
||||||
CLI_INDEX='''
|
CLI_INDEX='''
|
||||||
.. _cli:
|
.. _cli:
|
||||||
|
|
||||||
@ -72,15 +76,16 @@ CLI_PREAMBLE='''\
|
|||||||
{usage}
|
{usage}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
def titlecase(app, x):
|
def titlecase(app, x):
|
||||||
if x and app.config.language == 'en':
|
if x and app.config.language == 'en':
|
||||||
from calibre.utils.titlecase import titlecase as tc
|
from calibre.utils.titlecase import titlecase as tc
|
||||||
x = tc(x)
|
x = tc(x)
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
||||||
def generate_calibredb_help(preamble, app):
|
def generate_calibredb_help(preamble, app):
|
||||||
from calibre.library.cli import COMMANDS, get_parser
|
from calibre.db.cli.main import COMMANDS, option_parser_for, get_parser
|
||||||
import calibre.library.cli as cli
|
|
||||||
preamble = preamble[:preamble.find('\n\n\n', preamble.find('code-block'))]
|
preamble = preamble[:preamble.find('\n\n\n', preamble.find('code-block'))]
|
||||||
preamble += textwrap.dedent('''
|
preamble += textwrap.dedent('''
|
||||||
|
|
||||||
@ -98,12 +103,7 @@ def generate_calibredb_help(preamble, app):
|
|||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
for cmd in COMMANDS:
|
for cmd in COMMANDS:
|
||||||
args = []
|
parser = option_parser_for(cmd)()
|
||||||
if cmd == 'catalog':
|
|
||||||
args = [['doc.xml', '-h']]
|
|
||||||
parser = getattr(cli, cmd+'_option_parser')(*args)
|
|
||||||
if cmd == 'catalog':
|
|
||||||
parser = parser[0]
|
|
||||||
lines += ['.. _calibredb-%s-%s:' % (app.config.language, cmd), '']
|
lines += ['.. _calibredb-%s-%s:' % (app.config.language, cmd), '']
|
||||||
lines += [cmd, '~'*20, '']
|
lines += [cmd, '~'*20, '']
|
||||||
usage = parser.usage.strip()
|
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)
|
raw = preamble + '\n\n'+'.. contents::\n :local:'+ '\n\n' + global_options+'\n\n'+'\n'.join(lines)
|
||||||
update_cli_doc('calibredb', raw, app)
|
update_cli_doc('calibredb', raw, app)
|
||||||
|
|
||||||
|
|
||||||
def generate_ebook_convert_help(preamble, app):
|
def generate_ebook_convert_help(preamble, app):
|
||||||
from calibre.ebooks.conversion.cli import create_option_parser, manual_index_strings
|
from calibre.ebooks.conversion.cli import create_option_parser, manual_index_strings
|
||||||
from calibre.customize.ui import input_format_plugins, output_format_plugins
|
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)
|
update_cli_doc('ebook-convert', raw, app)
|
||||||
|
|
||||||
|
|
||||||
def update_cli_doc(name, raw, app):
|
def update_cli_doc(name, raw, app):
|
||||||
if isinstance(raw, unicode):
|
if isinstance(raw, unicode):
|
||||||
raw = raw.encode('utf-8')
|
raw = raw.encode('utf-8')
|
||||||
@ -180,6 +182,7 @@ def update_cli_doc(name, raw, app):
|
|||||||
os.makedirs(p)
|
os.makedirs(p)
|
||||||
open(path, 'wb').write(raw)
|
open(path, 'wb').write(raw)
|
||||||
|
|
||||||
|
|
||||||
def render_options(cmd, groups, options_header=True, add_program=True, header_level='~'):
|
def render_options(cmd, groups, options_header=True, add_program=True, header_level='~'):
|
||||||
lines = ['']
|
lines = ['']
|
||||||
if options_header:
|
if options_header:
|
||||||
@ -204,8 +207,10 @@ def render_options(cmd, groups, options_header=True, add_program=True, header_le
|
|||||||
lines.extend([opt, '', ' '+help, ''])
|
lines.extend([opt, '', ' '+help, ''])
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
|
||||||
def mark_options(raw):
|
def mark_options(raw):
|
||||||
raw = re.sub(r'(\s+)--(\s+)', r'\1``--``\2', raw)
|
raw = re.sub(r'(\s+)--(\s+)', r'\1``--``\2', raw)
|
||||||
|
|
||||||
def sub(m):
|
def sub(m):
|
||||||
opt = m.group()
|
opt = m.group()
|
||||||
a, b = opt.partition('=')[::2]
|
a, b = opt.partition('=')[::2]
|
||||||
@ -217,6 +222,7 @@ def mark_options(raw):
|
|||||||
raw = re.sub(r'(--[|()a-zA-Z0-9_=,-]+)', sub, raw)
|
raw = re.sub(r'(--[|()a-zA-Z0-9_=,-]+)', sub, raw)
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
|
|
||||||
def cli_docs(app):
|
def cli_docs(app):
|
||||||
info = app.builder.info
|
info = app.builder.info
|
||||||
info(bold('creating CLI documentation...'))
|
info(bold('creating CLI documentation...'))
|
||||||
@ -269,15 +275,18 @@ def cli_docs(app):
|
|||||||
raw += '\n'+'\n'.join(lines)
|
raw += '\n'+'\n'.join(lines)
|
||||||
update_cli_doc(cmd, raw, app)
|
update_cli_doc(cmd, raw, app)
|
||||||
|
|
||||||
|
|
||||||
def generate_docs(app):
|
def generate_docs(app):
|
||||||
cli_docs(app)
|
cli_docs(app)
|
||||||
template_docs(app)
|
template_docs(app)
|
||||||
|
|
||||||
|
|
||||||
def template_docs(app):
|
def template_docs(app):
|
||||||
from template_ref_generate import generate_template_language_help
|
from template_ref_generate import generate_template_language_help
|
||||||
raw = generate_template_language_help(app.config.language)
|
raw = generate_template_language_help(app.config.language)
|
||||||
update_cli_doc('template_ref', raw, app)
|
update_cli_doc('template_ref', raw, app)
|
||||||
|
|
||||||
|
|
||||||
def localized_path(app, langcode, pagename):
|
def localized_path(app, langcode, pagename):
|
||||||
href = app.builder.get_target_uri(pagename)
|
href = app.builder.get_target_uri(pagename)
|
||||||
href = re.sub(r'generated/[a-z]+/', 'generated/%s/' % langcode, href)
|
href = re.sub(r'generated/[a-z]+/', 'generated/%s/' % langcode, href)
|
||||||
@ -286,10 +295,12 @@ def localized_path(app, langcode, pagename):
|
|||||||
prefix += langcode + '/'
|
prefix += langcode + '/'
|
||||||
return prefix + href
|
return prefix + href
|
||||||
|
|
||||||
|
|
||||||
def add_html_context(app, pagename, templatename, context, *args):
|
def add_html_context(app, pagename, templatename, context, *args):
|
||||||
context['localized_path'] = partial(localized_path, app)
|
context['localized_path'] = partial(localized_path, app)
|
||||||
context['change_language_text'] = cli_index_strings()[5]
|
context['change_language_text'] = cli_index_strings()[5]
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
app.add_builder(EPUBHelpBuilder)
|
app.add_builder(EPUBHelpBuilder)
|
||||||
app.add_builder(LaTeXHelpBuilder)
|
app.add_builder(LaTeXHelpBuilder)
|
||||||
@ -299,7 +310,6 @@ def setup(app):
|
|||||||
app.connect('html-page-context', add_html_context)
|
app.connect('html-page-context', add_html_context)
|
||||||
app.connect('build-finished', finished)
|
app.connect('build-finished', finished)
|
||||||
|
|
||||||
|
|
||||||
def finished(app, exception):
|
def finished(app, exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -485,7 +485,7 @@ class CatalogPlugin(Plugin): # {{{
|
|||||||
#: dest = 'catalog_title',
|
#: dest = 'catalog_title',
|
||||||
#: help = (_('Title of generated catalog. \nDefault:') + " '" +
|
#: help = (_('Title of generated catalog. \nDefault:') + " '" +
|
||||||
#: '%default' + "'"))]
|
#: '%default' + "'"))]
|
||||||
#: cli_options parsed in library.cli:catalog_option_parser()
|
#: cli_options parsed in calibre.db.cli.cmd_catalog:option_parser()
|
||||||
cli_options = []
|
cli_options = []
|
||||||
|
|
||||||
def _field_sorter(self, key):
|
def _field_sorter(self, key):
|
||||||
|
@ -20,10 +20,11 @@ from calibre.utils.serialize import MSGPACK_MIME
|
|||||||
|
|
||||||
COMMANDS = (
|
COMMANDS = (
|
||||||
'list', 'add', 'remove', 'add_format', 'remove_format', 'show_metadata',
|
'list', 'add', 'remove', 'add_format', 'remove_format', 'show_metadata',
|
||||||
'set_metadata', 'export', 'catalog', 'saved_searches', 'add_custom_column',
|
'set_metadata', 'export', 'catalog',
|
||||||
'custom_columns', 'remove_custom_column', 'set_custom', 'restore_database',
|
# 'saved_searches', 'add_custom_column',
|
||||||
'check_library', 'list_categories', 'backup_metadata', 'clone', 'embed_metadata',
|
# 'custom_columns', 'remove_custom_column', 'set_custom', 'restore_database',
|
||||||
'search'
|
# 'check_library', 'list_categories', 'backup_metadata', 'clone', 'embed_metadata',
|
||||||
|
# 'search'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -331,7 +331,7 @@ def generate_catalog(parent, dbspec, ids, device_manager, db): # {{{
|
|||||||
out = PersistentTemporaryFile(suffix='_catalog_out.'+d.catalog_format.lower())
|
out = PersistentTemporaryFile(suffix='_catalog_out.'+d.catalog_format.lower())
|
||||||
|
|
||||||
# Profile the connected device
|
# Profile the connected device
|
||||||
# Parallel initialization in calibre.library.cli:command_catalog()
|
# Parallel initialization in calibre.db.cli.cmd_catalog
|
||||||
connected_device = {
|
connected_device = {
|
||||||
'is_device_connected': device_manager.is_device_present,
|
'is_device_connected': device_manager.is_device_present,
|
||||||
'kind': device_manager.connected_device_kind,
|
'kind': device_manager.connected_device_kind,
|
||||||
|
@ -44,7 +44,7 @@ class CatalogBuilder(object):
|
|||||||
|
|
||||||
Flow of control:
|
Flow of control:
|
||||||
gui2.actions.catalog:generate_catalog()
|
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()
|
called from gui2.convert.gui_conversion:gui_catalog()
|
||||||
catalog = Catalog(notification=Reporter())
|
catalog = Catalog(notification=Reporter())
|
||||||
catalog.build_sources()
|
catalog.build_sources()
|
||||||
|
@ -26,7 +26,7 @@ entry_points = {
|
|||||||
'lrf2lrs = calibre.ebooks.lrf.lrfparser:main',
|
'lrf2lrs = calibre.ebooks.lrf.lrfparser:main',
|
||||||
'lrs2lrf = calibre.ebooks.lrf.lrs.convert_from:main',
|
'lrs2lrf = calibre.ebooks.lrf.lrs.convert_from:main',
|
||||||
'calibre-debug = calibre.debug: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-parallel = calibre.utils.ipc.worker:main',
|
||||||
'calibre-customize = calibre.customize.ui:main',
|
'calibre-customize = calibre.customize.ui:main',
|
||||||
'calibre-complete = calibre.utils.complete:main',
|
'calibre-complete = calibre.utils.complete:main',
|
||||||
@ -402,15 +402,11 @@ _ebook_edit() {
|
|||||||
''' % (opt_lines, '|'.join(tweakable_fmts)) + '\n\n').encode('utf-8'))
|
''' % (opt_lines, '|'.join(tweakable_fmts)) + '\n\n').encode('utf-8'))
|
||||||
|
|
||||||
def do_calibredb(self, f):
|
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
|
from calibre.customize.ui import available_catalog_formats
|
||||||
parsers, descs = {}, {}
|
parsers, descs = {}, {}
|
||||||
for command in cli.COMMANDS:
|
for command in COMMANDS:
|
||||||
op = getattr(cli, '%s_option_parser'%command)
|
p = option_parser_for(command)()
|
||||||
args = [['t.epub']] if command == 'catalog' else []
|
|
||||||
p = op(*args)
|
|
||||||
if isinstance(p, tuple):
|
|
||||||
p = p[0]
|
|
||||||
parsers[command] = p
|
parsers[command] = p
|
||||||
lines = [x.strip().partition('.')[0] for x in p.usage.splitlines() if x.strip() and
|
lines = [x.strip().partition('.')[0] for x in p.usage.splitlines() if x.strip() and
|
||||||
not x.strip().startswith('%prog')]
|
not x.strip().startswith('%prog')]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user