]> code.delx.au - pymsnt/blob - src/xmlconfig.py
Reimporting (0.9.5)
[pymsnt] / src / xmlconfig.py
1 # Copyright 2004 James Bunton <james@delx.cjb.net>
2 # Licensed for distribution under the GPL version 2, check COPYING for details
3
4
5 import sys
6 import os
7
8 import utils
9 import config
10
11
12 def invalidError(text):
13 print text
14 print "Exiting..."
15 sys.exit(1)
16
17
18 def reloadConfig():
19 # Find out where the config file is
20 configFile = "../config.xml"
21 if(len(sys.argv) == 2):
22 configFile = sys.argv[1]
23
24 # Check the file exists
25 if(not os.path.isfile(configFile)):
26 print "Configuration file not found. You need to create a config.xml file in the PyMSNt directory."
27 sys.exit(1)
28
29 # Get ourself a DOM
30 root = utils.parseFile(configFile)
31
32 # Store all the options in config
33 for el in root.elements():
34 try:
35 tag = el.name
36 cdata = str(el)
37 if(cdata):
38 # For config options like <ip>127.0.0.1</ip>
39 if(type(getattr(config, tag)) != str):
40 invalidError("Tag %s in your configuration file should be a boolean (ie, no cdata)." % (tag))
41 setattr(config, tag, cdata)
42 else:
43 # For config options like <sessionGreeting/>
44 if(type(getattr(config, tag)) not in [bool, int]):
45 invalidError("Tag %s in your configuration file should be a string (ie, must have cdata)." % (tag))
46 setattr(config, tag, True)
47 except AttributeError:
48 print "Tag %s in your configuration file is not a defined tag. Ignoring!" % (tag)
49
50