45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
|
#!/usr/bin/env python
|
||
|
|
||
|
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
|
||
|
|