'Generate the HTML Description header from template.
Create HTML Description from book metadata and template.
Called by generate_html_descriptions()
Args:
book (dict): book metadata
Return:
soup (BeautifulSoup): HTML Description for book'

def generate_html_description_header(self, book):

    from calibre.ebooks.oeb.base import XHTML_NS
    def _generate_html():
        args = dict(author=author, author_prefix=author_prefix, comments=comments, css=css, formats=formats, genres=genres, note_content=note_content, note_source=note_source, pubdate=pubdate, publisher=publisher, pubmonth=pubmonth, pubyear=pubyear, rating=rating, series=series, series_index=series_index, thumb=thumb, title=title, title_str=title_str, xmlns=XHTML_NS)
        for (k, v) in args.iteritems():
            if isbytestring(v):
                args[k] = v.decode('utf-8')
        generated_html = P('catalog/template.xhtml', data=True).decode('utf-8').format(**args)
        generated_html = substitute_entites(generated_html)
        return BeautifulSoup(generated_html)
    css = P('catalog/stylesheet.css', data=True).decode('utf-8')
    title_str = title = escape(book['title'])
    series = ''
    series_index = ''
    if book['series']:
        series = escape(book['series'])
        series_index = str(book['series_index'])
        if series_index.endswith('.0'):
            series_index = series_index[:(-2)]
    author = book['author']
    if book['prefix']:
        author_prefix = ((book['prefix'] + '    ') + _('by    '))
    elif (self.opts.connected_kindle and (book['id'] in self.bookmarked_books)):
        author_prefix = ((self.SYMBOL_READING + '    ') + _('by    '))
    else:
        author_prefix = _('by    ')
    genres = ''
    if ('genres' in book):
        _soup = BeautifulSoup('')
        genresTag = Tag(_soup, 'p')
        gtc = 0
        for (i, tag) in enumerate(sorted(book.get('genres', []))):
            aTag = Tag(_soup, 'a')
            if self.opts.generate_genres:
                try:
                    aTag['href'] = ('Genre_%s.html' % self.genre_tags_dict[tag])
                except KeyError:
                    pass
            aTag.insert(0, escape(NavigableString(tag)))
            genresTag.insert(gtc, aTag)
            gtc += 1
            if (i < (len(book['genres']) - 1)):
                genresTag.insert(gtc, NavigableString('    &middot;    '))
                gtc += 1
        genres = genresTag.renderContents()
    formats = []
    if ('formats' in book):
        for format in sorted(book['formats']):
            formats.append(format.rpartition('.')[2].upper())
        formats = '    &middot;    '.join(formats)
    if book['date']:
        pubdate = book['date']
        (pubmonth, pubyear) = pubdate.split()
    else:
        pubdate = pubyear = pubmonth = ''
    _soup = BeautifulSoup('<html>', selfClosingTags=['img'])
    thumb = Tag(_soup, 'img')
    if (('cover' in book) and book['cover']):
        thumb['src'] = ('../images/thumbnail_%d.jpg' % int(book['id']))
    else:
        thumb['src'] = '../images/thumbnail_default.jpg'
    thumb['alt'] = 'cover    thumbnail'
    publisher = '    '
    if ('publisher' in book):
        publisher = book['publisher']
    stars = (int(book['rating']) / 2)
    rating = ''
    if stars:
        star_string = (self.SYMBOL_FULL_RATING * stars)
        empty_stars = (self.SYMBOL_EMPTY_RATING * (5 - stars))
        rating = ('%s%s    <br/>' % (star_string, empty_stars))
    note_source = ''
    note_content = ''
    if ('notes' in book):
        note_source = book['notes']['source']
        note_content = book['notes']['content']
    comments = ''
    if (('description' in book) and (book['description'] > '')):
        comments = book['description']
    soup = _generate_html()
    body = soup.find('body')
    btc = 0
    aTag = Tag(soup, 'a')
    aTag['id'] = ('book%d' % int(book['id']))
    divTag = Tag(soup, 'div')
    divTag.insert(0, aTag)
    body.insert(btc, divTag)
    btc += 1
    aTag = body.find('a', attrs={'class': 'series_id'})
    if aTag:
        if book['series']:
            if self.opts.generate_series:
                aTag['href'] = ('%s.html#%s' % ('BySeries', self.generate_series_anchor(book['series'])))
        else:
            aTag.extract()
    aTag = body.find('a', attrs={'class': 'author'})
    if (self.opts.generate_authors and aTag):
        aTag['href'] = ('%s.html#%s' % ('ByAlphaAuthor', self.generate_author_anchor(book['author'])))
    if (publisher == '    '):
        publisherTag = body.find('td', attrs={'class': 'publisher'})
        if publisherTag:
            publisherTag.contents[0].replaceWith('&nbsp;')
    if (not genres):
        genresTag = body.find('p', attrs={'class': 'genres'})
        if genresTag:
            genresTag.extract()
    if (not formats):
        formatsTag = body.find('p', attrs={'class': 'formats'})
        if formatsTag:
            formatsTag.extract()
    if (note_content == ''):
        tdTag = body.find('td', attrs={'class': 'notes'})
        if tdTag:
            tdTag.contents[0].replaceWith('&nbsp;')
    emptyTags = body.findAll('td', attrs={'class': 'empty'})
    for mt in emptyTags:
        newEmptyTag = Tag(BeautifulSoup(), 'td')
        newEmptyTag.insert(0, NavigableString('&nbsp;'))
        mt.replaceWith(newEmptyTag)
    return soup
