Allow json or yaml config

This commit is contained in:
dpedu 2015-06-18 20:19:06 -07:00
parent 374dd17239
commit a6afeab07d
2 changed files with 18 additions and 1 deletions

View File

@ -24,7 +24,7 @@ if __name__ == "__main__":
log.critical("No bot config file specified (-c). Exiting.")
sys.exit(0)
botconfig = yaml.load(open(options.config, 'r'))
botconfig = PyIRCBot.load(options.config)
log.debug(botconfig)

View File

@ -341,3 +341,20 @@ class PyIRCBot:
ob.message = message
return ob
# return (True, command, args, message)
@staticmethod
def load(filepath):
"""Return an object from the passed filepath
:param filepath: path to a file of json or yaml format. filename must end with .json or .yml
:type filepath: str
"""
if filepath.endswith(".yml"):
from yaml import load
return load(open(filepath, 'r'))
elif filepath.endswith(".json"):
from json import load
return load(open(filepath, 'r'))
else:
raise Exception("Unknown config format")