From cdf50da0342729728efc99d90eb519c5400c7387 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 15 Jul 2013 21:16:07 +0530 Subject: [PATCH] get_id_from_uuid() --- src/calibre/db/cache.py | 5 +++++ src/calibre/db/legacy.py | 4 ++++ src/calibre/db/tables.py | 3 +++ src/calibre/db/tests/legacy.py | 1 + 4 files changed, 13 insertions(+) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 330e8dfba5..ea62f3b90a 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -1353,6 +1353,11 @@ class Cache(object): self._mark_as_dirty(changed_books) return changed_books + @read_api + def lookup_by_uuid(self, uuid): + return self.fields['uuid'].table.lookup_by_uuid(uuid) + + # }}} class SortKey(object): # {{{ diff --git a/src/calibre/db/legacy.py b/src/calibre/db/legacy.py index ec480c3d2d..1faf9a2d1a 100644 --- a/src/calibre/db/legacy.py +++ b/src/calibre/db/legacy.py @@ -153,6 +153,10 @@ class LibraryDatabase(object): def refresh(self, field=None, ascending=True): self.data.refresh(field=field, ascending=ascending) + def get_id_from_uuid(self, uuid): + if uuid: + return self.new_api.lookup_by_uuid(uuid) + def add_listener(self, listener): ''' Add a listener. Will be called on change events with two arguments. diff --git a/src/calibre/db/tables.py b/src/calibre/db/tables.py index 81c66a0ca5..e76423d971 100644 --- a/src/calibre/db/tables.py +++ b/src/calibre/db/tables.py @@ -137,6 +137,9 @@ class UUIDTable(OneToOneTable): clean.add(val) return clean + def lookup_by_uuid(self, uuid): + return self.uuid_to_id_map.get(uuid, None) + class CompositeTable(OneToOneTable): def read(self, db): diff --git a/src/calibre/db/tests/legacy.py b/src/calibre/db/tests/legacy.py index 5f1aa2ff41..725f6c3ad9 100644 --- a/src/calibre/db/tests/legacy.py +++ b/src/calibre/db/tests/legacy.py @@ -163,6 +163,7 @@ class LegacyTest(BaseTest): for meth, args in { 'get_next_series_num_for': [('A Series One',)], + 'get_id_from_uuid':[('ddddd',), (db.uuid(1, True),)], 'get_author_id': [('author one',), ('unknown',), ('xxxxx',)], 'series_id': [(0,), (1,), (2,)], 'publisher_id': [(0,), (1,), (2,)],