Add new tag load in xml configuration file

This commit is contained in:
Némunaire 2012-06-23 15:12:15 +02:00
parent 7a91c49acf
commit 4f3b4099eb

View File

@ -168,25 +168,32 @@ def load_module(config, servers):
print (" Module `%s' not loaded: unable to find module implementation." % config["name"]) print (" Module `%s' not loaded: unable to find module implementation." % config["name"])
def load(cmds, servers): def load_file(filename, servers):
"""Load an XML configuration file""" """Realy load a file"""
if len(cmds) > 1: config = xmlparser.parse_file(filename)
for f in cmds[1:]:
config = xmlparser.parse_file(f)
if config.getName() == "nemubotconfig" or config.getName() == "config": if config.getName() == "nemubotconfig" or config.getName() == "config":
#Preset each server in this file #Preset each server in this file
for serveur in config.getChilds(): for serveur in config.getNodes("server"):
srv = server.Server(serveur, config.getAttribute('nick'), config.getAttribute('owner'), config.getAttribute('realname')) srv = server.Server(serveur, config["nick"], config["owner"], config["realname"])
if srv.id not in servers: if srv.id not in servers:
servers[srv.id] = srv servers[srv.id] = srv
print (" Server `%s' successfully added." % srv.id) print (" Server `%s' successfully added." % srv.id)
else: else:
print (" Server `%s' already added, skiped." % srv.id) print (" Server `%s' already added, skiped." % srv.id)
#Load files asked by the configuration file
for load in config.getNodes("load"):
load_file(load["path"], servers)
elif config.getName() == "nemubotmodule": elif config.getName() == "nemubotmodule":
load_module(config, servers) load_module(config, servers)
else: else:
print (" Can't load `%s'; this is not a valid nemubot configuration file." % f) print (" Can't load `%s'; this is not a valid nemubot configuration file." % f)
def load(cmds, servers):
"""Load an XML configuration file"""
if len(cmds) > 1:
for f in cmds[1:]:
load_file(f, servers)
else: else:
print ("Not enough arguments. `load' takes an filename.") print ("Not enough arguments. `load' takes an filename.")
return return