mirror of
https://github.com/jlu5/PyLink.git
synced 2025-02-18 22:40:44 +01:00
Refactor conf loading; skip the file-loading parts entirely for tests (#56)
This commit is contained in:
parent
cda54c71a5
commit
afd6d8c20d
36
conf.py
36
conf.py
@ -4,19 +4,6 @@ from collections import defaultdict
|
|||||||
|
|
||||||
import world
|
import world
|
||||||
|
|
||||||
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'
|
|
||||||
|
|
||||||
global testconf
|
global testconf
|
||||||
testconf = {'bot':
|
testconf = {'bot':
|
||||||
{
|
{
|
||||||
@ -43,13 +30,22 @@ testconf = {'bot':
|
|||||||
'maxnicklen': 20
|
'maxnicklen': 20
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if world.testing:
|
||||||
with open(fname, 'r') as f:
|
conf = testconf
|
||||||
global conf
|
confname = 'testconf'
|
||||||
if world.testing:
|
else:
|
||||||
conf = testconf
|
try:
|
||||||
confname = 'testconf'
|
# Get the config name from the command line, falling back to config.yml
|
||||||
else:
|
# 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:
|
||||||
try:
|
try:
|
||||||
conf = yaml.load(f)
|
conf = yaml.load(f)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
8
main.py
8
main.py
@ -4,15 +4,17 @@ import imp
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from log import log
|
# This must be done before conf imports, so we get the real conf instead of testing one.
|
||||||
|
import world
|
||||||
|
world.testing = False
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
|
from log import log
|
||||||
import classes
|
import classes
|
||||||
import utils
|
import utils
|
||||||
import coreplugin
|
import coreplugin
|
||||||
import world
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
world.testing = False
|
|
||||||
log.info('PyLink starting...')
|
log.info('PyLink starting...')
|
||||||
if conf.conf['login']['password'] == 'changeme':
|
if conf.conf['login']['password'] == 'changeme':
|
||||||
log.critical("You have not set the login details correctly! Exiting...")
|
log.critical("You have not set the login details correctly! Exiting...")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user