mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
commit
405a38b117
@ -181,17 +181,10 @@ class Metadata(object):
|
|||||||
'''
|
'''
|
||||||
return metadata describing a standard or custom field.
|
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_standard_metadata(self, key, make_copy=False)
|
||||||
return self.get_user_metadata(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):
|
def all_non_none_fields(self):
|
||||||
'''
|
'''
|
||||||
Return a dictionary containing all non-None metadata fields, including
|
Return a dictionary containing all non-None metadata fields, including
|
||||||
@ -305,7 +298,7 @@ class Metadata(object):
|
|||||||
def print_all_attributes(self):
|
def print_all_attributes(self):
|
||||||
for x in STANDARD_METADATA_FIELDS:
|
for x in STANDARD_METADATA_FIELDS:
|
||||||
prints('%s:'%x, getattr(self, x, 'None'))
|
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)
|
meta = self.get_user_metadata(x, make_copy=False)
|
||||||
if meta is not None:
|
if meta is not None:
|
||||||
prints(x, meta)
|
prints(x, meta)
|
||||||
@ -370,8 +363,8 @@ class Metadata(object):
|
|||||||
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
|
||||||
|
|
||||||
if getattr(other, 'user_metadata_keys', None):
|
if callable(getattr(other, 'custom_field_keys', None)):
|
||||||
for x in other.user_metadata_keys():
|
for x in other.custom_field_keys():
|
||||||
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, [])
|
||||||
@ -434,7 +427,7 @@ class Metadata(object):
|
|||||||
'''
|
'''
|
||||||
returns the tuple (field_name, formatted_value)
|
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)
|
res = self.get(key, None)
|
||||||
cmeta = self.get_user_metadata(key, make_copy=False)
|
cmeta = self.get_user_metadata(key, make_copy=False)
|
||||||
name = unicode(cmeta['name'])
|
name = unicode(cmeta['name'])
|
||||||
@ -516,7 +509,7 @@ class Metadata(object):
|
|||||||
fmt('Published', isoformat(self.pubdate))
|
fmt('Published', isoformat(self.pubdate))
|
||||||
if self.rights is not None:
|
if self.rights is not None:
|
||||||
fmt('Rights', unicode(self.rights))
|
fmt('Rights', unicode(self.rights))
|
||||||
for key in self.user_metadata_keys():
|
for key in self.custom_field_keys():
|
||||||
val = self.get(key, None)
|
val = self.get(key, None)
|
||||||
if val:
|
if val:
|
||||||
(name, val) = self.format_field(key)
|
(name, val) = self.format_field(key)
|
||||||
@ -541,7 +534,7 @@ class Metadata(object):
|
|||||||
ans += [(_('Published'), unicode(self.pubdate.isoformat(' ')))]
|
ans += [(_('Published'), unicode(self.pubdate.isoformat(' ')))]
|
||||||
if self.rights is not None:
|
if self.rights is not None:
|
||||||
ans += [(_('Rights'), unicode(self.rights))]
|
ans += [(_('Rights'), unicode(self.rights))]
|
||||||
for key in self.user_metadata_keys():
|
for key in self.custom_field_keys():
|
||||||
val = self.get(key, None)
|
val = self.get(key, None)
|
||||||
if val:
|
if val:
|
||||||
(name, val) = self.format_field(key)
|
(name, val) = self.format_field(key)
|
||||||
|
@ -331,7 +331,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
_('Book <font face="serif">%s</font> of %s.')%\
|
_('Book <font face="serif">%s</font> of %s.')%\
|
||||||
(sidx, prepare_string_for_xml(series))
|
(sidx, prepare_string_for_xml(series))
|
||||||
mi = self.db.get_metadata(idx)
|
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)
|
name, val = mi.format_field(key)
|
||||||
if val:
|
if val:
|
||||||
data[name] = val
|
data[name] = val
|
||||||
|
@ -96,6 +96,9 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
def mark_dirty(self):
|
def mark_dirty(self):
|
||||||
db = self.gui.library_view.model().db
|
db = self.gui.library_view.model().db
|
||||||
db.dirtied(list(db.data.iterallids()))
|
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):
|
def debug_device_detection(self, *args):
|
||||||
from calibre.gui2.preferences.device_debug import DebugDevice
|
from calibre.gui2.preferences.device_debug import DebugDevice
|
||||||
|
@ -127,7 +127,7 @@
|
|||||||
<item row="10" column="0" colspan="2">
|
<item row="10" column="0" colspan="2">
|
||||||
<widget class="QPushButton" name="button_all_books_dirty">
|
<widget class="QPushButton" name="button_all_books_dirty">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Back up metadata of all books (while you are working)</string>
|
<string>Back up metadata of all books</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -153,25 +153,33 @@ class Restore(Thread):
|
|||||||
def create_cc_metadata(self):
|
def create_cc_metadata(self):
|
||||||
self.books.sort(key=itemgetter('timestamp'))
|
self.books.sort(key=itemgetter('timestamp'))
|
||||||
m = {}
|
m = {}
|
||||||
fields = ('label', 'name', 'datatype', 'is_multiple', 'editable',
|
fields = ('label', 'name', 'datatype', 'is_multiple', 'is_editable',
|
||||||
'display')
|
'display')
|
||||||
for b in self.books:
|
for b in self.books:
|
||||||
|
for key in b['mi'].custom_field_keys():
|
||||||
|
cfm = b['mi'].metadata_for_field(key)
|
||||||
args = []
|
args = []
|
||||||
for x in fields:
|
for x in fields:
|
||||||
if x in b:
|
if x in cfm:
|
||||||
args.append(b[x])
|
if x == 'is_multiple':
|
||||||
|
args.append(cfm[x] is not None)
|
||||||
|
else:
|
||||||
|
args.append(cfm[x])
|
||||||
if len(args) == len(fields):
|
if len(args) == len(fields):
|
||||||
# TODO: Do series type columns need special handling?
|
# TODO: Do series type columns need special handling?
|
||||||
label = b['label']
|
label = cfm['label']
|
||||||
if label in m and args != m[label]:
|
if label in m and args != m[label]:
|
||||||
if label not in self.conflicting_custom_cols:
|
if label not in self.conflicting_custom_cols:
|
||||||
self.conflicting_custom_cols[label] = set([m[label]])
|
self.conflicting_custom_cols[label] = set([m[label]])
|
||||||
self.conflicting_custom_cols[label].add(args)
|
self.conflicting_custom_cols[label].add(args)
|
||||||
m[b['label']] = args
|
m[cfm['label']] = args
|
||||||
|
|
||||||
db = RestoreDatabase(self.library_path)
|
db = RestoreDatabase(self.library_path)
|
||||||
for args in m.values():
|
self.progress_callback(None, len(m))
|
||||||
|
if len(m):
|
||||||
|
for i,args in enumerate(m.values()):
|
||||||
db.create_custom_column(*args)
|
db.create_custom_column(*args)
|
||||||
|
self.progress_callback(_('creating custom column ')+args[0], i+1)
|
||||||
db.conn.close()
|
db.conn.close()
|
||||||
|
|
||||||
def restore_books(self):
|
def restore_books(self):
|
||||||
|
@ -100,7 +100,7 @@ class TemplateFormatter(string.Formatter):
|
|||||||
val = func[1](self, val)
|
val = func[1](self, val)
|
||||||
else:
|
else:
|
||||||
val = func[1](self, val, *args)
|
val = func[1](self, val, *args)
|
||||||
else:
|
elif val:
|
||||||
val = string.Formatter.format_field(self, val, fmt)
|
val = string.Formatter.format_field(self, val, fmt)
|
||||||
if not val:
|
if not val:
|
||||||
return ''
|
return ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user