Moved make_database to DbState
This commit is contained in:
parent
242abf9f69
commit
2dd365f8bc
@ -44,7 +44,6 @@ import sys
|
||||
#-------------------------------------------------------------------------
|
||||
from gramps.gen.recentfiles import recent_files
|
||||
from gramps.gen.utils.file import rm_tempdir, get_empty_tempdir
|
||||
from gramps.gen.db import make_database
|
||||
from .clidbman import CLIDbManager, NAME_FILE, find_locker_name
|
||||
|
||||
from gramps.gen.plug import BasePluginManager
|
||||
@ -492,7 +491,7 @@ class ArgHandler(object):
|
||||
else:
|
||||
self.imp_db_path = get_empty_tempdir("import_dbdir")
|
||||
|
||||
newdb = make_database("bsddb", self.dbstate)
|
||||
newdb = self.dbstate.make_database("bsddb")
|
||||
newdb.write_version(self.imp_db_path)
|
||||
|
||||
try:
|
||||
|
@ -54,7 +54,6 @@ _LOG = logging.getLogger(DBLOGNAME)
|
||||
#-------------------------------------------------------------------------
|
||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
from gramps.gen.db import make_database
|
||||
from gramps.gen.plug import BasePluginManager
|
||||
from gramps.gen.config import config
|
||||
from gramps.gen.constfunc import win, conv_to_unicode
|
||||
@ -295,7 +294,7 @@ class CLIDbManager(object):
|
||||
if create_db:
|
||||
# write the version number into metadata
|
||||
|
||||
newdb = make_database("bsddb", self.dbstate)
|
||||
newdb = self.dbstate.make_database("bsddb")
|
||||
newdb.write_version(new_path)
|
||||
|
||||
(tval, last) = time_val(new_path)
|
||||
@ -362,7 +361,7 @@ class CLIDbManager(object):
|
||||
# Create a new database
|
||||
self.__start_cursor(_("Importing data..."))
|
||||
|
||||
dbase = make_database("bsddb", self.dbstate)
|
||||
dbase = self.dbstate.make_database("bsddb")
|
||||
dbase.load(new_path, user.callback)
|
||||
|
||||
import_function = plugin.get_import_function()
|
||||
|
@ -49,7 +49,6 @@ from gramps.gen.config import config
|
||||
from gramps.gen.const import PLUGINS_DIR, USER_PLUGINS
|
||||
from gramps.gen.errors import DbError
|
||||
from gramps.gen.dbstate import DbState
|
||||
from gramps.gen.db import make_database
|
||||
from gramps.gen.db.exceptions import (DbUpgradeRequiredError,
|
||||
BsddbDowngradeError,
|
||||
DbVersionError,
|
||||
@ -152,7 +151,7 @@ class CLIDbLoader(object):
|
||||
else:
|
||||
mode = 'w'
|
||||
|
||||
db = make_database("bsddb", self.dbstate)
|
||||
db = self.dbstate.make_database("bsddb")
|
||||
|
||||
self.dbstate.change_database(db)
|
||||
self.dbstate.db.disable_signals()
|
||||
|
@ -94,18 +94,3 @@ from .txn import *
|
||||
from .exceptions import *
|
||||
#from .write import *
|
||||
#from .backup import backup, restore
|
||||
|
||||
def make_database(id, dbstate):
|
||||
from gramps.cli.grampscli import CLIManager
|
||||
from gramps.gen.plug import BasePluginManager
|
||||
from gramps.cli.user import User
|
||||
|
||||
climanager = CLIManager(dbstate, setloader=False, user=User()) # do not load db_loader
|
||||
climanager.do_reg_plugins(dbstate, None)
|
||||
pmgr = BasePluginManager.get_instance()
|
||||
pdata = pmgr.get_plugin(id)
|
||||
|
||||
mod = pmgr.load_plugin(pdata)
|
||||
database = getattr(mod, pdata.databaseclass)
|
||||
return database()
|
||||
|
||||
|
@ -24,7 +24,6 @@ Provide the database state class
|
||||
"""
|
||||
|
||||
from .db import DbReadBase
|
||||
from .db import make_database
|
||||
from .proxy.proxybase import ProxyDbBase
|
||||
from .utils.callback import Callback
|
||||
from .config import config
|
||||
@ -45,7 +44,7 @@ class DbState(Callback):
|
||||
just a place holder until a real DB is assigned.
|
||||
"""
|
||||
Callback.__init__(self)
|
||||
self.db = make_database("bsddb", self)
|
||||
self.db = self.make_database("bsddb")
|
||||
self.open = False
|
||||
self.stack = []
|
||||
|
||||
@ -88,7 +87,7 @@ class DbState(Callback):
|
||||
"""
|
||||
self.emit('no-database', ())
|
||||
self.db.close()
|
||||
self.db = make_database("bsddb", self)
|
||||
self.db = self.make_database("bsddb")
|
||||
self.db.db_is_open = False
|
||||
self.open = False
|
||||
self.emit('database-changed', (self.db, ))
|
||||
@ -122,3 +121,24 @@ class DbState(Callback):
|
||||
"""
|
||||
self.db = self.stack.pop()
|
||||
self.emit('database-changed', (self.db, ))
|
||||
|
||||
def make_database(self, id):
|
||||
"""
|
||||
Make a database, given a plugin id.
|
||||
"""
|
||||
from .plug import BasePluginManager
|
||||
from .const import PLUGINS_DIR, USER_PLUGINS
|
||||
|
||||
pmgr = BasePluginManager.get_instance()
|
||||
pdata = pmgr.get_plugin(id)
|
||||
|
||||
if not pdata:
|
||||
# This might happen if using gramps from outside, and
|
||||
# we haven't loaded plugins yet
|
||||
pmgr.reg_plugins(PLUGINS_DIR, self, None)
|
||||
pmgr.reg_plugins(USER_PLUGINS, self, None, load_on_reg=True)
|
||||
pdata = pmgr.get_plugin(id)
|
||||
|
||||
mod = pmgr.load_plugin(pdata)
|
||||
database = getattr(mod, pdata.databaseclass)
|
||||
return database()
|
||||
|
@ -55,7 +55,6 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
from gramps.cli.grampscli import CLIDbLoader
|
||||
from gramps.gen.config import config
|
||||
from gramps.gen.db import make_database
|
||||
from gramps.gen.db.exceptions import (DbUpgradeRequiredError,
|
||||
BsddbDowngradeError,
|
||||
DbVersionError,
|
||||
@ -305,7 +304,7 @@ class DbLoader(CLIDbLoader):
|
||||
else:
|
||||
mode = 'w'
|
||||
|
||||
db = make_database("bsddb", self.dbstate)
|
||||
db = self.dbstate.make_database("bsddb")
|
||||
db.disable_signals()
|
||||
self.dbstate.no_database()
|
||||
|
||||
|
@ -73,7 +73,6 @@ _ = glocale.translation.gettext
|
||||
from gramps.gen.const import URL_WIKISTRING
|
||||
from .user import User
|
||||
from .dialog import ErrorDialog, QuestionDialog, QuestionDialog2
|
||||
from gramps.gen.db import make_database
|
||||
from .pluginmanager import GuiPluginManager
|
||||
from gramps.cli.clidbman import CLIDbManager, NAME_FILE, time_val
|
||||
from .ddtargets import DdTargets
|
||||
@ -536,7 +535,7 @@ class DbManager(CLIDbManager):
|
||||
|
||||
self.__start_cursor(_("Extracting archive..."))
|
||||
|
||||
dbase = make_database("bsddb", self.dbstate)
|
||||
dbase = self.dbstate.make_database("bsddb")
|
||||
dbase.load(new_path, None)
|
||||
|
||||
self.__start_cursor(_("Importing archive..."))
|
||||
@ -723,10 +722,10 @@ class DbManager(CLIDbManager):
|
||||
fname = os.path.join(dirname, filename)
|
||||
os.unlink(fname)
|
||||
|
||||
newdb = make_database("bsddb", self.dbstate)
|
||||
newdb = self.dbstate.make_database("bsddb")
|
||||
newdb.write_version(dirname)
|
||||
|
||||
dbase = make_database("bsddb", self.dbstate)
|
||||
dbase = self.dbstate.make_database("bsddb")
|
||||
dbase.set_save_path(dirname)
|
||||
dbase.load(dirname, None)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user