From e24ba2f198ae7d8265a9e904655783acaa1d3ba5 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Fri, 28 Jul 2017 19:31:13 +0100 Subject: [PATCH] Remove settings.py file --- gramps/plugins/db/dbapi/dbapi.py | 41 +++++++++++----------- gramps/plugins/db/dbapi/settings.ini | 11 ------ gramps/plugins/db/dbapi/settings.py | 52 ---------------------------- 3 files changed, 21 insertions(+), 83 deletions(-) delete mode 100644 gramps/plugins/db/dbapi/settings.ini delete mode 100644 gramps/plugins/db/dbapi/settings.py diff --git a/gramps/plugins/db/dbapi/dbapi.py b/gramps/plugins/db/dbapi/dbapi.py index d7a0b0799..638bab3ed 100644 --- a/gramps/plugins/db/dbapi/dbapi.py +++ b/gramps/plugins/db/dbapi/dbapi.py @@ -25,7 +25,6 @@ # #------------------------------------------------------------------------- import os -import shutil import time import sys import pickle @@ -85,15 +84,6 @@ class DBAPI(DbGeneric): _LOG.debug("Write database backend file to 'dbapi'") with open(versionpath, "w") as version_file: version_file.write("dbapi") - # Write settings.py and settings.ini: - settings_py = os.path.join(os.path.dirname(os.path.abspath(__file__)), - "settings.py") - settings_ini = os.path.join(os.path.dirname(os.path.abspath(__file__)), - "settings.ini") - LOG.debug("Copy settings.py from: " + settings_py) - LOG.debug("Copy settings.ini from: " + settings_py) - shutil.copy2(settings_py, directory) - shutil.copy2(settings_ini, directory) def _initialize(self, directory): # Run code from directory @@ -107,16 +97,27 @@ class DBAPI(DbGeneric): config_mgr.register('database.password', 'password') config_mgr.register('database.port', 'port') config_mgr.load() # load from settings.ini - settings = { - "__file__": - os.path.join(directory, "settings.py"), - "config": config_mgr - } - settings_file = os.path.join(directory, "settings.py") - with open(settings_file) as fp: - code = compile(fp.read(), settings_file, 'exec') - exec(code, globals(), settings) - self.dbapi = settings["dbapi"] + + dbtype = config_mgr.get('database.dbtype') + + if dbtype == "sqlite": + from gramps.plugins.db.dbapi.sqlite import Sqlite + path_to_db = os.path.join(directory, 'sqlite.db') + self.dbapi = Sqlite(path_to_db) + else: + dbkwargs = {} + for key in config_mgr.get_section_settings('database'): + # Use all parameters except dbtype as keyword arguments + if key == 'dbtype': + continue + dbkwargs[key] = config_mgr.get('database.' + key) + if dbtype == "postgresql": + from gramps.plugins.db.dbapi.postgresql import Postgresql + self.dbapi = Postgresql(**dbkwargs) + else: + raise AttributeError(("invalid DB-API dbtype: '%s'. " + + "Should be 'sqlite' or 'postgresql'") + % dbtype) # We use the existence of the person table as a proxy for the database # being new diff --git a/gramps/plugins/db/dbapi/settings.ini b/gramps/plugins/db/dbapi/settings.ini deleted file mode 100644 index 94698fe2a..000000000 --- a/gramps/plugins/db/dbapi/settings.ini +++ /dev/null @@ -1,11 +0,0 @@ -;; Gramps key file -;; Automatically created at 2016/07/12 13:06:48 - -[database] -;;dbname='gramps' -;;dbtype='sqlite' -;;host='localhost' -;;password='password' -;;port='port' -;;user='user' - diff --git a/gramps/plugins/db/dbapi/settings.py b/gramps/plugins/db/dbapi/settings.py deleted file mode 100644 index 5e5f2e137..000000000 --- a/gramps/plugins/db/dbapi/settings.py +++ /dev/null @@ -1,52 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2015-2016 Douglas S. Blank -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -import os - -## This file is copied from gramps/plugins/db/dbapi/settings.py -## into each grampsdb/*/ directory. You can edit each copy -## to connect to different databases, or with different -## parameters. - -## The database options are saved in settings.ini. -# NOTE: config is predefined - -# NOTE: you can override this in settings.ini or here: -#from gramps.gen.config import config -dbtype = config.get('database.dbtype') - -if dbtype == "sqlite": - from gramps.plugins.db.dbapi.sqlite import Sqlite - path_to_db = os.path.join(os.path.dirname(os.path.realpath(__file__)), - 'sqlite.db') - dbapi = Sqlite(path_to_db) -else: - # NOTE: you can override these settings here or in settings.ini: - dbkwargs = {} - for key in config.get_section_settings('database'): - # Use all parameters except dbtype as keyword arguments - if key == 'dbtype': - continue - dbkwargs[key] = config.get('database.' + key) - if dbtype == "postgresql": - from gramps.plugins.db.dbapi.postgresql import Postgresql - dbapi = Postgresql(**dbkwargs) - else: - raise AttributeError(("invalid DB-API dbtype: '%s'. " + - "Should be 'sqlite' or 'postgresql'") % dbtype)