Allow json or yaml config
This commit is contained in:
parent
374dd17239
commit
a6afeab07d
@ -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)
|
||||
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user