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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL 3'
  6. __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
  7. __docformat__ = 'restructuredtext en'
  8. import os
  9. import re
  10. from lxml import etree
  11. from calibre.customize.conversion import OutputFormatPlugin
  12. from calibre import CurrentDir
  13. from calibre.customize.conversion import OptionRecommendation
  14. from urllib import unquote
  15.  
  16. class OEBOutput(OutputFormatPlugin):
  17.     name = 'OEB Output'
  18.     author = 'Kovid Goyal'
  19.     file_type = 'oeb'
  20.     recommendations = set([
  21.         ('pretty_print', True, OptionRecommendation.HIGH)])
  22.     
  23.     def convert(self, oeb_book, output_path, input_plugin, opts, log):
  24.         self.log = log
  25.         self.opts = opts
  26.         if not os.path.exists(output_path):
  27.             os.makedirs(output_path)
  28.         
  29.         OPF_MIME = OPF_MIME
  30.         NCX_MIME = NCX_MIME
  31.         PAGE_MAP_MIME = PAGE_MAP_MIME
  32.         import calibre.ebooks.oeb.base
  33.         CurrentDir(output_path).__enter__()
  34.         
  35.         try:
  36.             results = oeb_book.to_opf2(page_map = True)
  37.             for key in (OPF_MIME, NCX_MIME, PAGE_MAP_MIME):
  38.                 (href, root) = results.pop(key, [
  39.                     None,
  40.                     None])
  41.                 if root is not None:
  42.                     raw = etree.tostring(root, pretty_print = True, encoding = 'utf-8', xml_declaration = True)
  43.                     
  44.                     try:
  45.                         f = _[1]
  46.                         f.write(raw)
  47.                     finally:
  48.                         pass
  49.  
  50.                     continue
  51.                 open(href, 'wb').__exit__
  52.             
  53.             for item in oeb_book.manifest:
  54.                 path = os.path.abspath(unquote(item.href))
  55.                 dir = os.path.dirname(path)
  56.                 
  57.                 try:
  58.                     f = _[2]
  59.                     f.write(str(item))
  60.                 finally:
  61.                     pass
  62.  
  63.                 item.unload_data_from_memory(memory = path)
  64.         finally:
  65.             pass
  66.  
  67.  
  68.  
  69.