mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-28 05:32:51 +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
|
||||
|
||||
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
|
||||
testconf = {'bot':
|
||||
{
|
||||
@ -43,13 +30,22 @@ testconf = {'bot':
|
||||
'maxnicklen': 20
|
||||
})
|
||||
}
|
||||
|
||||
with open(fname, 'r') as f:
|
||||
global conf
|
||||
if world.testing:
|
||||
conf = testconf
|
||||
confname = 'testconf'
|
||||
else:
|
||||
if world.testing:
|
||||
conf = testconf
|
||||
confname = 'testconf'
|
||||
else:
|
||||
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:
|
||||
try:
|
||||
conf = yaml.load(f)
|
||||
except Exception as e:
|
||||
|
8
main.py
8
main.py
@ -4,15 +4,17 @@ import imp
|
||||
import os
|
||||
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
|
||||
from log import log
|
||||
import classes
|
||||
import utils
|
||||
import coreplugin
|
||||
import world
|
||||
|
||||
if __name__ == '__main__':
|
||||
world.testing = False
|
||||
log.info('PyLink starting...')
|
||||
if conf.conf['login']['password'] == 'changeme':
|
||||
log.critical("You have not set the login details correctly! Exiting...")
|
||||
|
Loading…
Reference in New Issue
Block a user