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('-c', '--with-cover', action='store_true', dest='with_cover', default=False,
22 help='create default cover')
23 parser.add_option('-d', '--make-dir', action='store_true', dest='make_dir', default=False,
24 help='create a directory for author and put the PDF in it')
25 parser.add_option('-t', '--save-tex', dest='save_tex', metavar='FILE',
26 help='path to save the intermediary LaTeX file to')
27 parser.add_option('-o', '--output-file', dest='output_file', metavar='FILE',
28 help='specifies the output file')
29 parser.add_option('-O', '--output-dir', dest='output_dir', metavar='DIR',
30 help='specifies the directory for output')
31 parser.add_option('-m', '--morefloats', dest='morefloats', metavar='old/new/none',
32 help='force morefloats in old (<1.0c), new (>=1.0c) or none')
33 (options, args) = parser.parse_args()
39 if options.output_dir and options.output_file:
40 raise ValueError("Either --output-dir or --output file should be specified")
43 for main_input in args:
44 path, fname = os.path.realpath(main_input).rsplit('/', 1)
45 provider = DirDocProvider(path)
46 output_file, output_dir = options.output_file, options.output_dir
47 if not (options.output_file or options.output_dir):
48 output_file = os.path.splitext(main_input)[0] + '.pdf'
52 doc = WLDocument.from_file(main_input, provider=provider)
53 pdf = doc.as_pdf(save_tex=options.save_tex,
54 cover=options.with_cover,
55 morefloats=options.morefloats)
57 doc.save_output_file(pdf,
58 output_file, options.output_dir, options.make_dir, 'pdf')
60 print '%(file)s:%(name)s:%(message)s; use -v to see more output' % {
62 'name': e.__class__.__name__,