catalog author_sort error handling improved, improved OPF search for <metadata>

This commit is contained in:
GRiker 2011-02-15 09:32:02 -07:00
parent ce56d9ea72
commit eea052b5d2
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 PIL import Image as PILImage
from lxml import etree
if isosx:
try:
@ -2514,23 +2515,23 @@ class ITUNES(DriverBase):
fnames = zf_opf.namelist()
opf = [x for x in fnames if '.opf' in x][0]
if opf:
opf_raw = cStringIO.StringIO(zf_opf.read(opf))
soup = BeautifulSoup(opf_raw.getvalue())
opf_raw.close()
# Touch existing calibre timestamp
md = soup.find('metadata')
if md:
ts = md.find('meta',attrs={'name':'calibre:timestamp'})
if ts:
timestamp = ts['content']
old_ts = parse_date(timestamp)
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)
else:
metadata.timestamp = now()
if DEBUG:
self.log.info(" add timestamp: %s" % metadata.timestamp)
opf_tree = etree.fromstring(zf_opf.read(opf))
ns_map = opf_tree.nsmap.keys()
for item in ns_map:
ns = opf_tree.nsmap[item]
md_el = opf_tree.find(".//{%s}metadata" % ns)
if md_el is not None:
ts = md_el.find('.//{%s}meta[@name="calibre:timestamp"]')
if ts:
timestamp = ts.get('content')
old_ts = parse_date(timestamp)
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)
else:
metadata.timestamp = now()
if DEBUG:
self.log.info(" add timestamp: %s" % metadata.timestamp)
break
else:
metadata.timestamp = now()
if DEBUG:
@ -2838,7 +2839,7 @@ class ITUNES(DriverBase):
def _xform_metadata_via_plugboard(self, book, format):
''' Transform book metadata from plugboard templates '''
if DEBUG:
self.log.info(" ITUNES._update_metadata_from_plugboard()")
self.log.info(" ITUNES._xform_metadata_via_plugboard()")
if self.plugboard_func:
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]
for (i,author) in enumerate(authors):
if author != current_author and i:
# Exit if author matches previous, but author_sort doesn't match
if author[0] == current_author[0]:
error_msg = _('''
Inconsistent Author Sort values for Author '{0}':
'{1}' <> '{2}',
unable to build catalog.\n
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)
if self.opts.fmt == 'mobi':
# Exit if building MOBI
error_msg = _(
'''Inconsistent Author Sort values for
Author '{0}':
'{1}' <> '{2}'
Unable to build MOBI catalog.\n
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
self.booksByAuthor = sorted(self.booksByAuthor, key=self.booksByAuthorSorter_author_sort)
# 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:
divOpeningTag.insert(dotc, pBookTag)
dotc += 1
else:
elif divRunningTag:
divRunningTag.insert(drtc,pBookTag)
drtc += 1