def get_current_db():
 from calibre.gui2.ui import get_gui
 gui = get_gui()
 if ((gui is not None) and (gui.current_db is not None)):
  return gui.current_db
 from calibre.library import db
 return db()

def get_current_db ( ) : from calibre . gui2 . ui import get_gui gui = get_gui ( ) if ( ( gui is not None ) and ( gui . current_db is not None ) ) : return gui . current_db from calibre . library import db return db ( )
this method will try to return the current database in use by the user as efficiently as possible .