2005-08-16 10:12:25 +00:00
|
|
|
#!/usr/bin/env python
|
2006-02-13 22:44:29 +00:00
|
|
|
# vim: set sw=4 ts=4 si et:
|
2005-08-16 10:12:25 +00:00
|
|
|
|
|
|
|
from xml.dom.ext import *
|
|
|
|
from xml.dom.ext.reader.Sax import *
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from account import Account
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
def __init__(self):
|
|
|
|
# create an empty list
|
|
|
|
self.account_list=None
|
|
|
|
# initialise xmlTree
|
|
|
|
self.xmlTree=None
|
|
|
|
|
|
|
|
def loadFromFile(self,configFile):
|
|
|
|
self.xmlTree=FromXmlFile(configFile)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def getAccounts(self):
|
|
|
|
if self.xmlTree:
|
|
|
|
xmlAccountList = self.xmlTree.getElementsByTagName("account")
|
|
|
|
accountList=[]
|
|
|
|
for xmlAccount in xmlAccountList:
|
|
|
|
account=Account()
|
|
|
|
account.setHost(xmlAccount.getAttribute("host"))
|
|
|
|
account.setLogin(xmlAccount.getAttribute("login"))
|
|
|
|
account.setPassword(xmlAccount.getAttribute("password"))
|
|
|
|
xmlTransportList=xmlAccount.getElementsByTagName("transport")
|
|
|
|
for xmlTransport in xmlTransportList:
|
|
|
|
isdefault=xmlTransport.getAttribute("default")
|
|
|
|
if isdefault=="true":
|
|
|
|
account.setTransport(\
|
|
|
|
xmlTransport.getAttribute("host"),\
|
|
|
|
xmlTransport.getAttribute("protocol"))
|
|
|
|
account.setProtocol(\
|
|
|
|
xmlTransport.getAttribute("protocol"),\
|
|
|
|
xmlTransport.getAttribute("host"))
|
|
|
|
#TODO:add something to override servers' defaults
|
|
|
|
accountList.append(account)
|
|
|
|
return accountList
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|