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

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/__init__.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:
23
23
    pass
24
24
 
25
25
BOOK_EXTENSIONS = ['lrf', 'rar', 'zip', 'rtf', 'lit', 'txt', 'htm', 'xhtm',
26
 
                   'html', 'xhtml', 'pdf', 'prc', 'mobi', 'azw',
 
26
                   'html', 'xhtml', 'pdf', 'pdb', 'prc', 'mobi', 'azw', 'doc',
27
27
                   'epub', 'fb2', 'djvu', 'lrx', 'cbr', 'cbz', 'oebzip',
28
 
                   'rb', 'imp', 'odt']
 
28
                   'rb', 'imp', 'odt', 'chm', 'tpz', 'azw1']
29
29
 
30
30
class HTMLRenderer(object):
31
31
 
57
57
            self.loop.exit(0)
58
58
 
59
59
 
 
60
def extract_cover_from_embedded_svg(html, base, log):
 
61
    from lxml import etree
 
62
    from calibre.ebooks.oeb.base import XPath, SVG, XLINK
 
63
    root = etree.fromstring(html)
 
64
 
 
65
    svg = XPath('//svg:svg')(root)
 
66
    if len(svg) == 1 and len(svg[0]) == 1 and svg[0][0].tag == SVG('image'):
 
67
        image = svg[0][0]
 
68
        href = image.get(XLINK('href'), None)
 
69
        path = os.path.join(base, *href.split('/'))
 
70
        if href and os.access(path, os.R_OK):
 
71
            return open(path, 'rb').read()
 
72
 
 
73
def render_html_svg_workaround(path_to_html, log, width=590, height=750):
 
74
    from calibre.ebooks.oeb.base import SVG_NS
 
75
    raw = open(path_to_html, 'rb').read()
 
76
    data = None
 
77
    if SVG_NS in raw:
 
78
        try:
 
79
            data = extract_cover_from_embedded_svg(raw,
 
80
                   os.path.dirname(path_to_html), log)
 
81
        except:
 
82
            pass
 
83
    if data is None:
 
84
        renderer = render_html(path_to_html, width, height)
 
85
        data = getattr(renderer, 'data', None)
 
86
    return data
 
87
 
 
88
 
60
89
def render_html(path_to_html, width=590, height=750):
61
90
    from PyQt4.QtWebKit import QWebPage
62
91
    from PyQt4.Qt import QEventLoop, QPalette, Qt, SIGNAL, QUrl, QSize
 
92
    from calibre.gui2 import is_ok_to_use_qt
 
93
    if not is_ok_to_use_qt(): return None
63
94
    path_to_html = os.path.abspath(path_to_html)
64
95
    with CurrentDir(os.path.dirname(path_to_html)):
65
96
        page = QWebPage()