]>
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
12 def invalidError(text
):
18 def importFile(configFile
):
19 # Check the file exists
20 if not os
.path
.isfile(configFile
):
21 print "Configuration file not found. You need to create a config.xml file in the PyMSNt directory."
26 root
= xmlw
.parseFile(configFile
)
28 invalidError("Error parsing configuration file: " + str(e
))
30 # Store all the options in config
31 for el
in root
.elements():
35 children
= [x
for x
in el
.elements()]
37 # For options like <admins><jid>user1@host.com</jid><jid>user2@host.com</jid></admins>
38 if type(getattr(config
, tag
)) != list:
39 invalidError("Tag %s in your configuration file should be a list (ie, must have subtags)." % (tag
))
40 myList
= getattr(config
, tag
)
41 for child
in children
:
45 # For config options like <ip>127.0.0.1</ip>
46 if type(getattr(config
, tag
)) != str:
47 invalidError("Tag %s in your configuration file should not be a string (ie, no cdata)." % (tag
))
48 setattr(config
, tag
, cdata
)
50 # For config options like <sessionGreeting/>
51 t
= type(getattr(config
, tag
))
52 if not (t
== bool or t
== int):
53 invalidError("Tag %s in your configuration file should not be a boolean (ie, must have cdata or subtags)." % (tag
))
54 setattr(config
, tag
, True)
55 except AttributeError:
56 print "Tag %s in your configuration file is not a defined tag. Ignoring!" % (tag
)
59 def importOptions(options
):
61 if hasattr(config
, o
):
62 setattr(config
, o
, options
[o
])
64 print "Option %s is not a defined option. Ignoring!" % (o
)
66 def reloadConfig(file=None, options
=None):
70 importOptions(options
)