]> code.delx.au - pymsnt/blobdiff - src/xmlconfig.py
Reimport and tags (0.10.1)
[pymsnt] / src / xmlconfig.py
index b630d95ebd93f80128912c564fafeca0ce5911b6..e461d7ef3fd0fcc4862e587d3fa7f109d95c0b78 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2004 James Bunton <james@delx.cjb.net>
+# Copyright 2004-2005 James Bunton <james@delx.cjb.net>
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
 
@@ -9,6 +9,7 @@ import utils
 import config
 
 
+
 def invalidError(text):
        print text
        print "Exiting..."
@@ -17,32 +18,45 @@ def invalidError(text):
 
 def reloadConfig():
        # Find out where the config file is
-       configFile = "../config.xml"
-       if(len(sys.argv) == 2):
+       configFile = "config.xml"
+       if len(sys.argv) == 2:
                configFile = sys.argv[1]
 
        # Check the file exists
-       if(not os.path.isfile(configFile)):
+       if not os.path.isfile(configFile):
                print "Configuration file not found. You need to create a config.xml file in the PyMSNt directory."
                sys.exit(1)
 
        # Get ourself a DOM
-       root = utils.parseFile(configFile)
+       try:
+               root = utils.parseFile(configFile)
+       except Exception, e:
+               invalidError("Error parsing configuration file: " + str(e))
 
        # Store all the options in config
        for el in root.elements():
                try:
                        tag = el.name
                        cdata = str(el)
-                       if(cdata):
+                       children = [x for x in el.elements()]
+                       if children:
+                               # For options like <admins><jid>user1@host.com</jid><jid>user2@host.com</jid></admins>
+                               if type(getattr(config, tag)) != list:
+                                       invalidError("Tag %s in your configuration file should be a list (ie, must have subtags)." % (tag))
+                               myList = getattr(config, tag)
+                               for child in children:
+                                       s = child.__str__()
+                                       myList.append(s)
+                       elif cdata:
                                # For config options like <ip>127.0.0.1</ip>
-                               if(type(getattr(config, tag)) != str):
-                                       invalidError("Tag %s in your configuration file should be a boolean (ie, no cdata)." % (tag))
+                               if type(getattr(config, tag)) != str:
+                                       invalidError("Tag %s in your configuration file should not be a string (ie, no cdata)." % (tag))
                                setattr(config, tag, cdata)
                        else:
                                # For config options like <sessionGreeting/>
-                               if(type(getattr(config, tag)) not in [bool, int]):
-                                       invalidError("Tag %s in your configuration file should be a string (ie, must have cdata)." % (tag))
+                               t = type(getattr(config, tag))
+                               if not (t == bool or t == int):
+                                       invalidError("Tag %s in your configuration file should not be a boolean (ie, must have cdata or subtags)." % (tag))
                                setattr(config, tag, True)
                except AttributeError:
                        print "Tag %s in your configuration file is not a defined tag. Ignoring!" % (tag)