From 43b6566aa8f38b14e6c52c3f5dae57d93694fb58 Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 28 Aug 2017 20:27:39 -0700 Subject: [PATCH] Move getDatabaseName from utils to conf (#476) --- conf.py | 15 ++++++++++++++- plugins/automode.py | 2 +- plugins/relay.py | 2 +- utils.py | 14 -------------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/conf.py b/conf.py index e8ad1a6..2d81270 100644 --- a/conf.py +++ b/conf.py @@ -108,7 +108,6 @@ def validateConf(conf, logger=None): return conf - def loadConf(filename, errors_fatal=True, logger=None): """Loads a PyLink configuration file from the filename given.""" global confname, conf, fname @@ -134,3 +133,17 @@ def loadConf(filename, errors_fatal=True, logger=None): raise else: return conf + +def getDatabaseName(dbname): + """ + Returns a database filename with the given base DB name appropriate for the + current PyLink instance. + + This returns '.db' if the running config name is PyLink's default + (pylink.yml), and '-.db' for anything else. For example, + if this is called from an instance running as './pylink testing.yml', it + would return '-testing.db'.""" + if confname != 'pylink': + dbname += '-%s' % conf.confname + dbname += '.db' + return dbname diff --git a/plugins/automode.py b/plugins/automode.py index d6df252..1ccc6bc 100644 --- a/plugins/automode.py +++ b/plugins/automode.py @@ -17,7 +17,7 @@ reply = modebot.reply error = modebot.error # Databasing variables. -dbname = utils.getDatabaseName('automode') +dbname = conf.getDatabaseName('automode') datastore = structures.JSONDataStore('automode', dbname, default_db=collections.defaultdict(dict)) db = datastore.store diff --git a/plugins/relay.py b/plugins/relay.py index 62037d2..31d5def 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -18,7 +18,7 @@ relayservers = defaultdict(dict) spawnlocks = defaultdict(threading.RLock) spawnlocks_servers = defaultdict(threading.RLock) -dbname = utils.getDatabaseName('pylinkrelay') +dbname = conf.getDatabaseName('pylinkrelay') datastore = structures.PickleDataStore('pylinkrelay', dbname) db = datastore.store diff --git a/utils.py b/utils.py index b6ba882..dbbfb85 100644 --- a/utils.py +++ b/utils.py @@ -112,20 +112,6 @@ def getProtocolModule(name): """ return importlib.import_module(PROTOCOL_PREFIX + name) -def getDatabaseName(dbname): - """ - Returns a database filename with the given base DB name appropriate for the - current PyLink instance. - - This returns '.db' if the running config name is PyLink's default - (pylink.yml), and '-.db' for anything else. For example, - if this is called from an instance running as './pylink testing.yml', it - would return '-testing.db'.""" - if conf.confname != 'pylink': - dbname += '-%s' % conf.confname - dbname += '.db' - return dbname - def splitHostmask(mask): """ Returns a nick!user@host hostmask split into three fields: nick, user, and host.