def do_calibredb(self, f): from calibre.db.cli.main import COMMANDS, option_parser_for from calibre.customize.ui import available_catalog_formats parsers, descs = {}, {} 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') ] descs[command] = lines[0] w = polyglot_write(f) w('\n_calibredb_cmds() {\n local commands; commands=(\n') w(' {-h,--help}":Show help"\n') w(' "--version:Show version"\n') for command, desc in iteritems(descs): w(' "%s:%s"\n' % (command, desc.replace(':', '\\:').replace('"', '\''))) w(' )\n _describe -t commands "calibredb command" commands \n}\n') subcommands = [] for command, parser in iteritems(parsers): exts = [] if command == 'catalog': exts = [x.lower() for x in available_catalog_formats()] elif command == 'set_metadata': exts = ['opf'] exts = set(exts).union(x.upper() for x in exts) pats = ('*.%s' % x for x in exts) extra = ("'*:filename:_files -g \"%s\"' " % ' '.join(pats), ) if exts else () if command in {'add', 'add_format'}: extra = ("'*:filename:_files' ", ) opts = '\\\n '.join(tuple(self.get_options(parser)) + extra) txt = ' _arguments -s \\\n ' + opts subcommands.append('(%s)' % command) subcommands.append(txt) subcommands.append(';;') w('\n_calibredb() {') w((r''' local state line state_descr context typeset -A opt_args local ret=1 _arguments \ '1: :_calibredb_cmds' \ '*::calibredb subcommand options:->args' \ && ret=0 case $state in (args) case $line[1] in (-h|--help|--version) _message 'no more arguments' && ret=0 ;; %s esac ;; esac return ret ''' % '\n '.join(subcommands))) w('\n}\n\n')
def do_calibredb(self, f): from calibre.db.cli.main import COMMANDS, option_parser_for from calibre.customize.ui import available_catalog_formats parsers, descs = {}, {} 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')] descs[command] = lines[0] f.write('\n_calibredb_cmds() {\n local commands; commands=(\n') f.write(' {-h,--help}":Show help"\n') f.write(' "--version:Show version"\n') for command, desc in descs.iteritems(): f.write(' "%s:%s"\n'%( command, desc.replace(':', '\\:').replace('"', '\''))) f.write(' )\n _describe -t commands "calibredb command" commands \n}\n') subcommands = [] for command, parser in parsers.iteritems(): exts = [] if command == 'catalog': exts = [x.lower() for x in available_catalog_formats()] elif command == 'set_metadata': exts = ['opf'] exts = set(exts).union(x.upper() for x in exts) pats = ('*.%s'%x for x in exts) extra = ("'*:filename:_files -g \"%s\"' "%' '.join(pats),) if exts else () if command in {'add', 'add_format'}: extra = ("'*:filename:_files' ",) opts = '\\\n '.join(tuple(self.get_options( parser)) + extra) txt = ' _arguments -s \\\n ' + opts subcommands.append('(%s)'%command) subcommands.append(txt) subcommands.append(';;') f.write('\n_calibredb() {') f.write(( r''' local state line state_descr context typeset -A opt_args local ret=1 _arguments \ '1: :_calibredb_cmds' \ '*::calibredb subcommand options:->args' \ && ret=0 case $state in (args) case $line[1] in (-h|--help|--version) _message 'no more arguments' && ret=0 ;; %s esac ;; esac return ret '''%'\n '.join(subcommands)).encode('utf-8')) f.write('\n}\n\n')
def generate_calibredb_help(preamble, app): 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(''' :command:`calibredb` is the command line interface to the calibre database. It has several sub-commands, documented below. :command:`calibredb` can be used to manipulate either a calibre database specified by path or a calibre :guilabel:`Content server` running either on the local machine or over the internet. You can start a calibre :guilabel:`Content server` using either the :command:`calibre-server` program or in the main calibre program click :guilabel:`Connect/share -> Start Content server`. Since :command:`calibredb` can make changes to your calibre libraries, you must setup authentication on the server first. There are two ways to do that: * If you plan to connect only to a server running on the same computer, you can simply use the ``--enable-local-write`` option of the content server, to allow any program, including calibredb, running on the local computer to make changes to your calibre data. When running the server from the main calibre program, this option is in :guilabel:`Preferences->Sharing over the net->Advanced`. * If you want to enable access over the internet, then you should setup user accounts on the server and use the :option:`--username` and :option:`--password` options to :command:`calibredb` to give it access. You can setup user authentication for :command:`calibre-server` by using the ``--enable-auth`` option and using ``--manage-users`` to create the user accounts. If you are running the server from the main calibre program, use :guilabel:`Preferences->Sharing over the net->Require username/password`. To connect to a running Content server, pass the URL of the server to the :option:`--with-library` option, see the documentation of that option for details and examples. ''') global_parser = get_parser('') groups = [] for grp in global_parser.option_groups: groups.append((titlecase(app, grp.title), grp.description, grp.option_list)) global_options = '\n'.join( render_options('calibredb', groups, False, False)) lines = [] for cmd in COMMANDS: parser = option_parser_for(cmd)() lines += ['.. _calibredb-%s-%s:' % (app.config.language, cmd), ''] lines += [cmd, '~' * 20, ''] usage = parser.usage.strip() usage = [i for i in usage.replace('%prog', 'calibredb').splitlines()] cmdline = ' ' + usage[0] usage = usage[1:] usage = [ re.sub(r'(%s)([^a-zA-Z0-9])' % cmd, r':command:`\1`\2', i) for i in usage ] lines += ['.. code-block:: none', '', cmdline, ''] lines += usage groups = [(None, None, parser.option_list)] lines += [''] lines += render_options('calibredb ' + cmd, groups, False) lines += [''] for group in parser.option_groups: if not getattr(group, 'is_global_options', False): lines.extend( render_options('calibredb_' + cmd, [[ titlecase(app, group.title), group.description, group.option_list ]], False, False, header_level='^')) lines += [''] raw = preamble + '\n\n' + '.. contents::\n :local:' + '\n\n' + global_options + '\n\n' + '\n'.join( lines) update_cli_doc('calibredb', raw, app)
def generate_calibredb_help(preamble, app): 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(''' :command:`calibredb` is the command line interface to the calibre database. It has several sub-commands, documented below. :command:`calibredb` can be used to manipulate either a calibre database specified by path or a calibre :guilabel:`Content server` running either on the local machine or over the internet. You can start a calibre :guilabel:`Content server` using either the :command:`calibre-server` program or in the main calibre program click :guilabel:`Connect/share -> Start Content server`. Since :command:`calibredb` can make changes to your calibre libraries, you must setup authentication on the server first. There are two ways to do that: * If you plan to connect only to a server running on the same computer, you can simply use the ``--enable-local-write`` option of the content server, to allow any program, including calibredb, running on the local computer to make changes to your calibre data. When running the server from the main calibre program, this option is in :guilabel:`Preferences->Sharing over the net->Advanced`. * If you want to enable access over the internet, then you should setup user accounts on the server and use the :option:`--username` and :option:`--password` options to :command:`calibredb` to give it access. You can setup user authentication for :command:`calibre-server` by using the ``--enable-auth`` option and using ``--manage-users`` to create the user accounts. If you are running the server from the main calibre program, use :guilabel:`Preferences->Sharing over the net->Require username/password`. To connect to a running Content server, pass the URL of the server to the :option:`--with-library` option, see the documentation of that option for details and examples. ''') global_parser = get_parser('') groups = [] for grp in global_parser.option_groups: groups.append((titlecase(app, grp.title), grp.description, grp.option_list)) global_options = '\n'.join(render_options('calibredb', groups, False, False)) lines = [] for cmd in COMMANDS: parser = option_parser_for(cmd)() lines += ['.. _calibredb-%s-%s:' % (app.config.language, cmd), ''] lines += [cmd, '~'*20, ''] usage = parser.usage.strip() usage = [i for i in usage.replace('%prog', 'calibredb').splitlines()] cmdline = ' '+usage[0] usage = usage[1:] usage = [re.sub(r'(%s)([^a-zA-Z0-9])'%cmd, r':command:`\1`\2', i) for i in usage] lines += ['.. code-block:: none', '', cmdline, ''] lines += usage groups = [(None, None, parser.option_list)] lines += [''] lines += render_options('calibredb '+cmd, groups, False) lines += [''] for group in parser.option_groups: if not getattr(group, 'is_global_options', False): lines.extend(render_options( 'calibredb_' + cmd, [[titlecase(app, group.title), group.description, group.option_list]], False, False, header_level='^')) lines += [''] raw = preamble + '\n\n'+'.. contents::\n :local:'+ '\n\n' + global_options+'\n\n'+'\n'.join(lines) update_cli_doc('calibredb', raw, app)