home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1140 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.0 KB  |  45 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL 3'
  5. __copyright__ = '2009, John Schember <john@nachtimwald.com>'
  6. __docformat__ = 'restructuredtext en'
  7. import os
  8. from calibre.customize.conversion import OutputFormatPlugin, OptionRecommendation
  9. from calibre.ebooks.txt.txtml import TXTMLizer
  10. from calibre.ebooks.txt.newlines import TxtNewlines, specified_newlines
  11.  
  12. class TXTOutput(OutputFormatPlugin):
  13.     name = 'TXT Output'
  14.     author = 'John Schember'
  15.     file_type = 'txt'
  16.     options = set([
  17.         OptionRecommendation(name = 'newline', recommended_value = 'system', level = OptionRecommendation.LOW, short_switch = 'n', choices = TxtNewlines.NEWLINE_TYPES.keys(), help = _("Type of newline to use. Options are %s. Default is 'system'. Use 'old_mac' for compatibility with Mac OS 9 and earlier. For Mac OS X use 'unix'. 'system' will default to the newline type used by this OS.") % sorted(TxtNewlines.NEWLINE_TYPES.keys())),
  18.         OptionRecommendation(name = 'output_encoding', recommended_value = 'utf-8', level = OptionRecommendation.LOW, help = _('Specify the character encoding of the output document. The default is utf-8. Note: This option is not honored by all formats.')),
  19.         OptionRecommendation(name = 'inline_toc', recommended_value = False, level = OptionRecommendation.LOW, help = _('Add Table of Contents to beginning of the book.')),
  20.         OptionRecommendation(name = 'max_line_length', recommended_value = 0, level = OptionRecommendation.LOW, help = _('The maximum number of characters per line. This splits on the first space before the specified value. If no space is found the line will be broken at the space after and will exceed the specified value. Also, there is a minimum of 25 characters. Use 0 to disable line splitting.')),
  21.         OptionRecommendation(name = 'force_max_line_length', recommended_value = False, level = OptionRecommendation.LOW, help = _('Force splitting on the max-line-length value when no space is present. Also allows max-line-length to be below the minimum'))])
  22.     
  23.     def convert(self, oeb_book, output_path, input_plugin, opts, log):
  24.         writer = TXTMLizer(log)
  25.         txt = writer.extract_content(oeb_book, opts)
  26.         log.debug('\tReplacing newlines with selected type...')
  27.         txt = specified_newlines(TxtNewlines(opts.newline).newline, txt)
  28.         close = False
  29.         if not hasattr(output_path, 'write'):
  30.             close = True
  31.             if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path) != '':
  32.                 os.makedirs(os.path.dirname(output_path))
  33.             
  34.             out_stream = open(output_path, 'wb')
  35.         else:
  36.             out_stream = output_path
  37.         out_stream.seek(0)
  38.         out_stream.truncate()
  39.         out_stream.write(txt.encode(opts.output_encoding, 'replace'))
  40.         if close:
  41.             out_stream.close()
  42.         
  43.  
  44.  
  45.