Add a get_current_db method

This commit is contained in:
Kovid Goyal 2011-04-17 15:33:17 -06:00
parent 5157f576aa
commit 7eb4f5fa7b

View File

@ -648,6 +648,18 @@ def open_url(qurl):
if isfrozen and islinux and paths: if isfrozen and islinux and paths:
os.environ['LD_LIBRARY_PATH'] = os.pathsep.join(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): def open_local_file(path):
if iswindows: if iswindows: