From abc1f7525c8a2af18a714ee57944c720750b7ec7 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Wed, 20 Oct 2010 12:28:55 +0100 Subject: [PATCH 1/4] Fix restore not to die when conflicting custom columns are encountered. --- src/calibre/library/restore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/library/restore.py b/src/calibre/library/restore.py index 16aba3aebd..748d60b0b2 100644 --- a/src/calibre/library/restore.py +++ b/src/calibre/library/restore.py @@ -170,8 +170,8 @@ class Restore(Thread): 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) + self.conflicting_custom_cols[label] = [] + self.conflicting_custom_cols[label].append(args) m[cfm['label']] = args db = RestoreDatabase(self.library_path) From 5fc0d687307bb921c35076bcd92bbcc87d25906a Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 21 Oct 2010 09:54:21 +0100 Subject: [PATCH 2/4] Improve conflicting custom column error reporting when restoring a database --- src/calibre/library/restore.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/calibre/library/restore.py b/src/calibre/library/restore.py index 748d60b0b2..bc2c740279 100644 --- a/src/calibre/library/restore.py +++ b/src/calibre/library/restore.py @@ -71,9 +71,17 @@ class Restore(Thread): if self.conflicting_custom_cols: ans += '\n\n' - ans += 'The following custom columns were not fully restored:\n' + ans += 'The following custom columns have conflicting definitions ' \ + 'and were not fully restored:\n' for x in self.conflicting_custom_cols: ans += '\t#'+x+'\n' + ans += '\tused:\t%s, %s, %s, %s\n'%(self.custom_columns[x][1], + self.custom_columns[x][2], + self.custom_columns[x][3], + self.custom_columns[x][5]) + for coldef in self.conflicting_custom_cols[x]: + ans += '\tother:\t%s, %s, %s, %s\n'%(coldef[1], coldef[2], + coldef[3], coldef[5]) if self.mismatched_dirs: ans += '\n\n' @@ -152,7 +160,7 @@ class Restore(Thread): def create_cc_metadata(self): self.books.sort(key=itemgetter('timestamp')) - m = {} + self.custom_columns = {} fields = ('label', 'name', 'datatype', 'is_multiple', 'is_editable', 'display') for b in self.books: @@ -168,16 +176,17 @@ class Restore(Thread): 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 in self.custom_columns and args != self.custom_columns[label]: if label not in self.conflicting_custom_cols: self.conflicting_custom_cols[label] = [] - self.conflicting_custom_cols[label].append(args) - m[cfm['label']] = args + if self.custom_columns[label] not in self.conflicting_custom_cols[label]: + self.conflicting_custom_cols[label].append(self.custom_columns[label]) + self.custom_columns[label] = args db = RestoreDatabase(self.library_path) - self.progress_callback(None, len(m)) - if len(m): - for i,args in enumerate(m.values()): + self.progress_callback(None, len(self.custom_columns)) + if len(self.custom_columns): + for i,args in enumerate(self.custom_columns.values()): db.create_custom_column(*args) self.progress_callback(_('creating custom column ')+args[0], i+1) db.conn.close() From 77284f75284ae7e5f8eb0823cd1f406316e0280b Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 21 Oct 2010 21:09:47 +0100 Subject: [PATCH 3/4] Fix exceptions when referencing invalid fields XXX_index --- src/calibre/ebooks/metadata/book/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index 593e161df7..9286226a3e 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -501,13 +501,15 @@ class Metadata(object): if key.startswith('#') and key.endswith('_index'): tkey = key[:-6] # strip the _index cmeta = self.get_user_metadata(tkey, make_copy=False) - if cmeta['datatype'] == 'series': + if cmeta and cmeta['datatype'] == 'series': if self.get(tkey): res = self.get_extra(tkey) return (unicode(cmeta['name']+'_index'), self.format_series_index(res), res, cmeta) else: return (unicode(cmeta['name']+'_index'), '', '', cmeta) + else: + return (key, key, None, None) if key in self.custom_field_keys(): res = self.get(key, None) From 6375d4cc451ec5a3d28a078e4170134321c2bb86 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 21 Oct 2010 21:14:04 +0100 Subject: [PATCH 4/4] Fix the fix --- src/calibre/ebooks/metadata/book/base.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index 9286226a3e..125cd542b8 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -508,8 +508,6 @@ class Metadata(object): self.format_series_index(res), res, cmeta) else: return (unicode(cmeta['name']+'_index'), '', '', cmeta) - else: - return (key, key, None, None) if key in self.custom_field_keys(): res = self.get(key, None)