home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_892 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.7 KB  |  38 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.fb2.fb2ml import FB2MLizer
  10.  
  11. class FB2Output(OutputFormatPlugin):
  12.     name = 'FB2 Output'
  13.     author = 'John Schember'
  14.     file_type = 'fb2'
  15.     options = set([
  16.         OptionRecommendation(name = 'inline_toc', recommended_value = False, level = OptionRecommendation.LOW, help = _('Add Table of Contents to beginning of the book.'))])
  17.     
  18.     def convert(self, oeb_book, output_path, input_plugin, opts, log):
  19.         fb2mlizer = FB2MLizer(log)
  20.         fb2_content = fb2mlizer.extract_content(oeb_book, opts)
  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.         out_stream.seek(0)
  31.         out_stream.truncate()
  32.         out_stream.write(fb2_content.encode('utf-8', 'replace'))
  33.         if close:
  34.             out_stream.close()
  35.         
  36.  
  37.  
  38.