home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1029 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.3 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.pdb import PDBError, get_writer, FORMAT_WRITERS
  10.  
  11. class PDBOutput(OutputFormatPlugin):
  12.     name = 'PDB Output'
  13.     author = 'John Schember'
  14.     file_type = 'pdb'
  15.     options = set([
  16.         OptionRecommendation(name = 'format', recommended_value = 'doc', level = OptionRecommendation.LOW, short_switch = 'f', choices = FORMAT_WRITERS.keys(), help = _('Format to use inside the pdb container. Choices are:') + ' %s' % FORMAT_WRITERS.keys()),
  17.         OptionRecommendation(name = 'output_encoding', recommended_value = 'cp1252', level = OptionRecommendation.LOW, help = _('Specify the character encoding of the output document. The default is cp1252. Note: This option is not honored by all formats.')),
  18.         OptionRecommendation(name = 'inline_toc', recommended_value = False, level = OptionRecommendation.LOW, help = _('Add Table of Contents to beginning of the book.'))])
  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.         Writer = get_writer(opts.format)
  31.         if Writer is None:
  32.             raise PDBError('No writer available for format %s.' % format)
  33.         Writer is None
  34.         setattr(opts, 'max_line_length', 0)
  35.         setattr(opts, 'force_max_line_length', False)
  36.         writer = Writer(opts, log)
  37.         out_stream.seek(0)
  38.         out_stream.truncate()
  39.         writer.write_content(oeb_book, out_stream, oeb_book.metadata)
  40.         if close:
  41.             out_stream.close()
  42.         
  43.  
  44.  
  45.