home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1135 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.3 KB  |  46 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.compression.tcr import compress
  11.  
  12. class TCROutput(OutputFormatPlugin):
  13.     name = 'TCR Output'
  14.     author = 'John Schember'
  15.     file_type = 'tcr'
  16.     options = set([
  17.         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.')),
  18.         OptionRecommendation(name = 'compression_level', recommended_value = 5, level = OptionRecommendation.LOW, help = _('Specify the compression level to use. Scale 1 - 10. 1 being the lowest compression but the fastest and 10 being the highest compression but the slowest.'))])
  19.     
  20.     def convert(self, oeb_book, output_path, input_plugin, opts, log):
  21.         close = False
  22.         if not hasattr(output_path, 'write'):
  23.             close = True
  24.             if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path) != '':
  25.                 os.makedirs(os.path.dirname(output_path))
  26.             
  27.             out_stream = open(output_path, 'wb')
  28.         else:
  29.             out_stream = output_path
  30.         setattr(opts, 'flush_paras', False)
  31.         setattr(opts, 'max_line_length', 0)
  32.         setattr(opts, 'force_max_line_length', False)
  33.         setattr(opts, 'indent_paras', False)
  34.         writer = TXTMLizer(log)
  35.         txt = writer.extract_content(oeb_book, opts).encode(opts.output_encoding, 'replace')
  36.         log.info('Compressing text...')
  37.         txt = compress(txt, opts.compression_level)
  38.         out_stream.seek(0)
  39.         out_stream.truncate()
  40.         out_stream.write(txt)
  41.         if close:
  42.             out_stream.close()
  43.         
  44.  
  45.  
  46.