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 html, ParseError
13 if __name__ == '__main__':
14 # Parse commandline arguments
15 usage = """Usage: %prog [options] SOURCE [SOURCE...]
16 Convert SOURCE files to HTML 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('-i', '--ignore-dublin-core', action='store_false', dest='parse_dublincore', default=True,
23 help='don\'t try to parse dublin core metadata')
25 options, input_filenames = parser.parse_args()
27 if len(input_filenames) < 1:
32 for input_filename in input_filenames:
36 output_filename = os.path.splitext(input_filename)[0] + '.html'
38 html.transform(input_filename, output_filename, parse_dublincore=options.parse_dublincore,\
41 print '%(file)s:%(name)s:%(message)s' % {
42 'file': input_filename,
43 'name': e.__class__.__name__,
44 'message': e.message.encode('utf-8')
47 print '%(file)s:%(name)s:%(message)s' % {
48 'file': input_filename,
49 'name': e.__class__.__name__,
50 'message': e.strerror,
52 except BaseException, e:
53 print '%(file)s:%(etype)s:%(message)s' % {
54 'file': input_filename,
55 'etype': e.__class__.__name__,
56 'message': e.message.encode('utf-8'),