put database directory next to HUD_config.xml file
This commit is contained in:
parent
45397695d3
commit
5c88c6b0ad
|
@ -113,10 +113,6 @@ log = get_logger("logging.conf")
|
|||
APPLICATION_NAME_SHORT = 'fpdb'
|
||||
APPLICATION_VERSION = 'xx.xx.xx'
|
||||
|
||||
DIR_SELF = os.path.dirname(get_exec_path())
|
||||
#TODO: imo no good idea to place 'database' in parent dir
|
||||
DIR_DATABASES = os.path.join(os.path.dirname(DIR_SELF), 'database')
|
||||
|
||||
DATABASE_TYPE_POSTGRESQL = 'postgresql'
|
||||
DATABASE_TYPE_SQLITE = 'sqlite'
|
||||
DATABASE_TYPE_MYSQL = 'mysql'
|
||||
|
@ -429,6 +425,8 @@ class Config:
|
|||
|
||||
self.doc = doc
|
||||
self.file = file
|
||||
self.dir = os.path.dirname(self.file)
|
||||
self.dir_databases = os.path.join(self.dir, 'database')
|
||||
self.supported_sites = {}
|
||||
self.supported_games = {}
|
||||
self.supported_databases = {} # databaseName --> Database instance
|
||||
|
|
|
@ -41,6 +41,10 @@ except ImportError:
|
|||
import FpdbSQLQueries
|
||||
import Configuration
|
||||
|
||||
|
||||
DB_VERSION = 118
|
||||
|
||||
|
||||
# Variance created as sqlite has a bunch of undefined aggregate functions.
|
||||
|
||||
class VARIANCE:
|
||||
|
@ -74,6 +78,7 @@ class fpdb_db:
|
|||
if config is None:
|
||||
raise FpdbError('Configuration not defined')
|
||||
|
||||
self.config = config
|
||||
self.settings = {}
|
||||
self.settings['os'] = "linuxmac" if os.name != "nt" else "windows"
|
||||
|
||||
|
@ -95,6 +100,8 @@ class fpdb_db:
|
|||
self.user = user
|
||||
self.password = password
|
||||
self.database = database
|
||||
createTables = False
|
||||
|
||||
if backend == fpdb_db.MYSQL_INNODB:
|
||||
import MySQLdb
|
||||
if use_pool:
|
||||
|
@ -154,10 +161,12 @@ class fpdb_db:
|
|||
else:
|
||||
logging.warning("SQLite won't work well without 'sqlalchemy' installed.")
|
||||
|
||||
if not os.path.isdir(Configuration.DIR_DATABASES) and not database == ":memory:":
|
||||
print "Creating directory: '%s'" % (Configuration.DIR_DATABASES)
|
||||
os.mkdir(Configuration.DIR_DATABASES)
|
||||
database = os.path.join(Configuration.DIR_DATABASES, database)
|
||||
if not os.path.isdir(self.config.dir_databases) and not database == ":memory:":
|
||||
print "Creating directory: '%s'" % (self.config.dir_databases)
|
||||
logging.info("Creating directory: '%s'" % (self.config.dir_databases))
|
||||
os.mkdir(self.config.dir_databases)
|
||||
database = os.path.join(self.config.dir_databases, database)
|
||||
createTables = True
|
||||
self.db = sqlite3.connect(database, detect_types=sqlite3.PARSE_DECLTYPES )
|
||||
sqlite3.register_converter("bool", lambda x: bool(int(x)))
|
||||
sqlite3.register_adapter(bool, lambda x: "1" if x else "0")
|
||||
|
@ -179,8 +188,9 @@ class fpdb_db:
|
|||
try:
|
||||
self.cursor.execute("SELECT * FROM Settings")
|
||||
settings = self.cursor.fetchone()
|
||||
if settings[0] != 118:
|
||||
print "outdated or too new database version - please recreate tables"
|
||||
if settings[0] != DB_VERSION:
|
||||
logging.error("outdated or too new database version (%s) - please recreate tables"
|
||||
% (settings[0]))
|
||||
self.wrongDbVersion = True
|
||||
except:# _mysql_exceptions.ProgrammingError:
|
||||
if database != ":memory:": print "failed to read settings table - please recreate tables"
|
||||
|
|
Loading…
Reference in New Issue
Block a user