Added ability to override conf.py defaults with -c option

This commit is contained in:
Jeremy Fincher 2003-03-27 09:45:39 +00:00
parent 2719dcd8bd
commit 5e785ba212

View File

@ -37,16 +37,9 @@ from fix import *
import sys import sys
import email import email
import getopt
import conf import conf
import world
import debug
import irclib
import ircmsgs
import drivers
import schedule
import privmsgs
import asyncoreDrivers
sys.path.append(conf.pluginDir) sys.path.append(conf.pluginDir)
@ -69,6 +62,16 @@ class ConfigurationDict(dict):
return dict.__contains__(self, key.lower()) return dict.__contains__(self, key.lower())
def processConfigFile(filename):
import debug
import world
import irclib
import ircmsgs
import privmsgs
import asyncoreDrivers
def reportConfigError(filename, msg):
debug.recoverableError('%s: %s' % (filename, msg))
class ConfigAfter376(irclib.IrcCallback): class ConfigAfter376(irclib.IrcCallback):
public = False public = False
def __init__(self, msgs): def __init__(self, msgs):
@ -80,11 +83,6 @@ class ConfigAfter376(irclib.IrcCallback):
irc.queueMsg(msg) irc.queueMsg(msg)
do377 = do376 do377 = do376
def reportConfigError(filename, msg):
debug.recoverableError('%s: %s' % (filename, msg))
def processConfigFile(filename):
try: try:
fd = file(filename) fd = file(filename)
m = email.message_from_file(fd) m = email.message_from_file(fd)
@ -134,7 +132,23 @@ def processConfigFile(filename):
reportConfigError(filename, msg) reportConfigError(filename, msg)
def main(): def main():
for filename in sys.argv[1:]: (optlist, filenames) = getopt.getopt(sys.argv[1:], 'c:')
for (option, argument) in optlist:
if option == '-c':
myLocals = {}
myGlobals = {}
execfile(argument, myGlobals, myLocals)
for (key, value) in myGlobals.iteritems():
setattr(conf, key, value)
for (key, value) in myLocals.iteritems():
setattr(conf, key, value)
else:
print 'Unexpected argument %s; ignoring.' % option
import debug
import world
import drivers
import schedule
for filename in filenames:
processConfigFile(filename) processConfigFile(filename)
schedule.addPeriodicEvent(world.upkeep, 300) schedule.addPeriodicEvent(world.upkeep, 300)
try: try: