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')
21 options, input_filenames = parser.parse_args()
23 if len(input_filenames) < 1:
28 for input_filename in input_filenames:
32 output_filename = os.path.splitext(input_filename)[0] + '.txt'
34 text.transform(input_filename, output_filename, wrapping=str(options.wrapping))
36 print '%(file)s:%(name)s:%(message)s' % {
37 'file': input_filename,
38 'name': e.__class__.__name__,
42 print '%(file)s:%(name)s:%(message)s' % {
43 'file': input_filename,
44 'name': e.__class__.__name__,
45 'message': e.strerror,
47 except BaseException, e:
48 print '%(file)s:%(etype)s:%(message)s' % {
49 'file': input_filename,
50 'etype': e.__class__.__name__,