diff --git a/.gitignore b/.gitignore index a4918e7..d1e6f0b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -config.yml +*.yml build/ __pycache__/ *.py[cod] @@ -6,4 +6,4 @@ __pycache__/ *~ *.save* *.db -pylink.pid +*.pid diff --git a/conf.py b/conf.py index 6bdda47..8a102b5 100644 --- a/conf.py +++ b/conf.py @@ -1,5 +1,19 @@ import yaml +import sys -with open("config.yml", 'r') as f: +global confname +try: + # Get the config name from the command line, falling back to config.yml + # if not given. + fname = sys.argv[1] + confname = fname.split('.', 1)[0] +except IndexError: + # confname is used for logging and PID writing, so that each + # instance uses its own files. fname is the actual name of the file + # we load. + confname = 'pylink' + fname = 'config.yml' + +with open(fname, 'r') as f: global conf conf = yaml.load(f) diff --git a/log.py b/log.py index 3f6180f..67a84d7 100644 --- a/log.py +++ b/log.py @@ -2,7 +2,7 @@ import logging import sys import os -from conf import conf +from conf import conf, confname level = conf['bot'].get('loglevel') or 'DEBUG' try: @@ -21,7 +21,7 @@ logging.basicConfig(level=level, format=_format) # Set log file to $CURDIR/log/pylink logformat = logging.Formatter(_format) -logfile = logging.FileHandler(os.path.join(logdir, 'pylink.log'), mode='w') +logfile = logging.FileHandler(os.path.join(logdir, '%s.log' % confname), mode='w') logfile.setFormatter(logformat) global log diff --git a/main.py b/main.py index f72f8e0..7709260 100755 --- a/main.py +++ b/main.py @@ -205,7 +205,7 @@ if __name__ == '__main__': protocols_folder = [os.path.join(os.getcwd(), 'protocols')] # Write a PID file. - with open('pylink.pid', 'w') as f: + with open('%s.pid' % conf.confname, 'w') as f: f.write(str(os.getpid())) # Import plugins first globally, because they can listen for events diff --git a/plugins/relay.py b/plugins/relay.py index 5f57968..31b2c1d 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -10,8 +10,12 @@ from collections import defaultdict import utils from log import log +from conf import confname -dbname = "pylinkrelay.db" +dbname = "pylinkrelay" +if confname != 'pylink': + dbname += '-%s' % confname +dbname += '.db' relayusers = defaultdict(dict) def relayWhoisHandlers(irc, target):