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

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/mobi/input.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
from __future__ import with_statement
 
2
__license__ = 'GPL 3'
 
3
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
 
4
__docformat__ = 'restructuredtext en'
 
5
 
 
6
from calibre.customize.conversion import InputFormatPlugin
 
7
 
 
8
class MOBIInput(InputFormatPlugin):
 
9
 
 
10
    name        = 'MOBI Input'
 
11
    author      = 'Kovid Goyal'
 
12
    description = 'Convert MOBI files (.mobi, .prc, .azw) to HTML'
 
13
    file_types  = set(['mobi', 'prc', 'azw'])
 
14
 
 
15
    def convert(self, stream, options, file_ext, log,
 
16
                accelerators):
 
17
        from calibre.ebooks.mobi.reader import MobiReader
 
18
        from lxml import html
 
19
        mr = MobiReader(stream, log, options.input_encoding,
 
20
                        options.debug_input)
 
21
        parse_cache = {}
 
22
        mr.extract_content('.', parse_cache)
 
23
        raw = parse_cache.pop('calibre_raw_mobi_markup', False)
 
24
        if raw:
 
25
            if isinstance(raw, unicode):
 
26
                raw = raw.encode('utf-8')
 
27
            open('debug-raw.html', 'wb').write(raw)
 
28
        for f, root in parse_cache.items():
 
29
            with open(f, 'wb') as q:
 
30
                q.write(html.tostring(root, encoding='utf-8', method='xml',
 
31
                    include_meta_content_type=False))
 
32
                accelerators['pagebreaks'] = '//h:div[@class="mbp_pagebreak"]'
 
33
        return mr.created_opf_path