Catalog generation: Do not abort on author sort mismatches when generating an EPUB catalog

This commit is contained in:
Kovid Goyal 2011-02-15 10:52:18 -07:00
commit 73a5003a4c
2 changed files with 46 additions and 32 deletions

View File

@ -24,6 +24,7 @@ from calibre.utils.logging import Log
from calibre.utils.zipfile import ZipFile from calibre.utils.zipfile import ZipFile
from PIL import Image as PILImage from PIL import Image as PILImage
from lxml import etree
if isosx: if isosx:
try: try:
@ -2515,23 +2516,23 @@ class ITUNES(DriverBase):
fnames = zf_opf.namelist() fnames = zf_opf.namelist()
opf = [x for x in fnames if '.opf' in x][0] opf = [x for x in fnames if '.opf' in x][0]
if opf: if opf:
opf_raw = cStringIO.StringIO(zf_opf.read(opf)) opf_tree = etree.fromstring(zf_opf.read(opf))
soup = BeautifulSoup(opf_raw.getvalue()) ns_map = opf_tree.nsmap.keys()
opf_raw.close() for item in ns_map:
ns = opf_tree.nsmap[item]
# Touch existing calibre timestamp md_el = opf_tree.find(".//{%s}metadata" % ns)
md = soup.find('metadata') if md_el is not None:
if md: ts = md_el.find('.//{%s}meta[@name="calibre:timestamp"]')
ts = md.find('meta',attrs={'name':'calibre:timestamp'}) if ts:
if ts: timestamp = ts.get('content')
timestamp = ts['content'] old_ts = parse_date(timestamp)
old_ts = parse_date(timestamp) metadata.timestamp = datetime.datetime(old_ts.year, old_ts.month, old_ts.day, old_ts.hour,
metadata.timestamp = datetime.datetime(old_ts.year, old_ts.month, old_ts.day, old_ts.hour, old_ts.minute, old_ts.second, old_ts.microsecond+1, old_ts.tzinfo)
old_ts.minute, old_ts.second, old_ts.microsecond+1, old_ts.tzinfo) else:
else: metadata.timestamp = now()
metadata.timestamp = now() if DEBUG:
if DEBUG: self.log.info(" add timestamp: %s" % metadata.timestamp)
self.log.info(" add timestamp: %s" % metadata.timestamp) break
else: else:
metadata.timestamp = now() metadata.timestamp = now()
if DEBUG: if DEBUG:
@ -2839,7 +2840,7 @@ class ITUNES(DriverBase):
def _xform_metadata_via_plugboard(self, book, format): def _xform_metadata_via_plugboard(self, book, format):
''' Transform book metadata from plugboard templates ''' ''' Transform book metadata from plugboard templates '''
if DEBUG: if DEBUG:
self.log.info(" ITUNES._update_metadata_from_plugboard()") self.log.info(" ITUNES._xform_metadata_via_plugboard()")
if self.plugboard_func: if self.plugboard_func:
pb = self.plugboard_func(self.DEVICE_PLUGBOARD_NAME, format, self.plugboards) pb = self.plugboard_func(self.DEVICE_PLUGBOARD_NAME, format, self.plugboards)

View File

@ -1481,23 +1481,36 @@ class EPUB_MOBI(CatalogPlugin):
current_author = authors[0] current_author = authors[0]
for (i,author) in enumerate(authors): for (i,author) in enumerate(authors):
if author != current_author and i: if author != current_author and i:
# Exit if author matches previous, but author_sort doesn't match
if author[0] == current_author[0]: if author[0] == current_author[0]:
error_msg = _(''' if self.opts.fmt == 'mobi':
Inconsistent Author Sort values for Author '{0}': # Exit if building MOBI
'{1}' <> '{2}', error_msg = _(
unable to build catalog.\n '''Inconsistent Author Sort values for
Select all books by '{0}', apply correct Author Sort value in Edit Metadata dialog, Author '{0}':
then rebuild the catalog.\n''').format(author[0],author[1],current_author[1]) '{1}' <> '{2}'
self.opts.log.warn('\n*** Metadata error ***') Unable to build MOBI catalog.\n
self.opts.log.warn(error_msg) Select all books by '{0}', apply correct Author Sort value in Edit Metadata dialog, then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
self.opts.log.warn('\n*** Metadata error ***')
self.opts.log.warn(error_msg)
self.error.append('Author Sort mismatch')
self.error.append(error_msg)
return False
else:
# Warning if building non-MOBI
if not self.error:
self.error.append('Author Sort mismatch')
error_msg = _(
'''Warning: inconsistent Author Sort values for
Author '{0}':
'{1}' <> '{2}'\n''').format(author[0],author[1],current_author[1])
self.opts.log.warn('\n*** Metadata warning ***')
self.opts.log.warn(error_msg)
self.error.append(error_msg)
self.error.append('Metadata error')
self.error.append(error_msg)
return False
current_author = author current_author = author
self.booksByAuthor = sorted(self.booksByAuthor, key=self.booksByAuthorSorter_author_sort) self.booksByAuthor = sorted(self.booksByAuthor, key=self.booksByAuthorSorter_author_sort)
# Build the unique_authors set from existing data # Build the unique_authors set from existing data
@ -2135,7 +2148,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
if author_count == 1: if author_count == 1:
divOpeningTag.insert(dotc, pBookTag) divOpeningTag.insert(dotc, pBookTag)
dotc += 1 dotc += 1
else: elif divRunningTag:
divRunningTag.insert(drtc,pBookTag) divRunningTag.insert(drtc,pBookTag)
drtc += 1 drtc += 1