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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL v3'
  6. __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
  7. __docformat__ = 'restructuredtext en'
  8. import sys
  9. import os
  10. import glob
  11. import logging
  12. from calibre.ebooks.epub.from_any import any2epub, formats, USAGE
  13. from calibre.ebooks.epub import config as common_config
  14. from calibre.ptempfile import TemporaryDirectory
  15. from calibre.ebooks.lit.writer import oeb2lit
  16.  
  17. def config(defaults = None):
  18.     c = common_config(defaults = defaults, name = 'lit')
  19.     return c
  20.  
  21.  
  22. def option_parser(usage = USAGE):
  23.     return config().option_parser(usage = usage % ('LIT', formats()))
  24.  
  25.  
  26. def any2lit(opts, path):
  27.     ext = os.path.splitext(path)[1]
  28.     if not ext:
  29.         raise ValueError('Unknown file type: ' + path)
  30.     ext
  31.     ext = ext.lower()[1:]
  32.     if opts.output is None:
  33.         opts.output = os.path.splitext(os.path.basename(path))[0] + '.lit'
  34.     
  35.     opts.output = os.path.abspath(opts.output)
  36.     orig_output = opts.output
  37.     
  38.     try:
  39.         tdir = _[1]
  40.         oebdir = os.path.join(tdir, 'oeb')
  41.         os.mkdir(oebdir)
  42.         opts.output = os.path.join(tdir, 'dummy.epub')
  43.         opts.profile = 'None'
  44.         orig_bfs = opts.base_font_size2
  45.         opts.base_font_size2 = 0
  46.         any2epub(opts, path, create_epub = False, oeb_cover = True, extract_to = oebdir)
  47.         opts.base_font_size2 = orig_bfs
  48.         opf = glob.glob(os.path.join(oebdir, '*.opf'))[0]
  49.         opts.output = orig_output
  50.         logging.getLogger('html2epub').info(_('Creating LIT file from EPUB...'))
  51.         oeb2lit(opts, opf)
  52.     finally:
  53.         pass
  54.  
  55.  
  56.  
  57. def main(args = sys.argv):
  58.     parser = option_parser()
  59.     (opts, args) = parser.parse_args(args)
  60.     if len(args) < 2:
  61.         parser.print_help()
  62.         print 'No input file specified.'
  63.         return 1
  64.     any2lit(opts, args[1])
  65.     return 0
  66.  
  67. if __name__ == '__main__':
  68.     sys.exit(main())
  69.  
  70.