home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1065 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.8 KB  |  73 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.  
  9. try:
  10.     from PIL import Image
  11.     Image
  12. except ImportError:
  13.     import Image
  14.  
  15. import cStringIO
  16. from calibre.customize.conversion import OutputFormatPlugin
  17. from calibre.customize.conversion import OptionRecommendation
  18. from calibre.ptempfile import TemporaryDirectory
  19. from calibre.utils.zipfile import ZipFile
  20. from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES
  21. from calibre.ebooks.pml.pmlml import PMLMLizer
  22.  
  23. class PMLOutput(OutputFormatPlugin):
  24.     name = 'PML Output'
  25.     author = 'John Schember'
  26.     file_type = 'pmlz'
  27.     options = set([
  28.         OptionRecommendation(name = 'output_encoding', recommended_value = 'cp1252', level = OptionRecommendation.LOW, help = _('Specify the character encoding of the output document. The default is cp1252.')),
  29.         OptionRecommendation(name = 'inline_toc', recommended_value = False, level = OptionRecommendation.LOW, help = _('Add Table of Contents to beginning of the book.'))])
  30.     
  31.     def convert(self, oeb_book, output_path, input_plugin, opts, log):
  32.         
  33.         try:
  34.             tdir = _[1]
  35.             pmlmlizer = PMLMLizer(log)
  36.             pml = unicode(pmlmlizer.extract_content(oeb_book, opts))
  37.             
  38.             try:
  39.                 out = _[2]
  40.                 out.write(pml.encode(opts.output_encoding, 'replace'))
  41.             finally:
  42.                 pass
  43.  
  44.             self.write_images(oeb_book.manifest, pmlmlizer.image_hrefs, tdir)
  45.             log.debug('Compressing output...')
  46.             pmlz = ZipFile(output_path, 'w')
  47.             pmlz.add_dir(tdir)
  48.         finally:
  49.             pass
  50.  
  51.  
  52.     
  53.     def write_images(self, manifest, image_hrefs, out_dir):
  54.         for item in manifest:
  55.             if item.media_type in OEB_RASTER_IMAGES and item.href in image_hrefs.keys():
  56.                 im = Image.open(cStringIO.StringIO(item.data))
  57.                 data = cStringIO.StringIO()
  58.                 im.save(data, 'PNG')
  59.                 data = data.getvalue()
  60.                 path = os.path.join(out_dir, image_hrefs[item.href])
  61.                 
  62.                 try:
  63.                     out = _[1]
  64.                     out.write(data)
  65.                 finally:
  66.                     pass
  67.  
  68.                 continue
  69.             open(path, 'wb').__exit__
  70.         
  71.  
  72.  
  73.