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
9 from librarian import pdf, DirDocProvider, ParseError
11 if __name__ == '__main__':
12 usage = """Usage: %prog [options] SOURCE [SOURCE...]
13 Convert SOURCE files to PDF format."""
15 parser = OptionParser(usage)
16 parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
17 help='make lots of noise and revert to default interaction in LaTeX')
18 parser.add_option('-d', '--make-dir', action='store_true', dest='make_dir', default=False,
19 help='create a directory for author and put the PDF in it')
20 parser.add_option('-t', '--save-tex', dest='save_tex', metavar='FILE',
21 help='path to save the intermediary LaTeX file to')
22 parser.add_option('-o', '--output-file', dest='output_file', metavar='FILE',
23 help='specifies the output file')
24 parser.add_option('-O', '--output-dir', dest='output_dir', metavar='DIR',
25 help='specifies the directory for output')
26 parser.add_option('-m', '--morefloats', dest='morefloats', metavar='old/new/none',
27 help='force morefloats in old (<1.0c), new (>=1.0c) or none')
28 (options, args) = parser.parse_args()
35 if options.output_dir and options.output_file:
36 raise ValueError("Either --output-dir or --output file should be specified")
38 for main_input in args:
41 path, fname = os.path.realpath(main_input).rsplit('/', 1)
42 provider = DirDocProvider(path)
44 output_file = output_dir = None
45 if options.output_dir:
46 output_dir = options.output_dir
47 elif options.output_file:
48 output_file = options.output_file
52 pdf.transform(provider,
54 output_file=output_file,
55 output_dir=output_dir,
56 verbose=options.verbose,
57 make_dir=options.make_dir,
58 save_tex=options.save_tex,
59 morefloats=options.morefloats
62 print '%(file)s:%(name)s:%(message)s; use -v to see more output' % {
64 'name': e.__class__.__name__,