mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 11:14:02 +02:00
...
This commit is contained in:
commit
405a38b117
6 changed files with 36 additions and 32 deletions
|
|
@ -181,17 +181,10 @@ def metadata_for_field(self, key):
|
|||
'''
|
||||
return metadata describing a standard or custom field.
|
||||
'''
|
||||
if key in self.user_metadata_keys():
|
||||
if key not in self.custom_field_keys():
|
||||
return self.get_standard_metadata(self, key, make_copy=False)
|
||||
return self.get_user_metadata(key, make_copy=False)
|
||||
|
||||
def user_metadata_keys(self):
|
||||
'''
|
||||
Return the standard keys actually in this book.
|
||||
'''
|
||||
_data = object.__getattribute__(self, '_data')
|
||||
return frozenset(_data['user_metadata'].iterkeys())
|
||||
|
||||
def all_non_none_fields(self):
|
||||
'''
|
||||
Return a dictionary containing all non-None metadata fields, including
|
||||
|
|
@ -305,7 +298,7 @@ def set_user_metadata(self, field, metadata):
|
|||
def print_all_attributes(self):
|
||||
for x in STANDARD_METADATA_FIELDS:
|
||||
prints('%s:'%x, getattr(self, x, 'None'))
|
||||
for x in self.user_metadata_keys():
|
||||
for x in self.custom_field_keys():
|
||||
meta = self.get_user_metadata(x, make_copy=False)
|
||||
if meta is not None:
|
||||
prints(x, meta)
|
||||
|
|
@ -370,8 +363,8 @@ def copy_not_none(dest, src, attr):
|
|||
if len(other_cover) > len(self_cover):
|
||||
self.cover_data = other.cover_data
|
||||
|
||||
if getattr(other, 'user_metadata_keys', None):
|
||||
for x in other.user_metadata_keys():
|
||||
if callable(getattr(other, 'custom_field_keys', None)):
|
||||
for x in other.custom_field_keys():
|
||||
meta = other.get_user_metadata(x, make_copy=True)
|
||||
if meta is not None:
|
||||
self_tags = self.get(x, [])
|
||||
|
|
@ -434,7 +427,7 @@ def format_field_extended(self, key, series_with_index=True):
|
|||
'''
|
||||
returns the tuple (field_name, formatted_value)
|
||||
'''
|
||||
if key in self.user_metadata_keys():
|
||||
if key in self.custom_field_keys():
|
||||
res = self.get(key, None)
|
||||
cmeta = self.get_user_metadata(key, make_copy=False)
|
||||
name = unicode(cmeta['name'])
|
||||
|
|
@ -516,7 +509,7 @@ def fmt(x, y):
|
|||
fmt('Published', isoformat(self.pubdate))
|
||||
if self.rights is not None:
|
||||
fmt('Rights', unicode(self.rights))
|
||||
for key in self.user_metadata_keys():
|
||||
for key in self.custom_field_keys():
|
||||
val = self.get(key, None)
|
||||
if val:
|
||||
(name, val) = self.format_field(key)
|
||||
|
|
@ -541,7 +534,7 @@ def to_html(self):
|
|||
ans += [(_('Published'), unicode(self.pubdate.isoformat(' ')))]
|
||||
if self.rights is not None:
|
||||
ans += [(_('Rights'), unicode(self.rights))]
|
||||
for key in self.user_metadata_keys():
|
||||
for key in self.custom_field_keys():
|
||||
val = self.get(key, None)
|
||||
if val:
|
||||
(name, val) = self.format_field(key)
|
||||
|
|
|
|||
|
|
@ -331,7 +331,7 @@ def get_book_display_info(self, idx):
|
|||
_('Book <font face="serif">%s</font> of %s.')%\
|
||||
(sidx, prepare_string_for_xml(series))
|
||||
mi = self.db.get_metadata(idx)
|
||||
for key in mi.user_metadata_keys():
|
||||
for key in mi.custom_field_keys():
|
||||
name, val = mi.format_field(key)
|
||||
if val:
|
||||
data[name] = val
|
||||
|
|
|
|||
|
|
@ -96,6 +96,9 @@ def genesis(self, gui):
|
|||
def mark_dirty(self):
|
||||
db = self.gui.library_view.model().db
|
||||
db.dirtied(list(db.data.iterallids()))
|
||||
info_dialog(self, _('Backup metadata'),
|
||||
_('Metadata will be backed up while calibre is running, at the '
|
||||
'rate of 30 books per minute.'), show=True)
|
||||
|
||||
def debug_device_detection(self, *args):
|
||||
from calibre.gui2.preferences.device_debug import DebugDevice
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@
|
|||
<item row="10" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="button_all_books_dirty">
|
||||
<property name="text">
|
||||
<string>Back up metadata of all books (while you are working)</string>
|
||||
<string>Back up metadata of all books</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
|||
|
|
@ -153,25 +153,33 @@ def process_dir(self, dirpath, filenames, book_id):
|
|||
def create_cc_metadata(self):
|
||||
self.books.sort(key=itemgetter('timestamp'))
|
||||
m = {}
|
||||
fields = ('label', 'name', 'datatype', 'is_multiple', 'editable',
|
||||
fields = ('label', 'name', 'datatype', 'is_multiple', 'is_editable',
|
||||
'display')
|
||||
for b in self.books:
|
||||
args = []
|
||||
for x in fields:
|
||||
if x in b:
|
||||
args.append(b[x])
|
||||
if len(args) == len(fields):
|
||||
# TODO: Do series type columns need special handling?
|
||||
label = b['label']
|
||||
if label in m and args != m[label]:
|
||||
if label not in self.conflicting_custom_cols:
|
||||
self.conflicting_custom_cols[label] = set([m[label]])
|
||||
self.conflicting_custom_cols[label].add(args)
|
||||
m[b['label']] = args
|
||||
for key in b['mi'].custom_field_keys():
|
||||
cfm = b['mi'].metadata_for_field(key)
|
||||
args = []
|
||||
for x in fields:
|
||||
if x in cfm:
|
||||
if x == 'is_multiple':
|
||||
args.append(cfm[x] is not None)
|
||||
else:
|
||||
args.append(cfm[x])
|
||||
if len(args) == len(fields):
|
||||
# TODO: Do series type columns need special handling?
|
||||
label = cfm['label']
|
||||
if label in m and args != m[label]:
|
||||
if label not in self.conflicting_custom_cols:
|
||||
self.conflicting_custom_cols[label] = set([m[label]])
|
||||
self.conflicting_custom_cols[label].add(args)
|
||||
m[cfm['label']] = args
|
||||
|
||||
db = RestoreDatabase(self.library_path)
|
||||
for args in m.values():
|
||||
db.create_custom_column(*args)
|
||||
self.progress_callback(None, len(m))
|
||||
if len(m):
|
||||
for i,args in enumerate(m.values()):
|
||||
db.create_custom_column(*args)
|
||||
self.progress_callback(_('creating custom column ')+args[0], i+1)
|
||||
db.conn.close()
|
||||
|
||||
def restore_books(self):
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ def format_field(self, val, fmt):
|
|||
val = func[1](self, val)
|
||||
else:
|
||||
val = func[1](self, val, *args)
|
||||
else:
|
||||
elif val:
|
||||
val = string.Formatter.format_field(self, val, fmt)
|
||||
if not val:
|
||||
return ''
|
||||
|
|
|
|||
Loading…
Reference in a new issue