Moved make_database to DbState

This commit is contained in:
Doug Blank 2015-05-12 19:09:17 -04:00
parent 242abf9f69
commit 2dd365f8bc
7 changed files with 31 additions and 31 deletions

View File

@ -44,7 +44,6 @@ import sys
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.recentfiles import recent_files from gramps.gen.recentfiles import recent_files
from gramps.gen.utils.file import rm_tempdir, get_empty_tempdir 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 .clidbman import CLIDbManager, NAME_FILE, find_locker_name
from gramps.gen.plug import BasePluginManager from gramps.gen.plug import BasePluginManager
@ -492,7 +491,7 @@ class ArgHandler(object):
else: else:
self.imp_db_path = get_empty_tempdir("import_dbdir") 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) newdb.write_version(self.imp_db_path)
try: try:

View File

@ -54,7 +54,6 @@ _LOG = logging.getLogger(DBLOGNAME)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
from gramps.gen.db import make_database
from gramps.gen.plug import BasePluginManager from gramps.gen.plug import BasePluginManager
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gen.constfunc import win, conv_to_unicode from gramps.gen.constfunc import win, conv_to_unicode
@ -295,7 +294,7 @@ class CLIDbManager(object):
if create_db: if create_db:
# write the version number into metadata # write the version number into metadata
newdb = make_database("bsddb", self.dbstate) newdb = self.dbstate.make_database("bsddb")
newdb.write_version(new_path) newdb.write_version(new_path)
(tval, last) = time_val(new_path) (tval, last) = time_val(new_path)
@ -362,7 +361,7 @@ class CLIDbManager(object):
# Create a new database # Create a new database
self.__start_cursor(_("Importing data...")) self.__start_cursor(_("Importing data..."))
dbase = make_database("bsddb", self.dbstate) dbase = self.dbstate.make_database("bsddb")
dbase.load(new_path, user.callback) dbase.load(new_path, user.callback)
import_function = plugin.get_import_function() import_function = plugin.get_import_function()

View File

@ -49,7 +49,6 @@ from gramps.gen.config import config
from gramps.gen.const import PLUGINS_DIR, USER_PLUGINS from gramps.gen.const import PLUGINS_DIR, USER_PLUGINS
from gramps.gen.errors import DbError from gramps.gen.errors import DbError
from gramps.gen.dbstate import DbState from gramps.gen.dbstate import DbState
from gramps.gen.db import make_database
from gramps.gen.db.exceptions import (DbUpgradeRequiredError, from gramps.gen.db.exceptions import (DbUpgradeRequiredError,
BsddbDowngradeError, BsddbDowngradeError,
DbVersionError, DbVersionError,
@ -152,7 +151,7 @@ class CLIDbLoader(object):
else: else:
mode = 'w' mode = 'w'
db = make_database("bsddb", self.dbstate) db = self.dbstate.make_database("bsddb")
self.dbstate.change_database(db) self.dbstate.change_database(db)
self.dbstate.db.disable_signals() self.dbstate.db.disable_signals()

View File

@ -94,18 +94,3 @@ from .txn import *
from .exceptions import * from .exceptions import *
#from .write import * #from .write import *
#from .backup import backup, restore #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()

View File

@ -24,7 +24,6 @@ Provide the database state class
""" """
from .db import DbReadBase from .db import DbReadBase
from .db import make_database
from .proxy.proxybase import ProxyDbBase from .proxy.proxybase import ProxyDbBase
from .utils.callback import Callback from .utils.callback import Callback
from .config import config from .config import config
@ -45,7 +44,7 @@ class DbState(Callback):
just a place holder until a real DB is assigned. just a place holder until a real DB is assigned.
""" """
Callback.__init__(self) Callback.__init__(self)
self.db = make_database("bsddb", self) self.db = self.make_database("bsddb")
self.open = False self.open = False
self.stack = [] self.stack = []
@ -88,7 +87,7 @@ class DbState(Callback):
""" """
self.emit('no-database', ()) self.emit('no-database', ())
self.db.close() self.db.close()
self.db = make_database("bsddb", self) self.db = self.make_database("bsddb")
self.db.db_is_open = False self.db.db_is_open = False
self.open = False self.open = False
self.emit('database-changed', (self.db, )) self.emit('database-changed', (self.db, ))
@ -122,3 +121,24 @@ class DbState(Callback):
""" """
self.db = self.stack.pop() self.db = self.stack.pop()
self.emit('database-changed', (self.db, )) 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()

View File

@ -55,7 +55,6 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
from gramps.cli.grampscli import CLIDbLoader from gramps.cli.grampscli import CLIDbLoader
from gramps.gen.config import config from gramps.gen.config import config
from gramps.gen.db import make_database
from gramps.gen.db.exceptions import (DbUpgradeRequiredError, from gramps.gen.db.exceptions import (DbUpgradeRequiredError,
BsddbDowngradeError, BsddbDowngradeError,
DbVersionError, DbVersionError,
@ -305,7 +304,7 @@ class DbLoader(CLIDbLoader):
else: else:
mode = 'w' mode = 'w'
db = make_database("bsddb", self.dbstate) db = self.dbstate.make_database("bsddb")
db.disable_signals() db.disable_signals()
self.dbstate.no_database() self.dbstate.no_database()

View File

@ -73,7 +73,6 @@ _ = glocale.translation.gettext
from gramps.gen.const import URL_WIKISTRING from gramps.gen.const import URL_WIKISTRING
from .user import User from .user import User
from .dialog import ErrorDialog, QuestionDialog, QuestionDialog2 from .dialog import ErrorDialog, QuestionDialog, QuestionDialog2
from gramps.gen.db import make_database
from .pluginmanager import GuiPluginManager from .pluginmanager import GuiPluginManager
from gramps.cli.clidbman import CLIDbManager, NAME_FILE, time_val from gramps.cli.clidbman import CLIDbManager, NAME_FILE, time_val
from .ddtargets import DdTargets from .ddtargets import DdTargets
@ -536,7 +535,7 @@ class DbManager(CLIDbManager):
self.__start_cursor(_("Extracting archive...")) self.__start_cursor(_("Extracting archive..."))
dbase = make_database("bsddb", self.dbstate) dbase = self.dbstate.make_database("bsddb")
dbase.load(new_path, None) dbase.load(new_path, None)
self.__start_cursor(_("Importing archive...")) self.__start_cursor(_("Importing archive..."))
@ -723,10 +722,10 @@ class DbManager(CLIDbManager):
fname = os.path.join(dirname, filename) fname = os.path.join(dirname, filename)
os.unlink(fname) os.unlink(fname)
newdb = make_database("bsddb", self.dbstate) newdb = self.dbstate.make_database("bsddb")
newdb.write_version(dirname) newdb.write_version(dirname)
dbase = make_database("bsddb", self.dbstate) dbase = self.dbstate.make_database("bsddb")
dbase.set_save_path(dirname) dbase.set_save_path(dirname)
dbase.load(dirname, None) dbase.load(dirname, None)