This commit is contained in:
Kovid Goyal 2013-07-23 08:57:10 +05:30
parent e1ed5f679f
commit 2da2657345

View File

@ -80,7 +80,7 @@ class Metadata(object):
self.title = title self.title = title
if authors: if authors:
# List of strings or [] # List of strings or []
self.author = list(authors) if authors else []# Needed for backward compatibility self.author = list(authors) if authors else [] # Needed for backward compatibility
self.authors = list(authors) if authors else [] self.authors = list(authors) if authors else []
from calibre.ebooks.metadata.book.formatter import SafeFormat from calibre.ebooks.metadata.book.formatter import SafeFormat
self.formatter = SafeFormat() self.formatter = SafeFormat()
@ -429,8 +429,7 @@ class Metadata(object):
try: try:
src = op[0] src = op[0]
dest = op[1] dest = op[1]
val = formatter.safe_format\ val = formatter.safe_format(src, other, 'PLUGBOARD TEMPLATE ERROR', other)
(src, other, 'PLUGBOARD TEMPLATE ERROR', other)
if dest == 'tags': if dest == 'tags':
self.set(dest, [f.strip() for f in val.split(',') if f.strip()]) self.set(dest, [f.strip() for f in val.split(',') if f.strip()])
elif dest == 'authors': elif dest == 'authors':
@ -476,7 +475,7 @@ class Metadata(object):
if replace_metadata: if replace_metadata:
# SPECIAL_FIELDS = frozenset(['lpath', 'size', 'comments', 'thumbnail']) # SPECIAL_FIELDS = frozenset(['lpath', 'size', 'comments', 'thumbnail'])
for attr in SC_COPYABLE_FIELDS: for attr in SC_COPYABLE_FIELDS:
setattr(self, attr, getattr(other, attr, 1.0 if \ setattr(self, attr, getattr(other, attr, 1.0 if
attr == 'series_index' else None)) attr == 'series_index' else None))
self.tags = other.tags self.tags = other.tags
self.cover_data = getattr(other, 'cover_data', self.cover_data = getattr(other, 'cover_data',
@ -507,8 +506,10 @@ class Metadata(object):
if getattr(other, 'cover_data', False): if getattr(other, 'cover_data', False):
other_cover = other.cover_data[-1] other_cover = other.cover_data[-1]
self_cover = self.cover_data[-1] if self.cover_data else '' self_cover = self.cover_data[-1] if self.cover_data else ''
if not self_cover: self_cover = '' if not self_cover:
if not other_cover: other_cover = '' self_cover = ''
if not other_cover:
other_cover = ''
if len(other_cover) > len(self_cover): if len(other_cover) > len(self_cover):
self.cover_data = other.cover_data self.cover_data = other.cover_data
@ -517,7 +518,7 @@ class Metadata(object):
meta = other.get_user_metadata(x, make_copy=True) meta = other.get_user_metadata(x, make_copy=True)
if meta is not None: if meta is not None:
self_tags = self.get(x, []) self_tags = self.get(x, [])
self.set_user_metadata(x, meta) # get... did the deepcopy self.set_user_metadata(x, meta) # get... did the deepcopy
other_tags = other.get(x, []) other_tags = other.get(x, [])
if meta['datatype'] == 'text' and meta['is_multiple']: if meta['datatype'] == 'text' and meta['is_multiple']:
# Case-insensitive but case preserving merging # Case-insensitive but case preserving merging
@ -607,7 +608,7 @@ class Metadata(object):
# Handle custom series index # Handle custom series index
if key.startswith('#') and key.endswith('_index'): if key.startswith('#') and key.endswith('_index'):
tkey = key[:-6] # strip the _index tkey = key[:-6] # strip the _index
cmeta = self.get_user_metadata(tkey, make_copy=False) cmeta = self.get_user_metadata(tkey, make_copy=False)
if cmeta and cmeta['datatype'] == 'series': if cmeta and cmeta['datatype'] == 'series':
if self.get(tkey): if self.get(tkey):
@ -698,7 +699,7 @@ class Metadata(object):
if self.title_sort: if self.title_sort:
fmt('Title sort', self.title_sort) fmt('Title sort', self.title_sort)
if self.authors: if self.authors:
fmt('Author(s)', authors_to_string(self.authors) + \ fmt('Author(s)', authors_to_string(self.authors) +
((' [' + self.author_sort + ']') ((' [' + self.author_sort + ']')
if self.author_sort and self.author_sort != _('Unknown') else '')) if self.author_sort and self.author_sort != _('Unknown') else ''))
if self.publisher: if self.publisher:
@ -805,3 +806,4 @@ def field_from_string(field, raw, field_metadata):
return val return val