From 7eb4f5fa7b3f93b807ca85dd05132873e3681a88 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 17 Apr 2011 15:33:17 -0600 Subject: [PATCH] Add a get_current_db method --- src/calibre/gui2/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index e39427021e..2bbf4243eb 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -648,6 +648,18 @@ def open_url(qurl): if isfrozen and islinux and paths: os.environ['LD_LIBRARY_PATH'] = os.pathsep.join(paths) +def get_current_db(): + ''' + This method will try to return the current database in use by the user as + efficiently as possible, i.e. without constructing duplicate + LibraryDatabase objects. + ''' + from calibre.gui2.ui import get_gui + gui = get_gui() + if gui is not None: + return gui.current_db + from calibre.library import db + return db() def open_local_file(path): if iswindows: