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

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/oeb/transforms/guide.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
from __future__ import with_statement
 
4
 
 
5
__license__   = 'GPL v3'
 
6
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
 
7
__docformat__ = 'restructuredtext en'
 
8
 
 
9
 
 
10
class Clean(object):
 
11
    '''Clean up guide, leaving only a pointer to the cover'''
 
12
 
 
13
    def __call__(self, oeb, opts):
 
14
        from calibre.ebooks.oeb.base import urldefrag
 
15
        self.oeb, self.log, self.opts = oeb, oeb.log, opts
 
16
 
 
17
        if 'cover' not in self.oeb.guide:
 
18
            covers = []
 
19
            for x in ('other.ms-coverimage-standard',
 
20
                    'other.ms-titleimage-standard', 'other.ms-titleimage',
 
21
                    'other.ms-coverimage', 'other.ms-thumbimage-standard',
 
22
                    'other.ms-thumbimage'):
 
23
                if x in self.oeb.guide:
 
24
                    href = self.oeb.guide[x].href
 
25
                    item = self.oeb.manifest.hrefs[href]
 
26
                    covers.append([self.oeb.guide[x], len(item.data)])
 
27
            covers.sort(cmp=lambda x,y:cmp(x[1], y[1]), reverse=True)
 
28
            if covers:
 
29
                ref = covers[0][0]
 
30
                if len(covers) > 1:
 
31
                    self.log('Choosing %s:%s as the cover'%(ref.type, ref.href))
 
32
                ref.type = 'cover'
 
33
                self.oeb.guide.refs['cover'] = ref
 
34
 
 
35
        for x in list(self.oeb.guide):
 
36
            href = urldefrag(self.oeb.guide[x].href)[0]
 
37
            if x.lower() not in ('cover', 'titlepage', 'masthead', 'toc',
 
38
                    'title-page', 'copyright-page', 'start'):
 
39
                self.oeb.guide.remove(x)
 
40