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 text
 
  27 from librarian import dcparser, ParseError
 
  30 if __name__ == '__main__':
 
  31     # Parse commandline arguments
 
  32     usage = """Usage: %prog [options] SOURCE [SOURCE...]
 
  33     Convert SOURCE files to TXT format."""
 
  35     parser = optparse.OptionParser(usage=usage)
 
  37     parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
 
  38         help='print status messages to stdout')
 
  39     parser.add_option('-w', '--wrap', action='store', type='int', dest='wrapping', default=0,
 
  40         help='set line wrap column')
 
  41     parser.add_option('-i', '--ignore-dublin-core', action='store_false', dest='parse_dublincore', default=True,
 
  42         help='don\'t try to parse dublin core metadata')
 
  44     options, input_filenames = parser.parse_args()
 
  46     if len(input_filenames) < 1:
 
  51     for input_filename in input_filenames:
 
  55         output_filename = os.path.splitext(input_filename)[0] + '.txt'
 
  57             text.transform(input_filename, output_filename, parse_dublincore=options.parse_dublincore,
 
  58                 wrapping=str(options.wrapping))
 
  60             print '%(file)s:%(name)s:%(message)s' % {
 
  61                 'file': input_filename,
 
  62                 'name': e.__class__.__name__,
 
  66             print '%(file)s:%(name)s:%(message)s' % {
 
  67                 'file': input_filename,
 
  68                 'name': e.__class__.__name__,
 
  69                 'message': e.strerror,
 
  71         except BaseException, e:
 
  72             print '%(file)s:%(etype)s:%(message)s' % {
 
  73                 'file': input_filename,
 
  74                 'etype': e.__class__.__name__,