3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +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 return conf
def loadConf(filename, errors_fatal=True, logger=None): def loadConf(filename, errors_fatal=True, logger=None):
"""Loads a PyLink configuration file from the filename given.""" """Loads a PyLink configuration file from the filename given."""
global confname, conf, fname global confname, conf, fname
@ -134,3 +133,17 @@ def loadConf(filename, errors_fatal=True, logger=None):
raise raise
else: else:
return conf 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 error = modebot.error
# Databasing variables. # Databasing variables.
dbname = utils.getDatabaseName('automode') dbname = conf.getDatabaseName('automode')
datastore = structures.JSONDataStore('automode', dbname, default_db=collections.defaultdict(dict)) datastore = structures.JSONDataStore('automode', dbname, default_db=collections.defaultdict(dict))
db = datastore.store db = datastore.store

View File

@ -18,7 +18,7 @@ relayservers = defaultdict(dict)
spawnlocks = defaultdict(threading.RLock) spawnlocks = defaultdict(threading.RLock)
spawnlocks_servers = defaultdict(threading.RLock) spawnlocks_servers = defaultdict(threading.RLock)
dbname = utils.getDatabaseName('pylinkrelay') dbname = conf.getDatabaseName('pylinkrelay')
datastore = structures.PickleDataStore('pylinkrelay', dbname) datastore = structures.PickleDataStore('pylinkrelay', dbname)
db = datastore.store db = datastore.store

View File

@ -112,20 +112,6 @@ def getProtocolModule(name):
""" """
return importlib.import_module(PROTOCOL_PREFIX + 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): def splitHostmask(mask):
""" """
Returns a nick!user@host hostmask split into three fields: nick, user, and host. Returns a nick!user@host hostmask split into three fields: nick, user, and host.