3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-28 13:42:37 +01:00

Move getDatabaseName from utils to conf (#476)

This commit is contained in:
James Lu 2017-08-28 20:27:39 -07:00
parent ff8587736f
commit 43b6566aa8
4 changed files with 16 additions and 17 deletions

15
conf.py
View File

@ -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 '<dbname>.db' if the running config name is PyLink's default
(pylink.yml), and '<dbname>-<config name>.db' for anything else. For example,
if this is called from an instance running as './pylink testing.yml', it
would return '<dbname>-testing.db'."""
if confname != 'pylink':
dbname += '-%s' % conf.confname
dbname += '.db'
return dbname

View File

@ -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

View File

@ -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

View File

@ -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 '<dbname>.db' if the running config name is PyLink's default
(pylink.yml), and '<dbname>-<config name>.db' for anything else. For example,
if this is called from an instance running as './pylink testing.yml', it
would return '<dbname>-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.