Remove settings.py file
This commit is contained in:
parent
d0880a07a0
commit
e24ba2f198
@ -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
|
||||
|
@ -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'
|
||||
|
@ -1,52 +0,0 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2015-2016 Douglas S. Blank <doug.blank@gmail.com>
|
||||
#
|
||||
# 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)
|
Loading…
Reference in New Issue
Block a user