コード例 #1
0
class PybtexCommandLine(CommandLine):
    prog = 'pybtex'
    args = '[options] auxfile.aux'
    description = 'BibTeX-compatible bibliography processor in Python'
    long_description = """

Pybtex reads citation information from a LaTeX .aux file and produces a
formatted bibliography. Pybtex understands BibTeX .bib and .bst style files and
can be used as a drop-in replacement for BibTeX.

Besides BibTeX .bib files, BibTeXML and YAML bibliography files are
supported.

It is also possible to define bibliography formatting styles in Python.

    """.strip()
    num_args = 1

    options = (
        (None, (
            standard_option('strict'),
            make_option(
                '--terse',
                dest='verbose',
                action='store_false',
                help='ignored for compatibility with BibTeX',
            ),
            standard_option('min_crossrefs'),
            standard_option('bib_format'),
            standard_option('output_backend'),
            standard_option('style'),
            make_option(
                '-l',
                '--style-language',
                dest='style_language',
                help='style definition language to use (bibtex or python)',
                metavar='LANGUAGE',
            ),
        )),
        ('Pythonic style options', (
            standard_option('label_style'),
            standard_option('name_style'),
            standard_option('sorting_style'),
            standard_option('abbreviate_names'),
        )),
        ('Encoding options', (
            standard_option('encoding'),
            make_option('--bibtex-encoding',
                        dest='bib_encoding',
                        metavar='ENCODING'),
            make_option('--bst-encoding',
                        dest='bst_encoding',
                        metavar='ENCODING'),
            standard_option('output_encoding'),
        )),
    )
    option_defaults = {
        'style_language': 'bibtex',
        'min_crossrefs': 2,
    }
    legacy_options = '-help', '-version', '-min-crossrefs', '-terse'

    def run(self, filename, style_language, encoding, **options):
        if style_language == 'bibtex':
            from pybtex import bibtex as engine
        elif style_language == 'python':
            import pybtex as engine
        else:
            self.opt_parser.error('unknown style language %s' % style_language)

        not_supported_by_bibtex = {
            'output_backend': 'output backends',
            'label_style': 'label styles',
            'name_style': 'name styles',
            'sorting_style': 'sorting styles',
            'abbreviate_names': 'abbreviated names',
        }
        if style_language != 'python':
            for option, what_is_not_supported in not_supported_by_bibtex.iteritems(
            ):
                if options[option]:
                    self.opt_parser.error(
                        '%s are only supported by the Pythonic style engine (-l python)'
                        % what_is_not_supported)

        for encoding_option in 'bib_encoding', 'bst_encoding', 'output_encoding':
            if not options[encoding_option]:
                options[encoding_option] = encoding

        ext = path.splitext(filename)[1]
        if ext != '.aux':
            filename = path.extsep.join([filename, 'aux'])
        engine.make_bibliography(filename, **options)
コード例 #2
0
ファイル: __main__.py プロジェクト: tuxkp/ay250
class PybtexConvertCommandLine(CommandLine):
    prog = 'pybtex-convert'
    args = '[options] in_filename out_filename'
    description = 'convert between bibliography database formats'
    long_description = """

pybtex-convert converts bibliography database files between supported formats
(currently BibTeX, BibTeXML and YAML).

    """.strip()

    num_args = 2

    options = (
        (None, (
            standard_option('strict'),
            make_option(
                '-f',
                '--from',
                dest='from_format',
                help='input format (%plugin_choices)',
                metavar='FORMAT',
                type='load_plugin',
                plugin_group='pybtex.database.input',
            ),
            make_option(
                '-t',
                '--to',
                dest='to_format',
                help='output format (%plugin_choices)',
                metavar='FORMAT',
                type='load_plugin',
                plugin_group='pybtex.database.output',
            ),
            standard_option('keyless_entries'),
            make_option(
                '--preserve-case',
                dest='preserve_case',
                action='store_true',
                help='do not convert identifiers to lower case',
            ),
        )),
        ('Encoding options', (
            standard_option('encoding'),
            standard_option('input_encoding'),
            standard_option('output_encoding'),
        )),
    )
    option_defaults = {
        'keyless_entries': False,
        'preserve_case': False,
    }

    def run(self, from_filename, to_filename, encoding, input_encoding,
            output_encoding, keyless_entries, **options):
        from pybtex.database.convert import convert
        convert(from_filename,
                to_filename,
                input_encoding=input_encoding or encoding,
                output_encoding=output_encoding or encoding,
                parser_options={'keyless_entries': keyless_entries},
                **options)
コード例 #3
0
class PybtexFormatCommandLine(CommandLine):
    prog = 'pybtex-format'
    args = '[options] in_filename out_filename'
    description = 'format bibliography database as human-readable text'
    long_description = """

pybtex-format formats bibliography database as human-readable text.
    """.strip()
    num_args = 2

    options = (
        (None, (
            standard_option('strict'),
            standard_option('bib_format'),
            standard_option('output_backend'),
            standard_option('min_crossrefs'),
            standard_option('keyless_entries'),
            standard_option('style'),
        )),
        ('Pythonic style options', (
            standard_option('label_style'),
            standard_option('name_style'),
            standard_option('sorting_style'),
            standard_option('abbreviate_names'),
        )),
        ('Encoding options', (
            standard_option('encoding'),
            standard_option('input_encoding'),
            standard_option('output_encoding'),
        )),
    )
    option_defaults = {
        'keyless_entries': False,
    }

    def run(self, from_filename, to_filename, encoding, input_encoding,
            output_encoding, keyless_entries, **options):
        from pybtex.database.format import format_database

        format_database(from_filename,
                        to_filename,
                        input_encoding=input_encoding or encoding,
                        output_encoding=output_encoding or encoding,
                        parser_options={'keyless_entries': keyless_entries},
                        **options)