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
11 from librarian.cover import ImageCover
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('-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('-o', '--output-file', dest='output_file', metavar='FILE',
26 help='specifies the output file')
27 parser.add_option('-O', '--output-dir', dest='output_dir', metavar='DIR',
28 help='specifies the directory for output')
29 parser.add_option('-i', '--with-images', action='store_true', dest='images', default=False,
30 help='add images with <ilustr src="..."/>')
31 parser.add_option('-A', '--less-advertising', action='store_true', dest='less_advertising', default=False,
32 help='less advertising, for commercial purposes')
33 parser.add_option('-W', '--not-wl', action='store_true', dest='not_wl', default=False,
34 help='not a WolneLektury book')
35 parser.add_option('-c', '--cover', dest='cover', metavar='FILE',
36 help='specifies the cover file')
38 options, input_filenames = parser.parse_args()
40 if len(input_filenames) < 1:
46 for main_input in input_filenames:
49 path, fname = os.path.realpath(main_input).rsplit('/', 1)
50 provider = DirDocProvider(path)
52 output_dir = output_file = None
53 if options.output_dir:
54 output_dir = options.output_dir
55 elif options.output_file:
56 output_file = options.output_file
62 cover = ImageCover(options.cover)
66 flags.append('images')
67 if options.less_advertising:
68 flags.append('less-advertising')
70 flags.append('not-wl')
72 epub.transform(provider, file_path=main_input, output_dir=output_dir, output_file=output_file, make_dir=options.make_dir,
73 cover=cover, flags=flags)
75 print '%(file)s:%(name)s:%(message)s' % {
77 'name': e.__class__.__name__,