~ubuntu-branches/ubuntu/karmic/calibre/karmic

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/lrf/mobi/convert_from.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730124941-qjdsmri25zt8zocn
Tags: 0.6.3+dfsg-0ubuntu1
* New upstream release. Please see http://calibre.kovidgoyal.net/new_in_6/
  for the list of new features and changes.
* remove_postinstall.patch: Update for new version.
* build_debug.patch: Does not apply any more, disable for now. Might not be
  necessary any more.
* debian/copyright: Fix reference to versionless GPL.
* debian/rules: Drop obsolete dh_desktop call.
* debian/rules: Add workaround for weird Python 2.6 setuptools behaviour of
  putting compiled .so files into src/calibre/plugins/calibre/plugins
  instead of src/calibre/plugins.
* debian/rules: Drop hal fdi moving, new upstream version does not use hal
  any more. Drop hal dependency, too.
* debian/rules: Install udev rules into /lib/udev/rules.d.
* Add debian/calibre.preinst: Remove unmodified
  /etc/udev/rules.d/95-calibre.rules on upgrade.
* debian/control: Bump Python dependencies to 2.6, since upstream needs
  it now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env  python
2
 
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
3
 
 
4
 
__license__   = 'GPL v3'
5
 
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
6
 
''''''
7
 
 
8
 
import sys, tempfile, os, logging, shutil
9
 
 
10
 
from calibre import setup_cli_handlers, __appname__
11
 
from calibre.ebooks.mobi.reader import MobiReader
12
 
from calibre.ebooks.lrf import option_parser as lrf_option_parser
13
 
from calibre.ebooks.lrf.html.convert_from import process_file as html_process_file
14
 
 
15
 
def generate_html(mobifile, tdir):
16
 
    mr = MobiReader(mobifile)
17
 
    mr.extract_content(tdir)
18
 
    return mr.htmlfile
19
 
 
20
 
def process_file(path, options, logger=None):
21
 
    if logger is None:
22
 
        level = logging.DEBUG if options.verbose else logging.INFO
23
 
        logger = logging.getLogger('lit2lrf')
24
 
        setup_cli_handlers(logger, level)
25
 
    mobi = os.path.abspath(os.path.expanduser(path))
26
 
    tdir = tempfile.mkdtemp('mobi2lrf', __appname__)
27
 
    try:
28
 
        htmlfile = generate_html(mobi, tdir)
29
 
        if not options.output:
30
 
            ext = '.lrs' if options.lrs else '.lrf'
31
 
            options.output = os.path.abspath(os.path.basename(os.path.splitext(path)[0]) + ext)
32
 
        options.output = os.path.abspath(os.path.expanduser(options.output))
33
 
        options.use_spine = True
34
 
        html_process_file(htmlfile, options, logger=logger)
35
 
    finally:
36
 
        try:
37
 
            shutil.rmtree(tdir)
38
 
        except:
39
 
            logger.warning('Failed to delete temporary directory '+tdir)
40
 
 
41
 
def option_parser():
42
 
    return lrf_option_parser(
43
 
_('''Usage: %prog [options] mybook.mobi|prc
44
 
 
45
 
 
46
 
%prog converts mybook.mobi to mybook.lrf''')
47
 
        )
48
 
 
49
 
 
50
 
def main(args=sys.argv, logger=None):
51
 
    parser = option_parser()
52
 
    options, args = parser.parse_args(args)
53
 
    if len(args) != 2:            
54
 
        parser.print_help()
55
 
        print
56
 
        print 'No mobi file specified'
57
 
        return 1
58
 
    process_file(args[1], options, logger)
59
 
 
60
 
    return 0
61
 
 
62
 
if __name__ == '__main__':
63
 
    sys.exit(main())
 
 
b'\\ No newline at end of file'