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 EPUB 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 (options, args) = parser.parse_args()
33 for main_input in args:
36 path, fname = os.path.realpath(main_input).rsplit('/', 1)
37 provider = DirDocProvider(path)
39 output_dir = output_file = None
40 if options.output_dir:
41 output_dir = options.output_dir
42 elif options.output_file:
43 output_file = options.output_file
47 pdf.transform(provider, file_path=main_input, output_file=output_file, output_dir=output_dir, make_dir=options.make_dir, verbose=options.verbose, save_tex=options.save_tex)
49 print '%(file)s:%(name)s:%(message)s' % {
51 'name': e.__class__.__name__,