/usr/share/pyaimt/src/xmlconfig.py is in pyaimt 0.8.0.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | # Copyright 2005-2006 Daniel Henninger <jadestorm@nc.rr.com>
# Licensed for distribution under the GPL version 2, check COPYING for details
import utils
from twisted.words.xish.domish import Element
from debug import LogEvent, INFO, WARN, ERROR
import config
import sys
if type(True) != bool: from bool import bool
def invalidError(text):
print text
print "Exiting..."
sys.exit(1)
def importFile(conffile):
#if conffile[0] != "/":
# conffile = "../"+conffile
try:
document = utils.parseFile(conffile)
except Exception, e:
invalidError("Error parsing configuration file: " + str(e))
for child in document.elements():
tag = child.name
cdata = child.__str__()
children = [x for x in child.elements()]
if not hasattr(config, tag):
print "Ignoring unrecognized configuration option %r" % tag
elif type(getattr(config, tag)) == dict:
# For options like <settings><username>blar</username><password>foo</password></settings>
try:
if not cdata.isspace():
invalidError("Tag %r in your configuration file should be a dictionary (ie, must have subtags)." % (tag))
myDict = getattr(config, tag)
for child in children:
n = child.name
s = child.__str__()
myDict[n] = s
LogEvent(INFO, msg="Adding %r=%r to config dictionary %r" % (n, s, tag), skipargs=True)
except AttributeError:
print "Ignoring configuration option %r" % tag
elif type(getattr(config, tag)) == list:
# For options like <admins><jid>user1@host.com</jid><jid>user2@host.com</jid></admins>
try:
if not cdata.isspace():
invalidError("Tag %r in your configuration file should be a list (ie, must have subtags)." % (tag))
myList = getattr(config, tag)
for child in children:
s = child.__str__()
LogEvent(INFO, msg="Adding %r to config list %r" % (s, tag), skipargs=True)
myList.append(s)
except AttributeError:
print "Ignoring configuration option %r" % tag
elif type(getattr(config, tag)) == str:
# For config options like <ip>127.0.0.1</ip>
try:
if not cdata:
invalidError("Tag %r in your configuration file should be a string (ie, must have cdata)." % (tag))
LogEvent(INFO, msg="Setting config option %r = %r" % (tag, cdata), skipargs=True)
setattr(config, tag, cdata)
except AttributeError:
print "Ignoring configuration option %r" % tag
elif type(getattr(config, tag)) == int:
# For config options like <port>5347</port>
try:
if not cdata:
invalidError("Tag %r in your configuration file should be an integer (ie, must have numeric cdata)." % (tag))
LogEvent(INFO, msg="Setting config option %r = %r" % (tag, cdata), skipargs=True)
try:
setattr(config, tag, int(cdata))
except:
# Isn't an integer apparantly.
invalidError("Tag %r in your configuration file should be an integer (ie, must have numeric cdata)." % (tag))
except AttributeError:
print "Ignoring configuration option %r" % tag
elif type(getattr(config, tag)) == bool:
# For config options like <crossChat/>
try:
if cdata:
invalidError("Tag %r in your configuration file should be a boolean (ie, no cdata)." % (tag))
LogEvent(INFO, msg="Enabling config option %r" % (tag), skipargs=True)
setattr(config, tag, True)
except AttributeError:
print "Ignoring configuration option %r" % tag
elif isinstance(getattr(config, tag), config.DeprecatedVariable):
# For deprecated options, we will display a warning
getattr(config, tag)()
else:
print "Ignoring unrecognized configuration option %r [unrecognized type %s]" % (tag, type(getattr(config, tag)))
def importOptions(options):
for o in options:
LogEvent(INFO, msg="Setting config option %r = %r" % (o, options[o]), skipargs=True)
setattr(config, o, options[o])
def Import(file = None, options = None):
LogEvent(INFO, msg="Created configuration entity", skipargs=True)
if file != None:
importFile(file)
if options != None:
importOptions(options)
|