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 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 HTML 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('-i', '--ignore-dublin-core', action='store_false', dest='parse_dublincore', default=True,
24 help='don\'t try to parse dublin core metadata')
25 parser.add_option('-r', '--raw', action='store_false', dest='full_page', default=True,
26 help='outpu raw text for use in templates')
28 options, input_filenames = parser.parse_args()
30 if len(input_filenames) < 1:
35 for input_filename in input_filenames:
39 output_filename = os.path.splitext(input_filename)[0] + '.html'
41 doc = WLDocument.from_file(input_filename,
42 parse_dublincore=options.parse_dublincore)
43 flags = ('full-page',) if options.full_page else None
44 html = doc.as_html(flags=flags)
45 doc.save_output_file(html, output_path=output_filename)
47 print '%(file)s:%(name)s:%(message)s' % {
48 'file': input_filename,
49 'name': e.__class__.__name__,
53 print '%(file)s:%(name)s:%(message)s' % {
54 'file': input_filename,
55 'name': e.__class__.__name__,
56 'message': e.strerror,
58 except BaseException, e:
59 print '%(file)s:%(etype)s:%(message)s' % {
60 'file': input_filename,
61 'etype': e.__class__.__name__,