]>
code.delx.au - pymsnt/blob - src/xmlconfig.py
1 # Copyright 2004-2005 James Bunton <james@delx.cjb.net>
2 # Licensed for distribution under the GPL version 2, check COPYING for details
13 def invalidError(text
):
20 # Find out where the config file is
21 configFile
= "config.xml"
22 if len(sys
.argv
) == 2:
23 configFile
= sys
.argv
[1]
25 # Check the file exists
26 if not os
.path
.isfile(configFile
):
27 print "Configuration file not found. You need to create a config.xml file in the PyMSNt directory."
32 root
= utils
.parseFile(configFile
)
34 invalidError("Error parsing configuration file: " + str(e
))
36 # Store all the options in config
37 for el
in root
.elements():
41 children
= [x
for x
in el
.elements()]
43 # For options like <admins><jid>user1@host.com</jid><jid>user2@host.com</jid></admins>
44 if type(getattr(config
, tag
)) != list:
45 invalidError("Tag %s in your configuration file should be a list (ie, must have subtags)." % (tag
))
46 myList
= getattr(config
, tag
)
47 for child
in children
:
51 # For config options like <ip>127.0.0.1</ip>
52 if type(getattr(config
, tag
)) != str:
53 invalidError("Tag %s in your configuration file should not be a string (ie, no cdata)." % (tag
))
54 setattr(config
, tag
, cdata
)
56 # For config options like <sessionGreeting/>
57 t
= type(getattr(config
, tag
))
58 if not (t
== bool or t
== int):
59 invalidError("Tag %s in your configuration file should not be a boolean (ie, must have cdata or subtags)." % (tag
))
60 setattr(config
, tag
, True)
61 except AttributeError:
62 print "Tag %s in your configuration file is not a defined tag. Ignoring!" % (tag
)