5 from librarian import text
6 from librarian import dcparser, ParseError
9 if __name__ == '__main__':
10 # Parse commandline arguments
11 usage = """Usage: %prog [options] SOURCE [SOURCE...]
12 Convert SOURCE files to TXT format."""
14 parser = optparse.OptionParser(usage=usage)
16 parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
17 help='print status messages to stdout')
18 parser.add_option('-w', '--wrap', action='store', type='int', dest='wrapping', default=0,
19 help='set line wrap column')
20 parser.add_option('-i', '--ignore-dublin-core', action='store_false', dest='parse_dublincore', default=True,
21 help='don\'t try to parse dublin core metadata')
23 options, input_filenames = parser.parse_args()
25 if len(input_filenames) < 1:
30 for input_filename in input_filenames:
34 output_filename = os.path.splitext(input_filename)[0] + '.txt'
36 text.transform(input_filename, output_filename, parse_dublincore=options.parse_dublincore,
37 wrapping=str(options.wrapping))
39 print '%(file)s:%(name)s:%(message)s' % {
40 'file': input_filename,
41 'name': e.__class__.__name__,
45 print '%(file)s:%(name)s:%(message)s' % {
46 'file': input_filename,
47 'name': e.__class__.__name__,
48 'message': e.strerror,
50 except BaseException, e:
51 print '%(file)s:%(etype)s:%(message)s' % {
52 'file': input_filename,
53 'etype': e.__class__.__name__,