2 # -*- coding: utf-8 -*-
4 # This file is part of Librarian.
6 # Copyright © 2008,2009,2010 Fundacja Nowoczesna Polska <fundacja@nowoczesnapolska.org.pl>
8 # For full list of contributors see AUTHORS file.
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Affero General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU Affero General Public License for more details.
20 # You should have received a copy of the GNU Affero General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 from librarian import html, ParseError
29 if __name__ == '__main__':
30 # Parse commandline arguments
31 usage = """Usage: %prog [options] SOURCE [SOURCE...]
32 Convert SOURCE files to HTML format."""
34 parser = optparse.OptionParser(usage=usage)
36 parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
37 help='print status messages to stdout')
38 parser.add_option('-i', '--ignore-dublin-core', action='store_false', dest='parse_dublincore', default=True,
39 help='don\'t try to parse dublin core metadata')
41 options, input_filenames = parser.parse_args()
43 if len(input_filenames) < 1:
48 for input_filename in input_filenames:
52 output_filename = os.path.splitext(input_filename)[0] + '.html'
54 html.transform(input_filename, output_filename, parse_dublincore=options.parse_dublincore,\
57 print '%(file)s:%(name)s:%(message)s' % {
58 'file': input_filename,
59 'name': e.__class__.__name__,
60 'message': e.message.encode('utf-8')
63 print '%(file)s:%(name)s:%(message)s' % {
64 'file': input_filename,
65 'name': e.__class__.__name__,
66 'message': e.strerror,
68 except BaseException, e:
69 print '%(file)s:%(etype)s:%(message)s' % {
70 'file': input_filename,
71 'etype': e.__class__.__name__,
72 'message': e.message.encode('utf-8'),