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 MOBI 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')
30 options, input_filenames = parser.parse_args()
32 if len(input_filenames) < 1:
38 for main_input in input_filenames:
39 path, fname = os.path.realpath(main_input).rsplit('/', 1)
40 provider = DirDocProvider(path)
41 if not (options.output_file or options.output_dir):
42 output_file = os.path.splitext(main_input)[0] + '.mobi'
46 doc = WLDocument.from_file(main_input, provider=provider)
49 doc.save_output_file(mobi,
50 output_file, options.output_dir, options.make_dir, 'mobi')
52 print '%(file)s:%(name)s:%(message)s' % {
54 'name': e.__class__.__name__,