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.
10 from librarian import DirDocProvider, ParseError
11 from librarian.parser import WLDocument
14 if __name__ == '__main__':
15 # Parse commandline arguments
16 usage = """Usage: %prog [options] SOURCE [SOURCE...]
17 Convert SOURCE files to EPUB format."""
19 parser = optparse.OptionParser(usage=usage)
21 parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
22 help='print status messages to stdout')
23 parser.add_option('-c', '--with-cover', action='store_true', dest='with_cover', default=False,
24 help='create default cover')
25 parser.add_option('-d', '--make-dir', action='store_true', dest='make_dir', default=False,
26 help='create a directory for author and put the PDF in it')
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')
32 options, input_filenames = parser.parse_args()
34 if len(input_filenames) < 1:
40 for main_input in input_filenames:
44 path, fname = os.path.realpath(main_input).rsplit('/', 1)
45 provider = DirDocProvider(path)
46 if not (options.output_file or options.output_dir):
47 output_file = os.path.splitext(main_input)[0] + '.epub'
51 doc = WLDocument.from_file(main_input, provider=provider)
52 epub = doc.as_epub(cover=options.with_cover)
54 doc.save_output_file(epub,
55 output_file, options.output_dir, options.make_dir, 'epub')
58 print '%(file)s:%(name)s:%(message)s' % {
60 'name': e.__class__.__name__,