~stub/ubuntu/precise/calibre/devel

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/oeb/transforms/jacket.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-04-12 11:29:25 UTC
  • mfrom: (42.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110412112925-c7171kt2bb5rmft4
Tags: 0.7.50+dfsg-2
* debian/control: Build with libpodofo-dev to enable PDF metadata.
  (Closes: #619632)
* debian/control: Add libboost1.42-dev build dependency. Apparently it is
  needed in some setups. (Closes: #619807)
* debian/rules: Call dh_sip to generate a proper sip API dependency, to
  prevent crashes like #616372 for partial upgrades.
* debian/control: Bump python-qt4 dependency to >= 4.8.3-2, which reportedly
  fixes crashes on startup. (Closes: #619701, #620125)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
from calibre.ebooks.BeautifulSoup import BeautifulSoup
16
16
from calibre.ebooks.oeb.base import XPath, XHTML_NS, XHTML
17
17
from calibre.library.comments import comments_to_html
 
18
from calibre.utils.date import is_date_undefined
18
19
 
19
20
JACKET_XPATH = '//h:meta[@name="calibre-content" and @content="jacket"]'
20
21
 
109
110
 
110
111
def render_jacket(mi, output_profile,
111
112
        alt_title=_('Unknown'), alt_tags=[], alt_comments='',
112
 
        alt_publisher=('Unknown publisher')):
 
113
        alt_publisher=('')):
113
114
    css = P('jacket/stylesheet.css', data=True).decode('utf-8')
114
115
 
115
116
    try:
127
128
    try:
128
129
        publisher = mi.publisher if mi.publisher else alt_publisher
129
130
    except:
130
 
        publisher = _('Unknown publisher')
 
131
        publisher = ''
131
132
 
132
133
    try:
133
 
        pubdate = strftime(u'%Y', mi.pubdate.timetuple())
 
134
        if is_date_undefined(mi.pubdate):
 
135
            pubdate = ''
 
136
        else:
 
137
            pubdate = strftime(u'%Y', mi.pubdate.timetuple())
134
138
    except:
135
139
        pubdate = ''
136
140
 
175
179
        soup = BeautifulSoup(generated_html)
176
180
        if not series:
177
181
            series_tag = soup.find(attrs={'class':'cbj_series'})
178
 
            series_tag.extract()
 
182
            if series_tag is not None:
 
183
                series_tag.extract()
179
184
        if not rating:
180
185
            rating_tag = soup.find(attrs={'class':'cbj_rating'})
181
 
            rating_tag.extract()
 
186
            if rating_tag is not None:
 
187
                rating_tag.extract()
182
188
        if not tags:
183
189
            tags_tag = soup.find(attrs={'class':'cbj_tags'})
184
 
            tags_tag.extract()
 
190
            if tags_tag is not None:
 
191
                tags_tag.extract()
185
192
        if not pubdate:
186
 
            pubdate_tag = soup.find(attrs={'class':'cbj_pubdate'})
187
 
            pubdate_tag.extract()
 
193
            pubdate_tag = soup.find(attrs={'class':'cbj_pubdata'})
 
194
            if pubdate_tag is not None:
 
195
                pubdate_tag.extract()
188
196
        if output_profile.short_name != 'kindle':
189
197
            hr_tag = soup.find('hr', attrs={'class':'cbj_kindle_banner_hr'})
190
 
            hr_tag.extract()
 
198
            if hr_tag is not None:
 
199
                hr_tag.extract()
191
200
 
192
201
        return soup.renderContents(None)
193
202