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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
  6. __docformat__ = 'restructuredtext en'
  7. import sys
  8. import os
  9. from calibre.utils.config import OptionParser
  10. from calibre.ptempfile import TemporaryDirectory
  11. from calibre import CurrentDir
  12. from calibre.utils.zipfile import ZipFile
  13. from calibre.utils.logging import default_log
  14. from calibre.customize.ui import epub_fixers
  15. from calibre.ebooks.epub.fix.container import Container
  16.  
  17. def option_parser():
  18.     parser = OptionParser(usage = _('%prog [options] file.epub\n\nFix common problems in EPUB files that can cause them to be rejected by poorly designed publishing services.\n\nBy default, no fixing is done and messages are printed out for each error detected. Use the options to control which errors are automatically fixed.'))
  19.     for fixer in epub_fixers():
  20.         fixer.add_options_to_parser(parser)
  21.     
  22.     return parser
  23.  
  24.  
  25. def run(epub, opts, log):
  26.     
  27.     try:
  28.         tdir = _[1]
  29.         CurrentDir(tdir).__enter__()
  30.         
  31.         try:
  32.             zf = ZipFile(epub)
  33.             zf.extractall()
  34.             zf.close()
  35.             container = Container(tdir, log)
  36.             for fixer in epub_fixers():
  37.                 fix = getattr(opts, fixer.fix_name, False)
  38.                 fixer.run(container, opts, log, fix = fix)
  39.             
  40.             container.write(epub)
  41.         finally:
  42.             pass
  43.  
  44.     finally:
  45.         pass
  46.  
  47.  
  48.  
  49. def main(args = sys.argv):
  50.     parser = option_parser()
  51.     (opts, args) = parser.parse_args(args)
  52.     if len(args) != 2:
  53.         parser.print_help()
  54.         print 
  55.         default_log.error(_('You must specify an epub file'))
  56.         return None
  57.     epub = os.path.abspath(args[1])
  58.     run(epub, opts, default_log)
  59.  
  60. if __name__ == '__main__':
  61.     main()
  62.  
  63.