From 10f9af93a9e2ec28938a2d855fc01247ab129960 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 26 Sep 2010 18:18:45 +0100 Subject: [PATCH] Fix restoring custom column definitions --- src/calibre/library/caches.py | 1 - src/calibre/library/restore.py | 38 ++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index 3e7f4d85ee..9d6f87324f 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -75,7 +75,6 @@ class MetadataBackup(Thread): # {{{ # Give the GUI thread a chance to do something. Python threads don't # have priorities, so this thread would naturally keep the processor # until some scheduling event happens. The sleep makes such an event - print 'do one' time.sleep(0.1) try: raw = metadata_to_opf(mi) diff --git a/src/calibre/library/restore.py b/src/calibre/library/restore.py index 89c7fe8395..d34e831fc7 100644 --- a/src/calibre/library/restore.py +++ b/src/calibre/library/restore.py @@ -145,25 +145,33 @@ class Restore(Thread): 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):