2 # -*- coding: utf-8 -*-
4 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
5 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
8 from optparse import OptionParser
10 from librarian import DirDocProvider, ParseError
11 from librarian.parser import WLDocument
14 if __name__ == '__main__':
15 usage = """Usage: %prog [options] SOURCE [SOURCE...]
16 Convert SOURCE files to PDF format."""
18 parser = OptionParser(usage)
19 parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
20 help='make lots of noise and revert to default interaction in LaTeX')
21 parser.add_option('-d', '--make-dir', action='store_true', dest='make_dir', default=False,
22 help='create a directory for author and put the PDF in it')
23 parser.add_option('-t', '--save-tex', dest='save_tex', metavar='FILE',
24 help='path to save the intermediary LaTeX file to')
25 parser.add_option('-o', '--output-file', dest='output_file', metavar='FILE',
26 help='specifies the output file')
27 parser.add_option('-O', '--output-dir', dest='output_dir', metavar='DIR',
28 help='specifies the directory for output')
29 parser.add_option('-m', '--morefloats', dest='morefloats', metavar='old/new/none',
30 help='force morefloats in old (<1.0c), new (>=1.0c) or none')
31 (options, args) = parser.parse_args()
37 if options.output_dir and options.output_file:
38 raise ValueError("Either --output-dir or --output file should be specified")
41 for main_input in args:
42 path, fname = os.path.realpath(main_input).rsplit('/', 1)
43 provider = DirDocProvider(path)
44 output_file, output_dir = options.output_file, options.output_dir
45 if not (options.output_file or options.output_dir):
46 output_file = os.path.splitext(main_input)[0] + '.pdf'
50 doc = WLDocument.from_file(main_input, provider=provider)
51 pdf = doc.as_pdf(save_tex=options.save_tex,
52 morefloats=options.morefloats)
54 doc.save_output_file(pdf,
55 output_file, options.output_dir, options.make_dir, 'pdf')
57 print '%(file)s:%(name)s:%(message)s; use -v to see more output' % {
59 'name': e.__class__.__name__,