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)
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)
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, ( make_option( '--min-crossrefs', type='int', dest='min_crossrefs', help='include item after NUMBER crossrefs; default 2', metavar='NUMBER', ), make_option( '--terse', dest='verbose', action='store_false', help='ignored for compatibility with BibTeX', ), make_option( '-f', '--bibliography-format', dest='bib_format', help='bibliograpy format (%plugin_choices)', type='load_plugin', plugin_group='pybtex.database.input', metavar='FORMAT', ), make_option( '-b', '--output-backend', dest='output_backend', help='output backend (%plugin_choices)', type='load_plugin', plugin_group='pybtex.backends', metavar='BACKEND', ), make_option( '-l', '--style-language', dest='style_language', help='style definition language to use (bibtex or python)', metavar='LANGUAGE', ), )), ('Pythonic style options', ( make_option( '--label-style', dest='label_style', help='label formatting style (%plugin_choices)', type='load_plugin', plugin_group='pybtex.style.labels', metavar='STYLE', ), make_option( '--name-style', dest='name_style', help='name formatting style (%plugin_choices)', type='load_plugin', plugin_group='pybtex.style.names', metavar='STYLE', ), make_option( '--sorting-style', dest='sorting_style', help='sorting style (%plugin_choices)', type='load_plugin', plugin_group='pybtex.style.sorting', metavar='STYLE', ), make_option( '--abbreviate-names', action='store_true', dest='abbreviate_names', help='use abbreviated name formatting style', ), )), ('Encoding options', ( make_option( '-e', '--encoding', dest='encoding', metavar='ENCODING', help='default encoding', ), make_option('--bibtex-encoding', dest='bib_encoding', metavar='ENCODING'), make_option('--bst-encoding', dest='bst_encoding', metavar='ENCODING'), make_option('--output-encoding', dest='output_encoding', metavar='ENCODING'), )), ) option_defaults = { 'style_language': 'bibtex', 'min_crossrefs': 2, } legacy_options = '-help', '-version', '-min-crossrefs', '-terse' def run(self, options, args): from pybtex.plugin import find_plugin filename = args[0] ext = path.splitext(filename)[1] if ext != '.aux': filename = path.extsep.join([filename, 'aux']) 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 options.style_language != 'python': for option, what_is_not_supported in not_supported_by_bibtex.iteritems(): if getattr(options, option): self.opt_parser.error( '%s are only supported by the Pythonic style engine (-l python)' % what_is_not_supported ) if options.style_language == 'bibtex': from pybtex import bibtex as engine elif options.style_language == 'python': import pybtex as engine else: self.opt_parser.error('unknown style language %s' % options.style_language) for encoding_option in 'bib_encoding', 'bst_encoding', 'output_encoding': if not getattr(options, encoding_option): setattr(options, encoding_option, options.encoding) kwargs = {} uninteresting_options = 'verbose', 'style_language' kwargs = dict( (key, value) for (key, value) in options.__dict__.iteritems() if key not in uninteresting_options ) engine.make_bibliography(filename, **kwargs)