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 epub, DirDocProvider, ParseError
13 if __name__ == '__main__':
14 # Parse commandline arguments
15 usage = """Usage: %prog [options] SOURCE [SOURCE...]
16 Convert SOURCE files to EPUB format."""
18 parser = optparse.OptionParser(usage=usage)
20 parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
21 help='print status messages to stdout')
22 parser.add_option('-d', '--make-dir', action='store_true', dest='make_dir', default=False,
23 help='create a directory for author and put the PDF in it')
24 parser.add_option('-o', '--output-file', dest='output_file', metavar='FILE',
25 help='specifies the output file')
26 parser.add_option('-O', '--output-dir', dest='output_dir', metavar='DIR',
27 help='specifies the directory for output')
29 options, input_filenames = parser.parse_args()
31 if len(input_filenames) < 1:
37 for main_input in input_filenames:
40 path, fname = os.path.realpath(main_input).rsplit('/', 1)
41 provider = DirDocProvider(path)
43 output_dir = output_file = None
44 if options.output_dir:
45 output_dir = options.output_dir
46 elif options.output_file:
47 output_file = options.output_file
51 epub.transform(provider, file_path=main_input, output_dir=output_dir, output_file=output_file, make_dir=options.make_dir)
53 print '%(file)s:%(name)s:%(message)s' % {
55 'name': e.__class__.__name__,