'''
该模块是用来读取配置文件,
通过正则表达式来获取下载路径和保存路径。
文件初始化时打开文件并读取配置文件信息
主要包括三个函数:
getDownPath():用来获取下载路径
getSavePath():用来获取保存路径
getSavePath():用来关闭文件
'''
import re
import os
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
class Config(object):
def __init__(self,configPath=PATH("..\config.xml")):
try:
self.configPath=configPath
self.configHandler=open(self.configPath,"rb")
self.configInfor=self.configHandler.read()
except IOError,e:
self.configHandler.close()
print e
def getDownPath(self):
getdwpath=re.findall('<Download>(.*)?</Download>', self.configInfor,re.S)
return getdwpath[0]
def getSavePath(self):
getsvpath=re.findall("<SavePath>(.*)?</SavePath>", self.configInfor,re.S)
return getsvpath[0]
def SetCmdImage(self):
setCmd=re.findall("<SetCmdImage>(.*)?</SetCmdImage>", self.configInfor,re.S)
return setCmd[0]
def RunErrorImage(self):
errorImage=re.findall("<RunErrorImage>(.*)?</RunErrorImage>", self.configInfor,re.S)
return errorImage[0]
def ExecResutlImage(self):
resultImage=re.findall("<ExecResutlImage>(.*)?</ExecResutlImage>", self.configInfor,re.S)
return resultImage[0]
def getXQLCMD(self):
xqlcmd=re.findall("<XQLCmd>(.*)?</XQLCmd>", self.configInfor,re.S)
return xqlcmd[0]
def getDiffPath(self):
xqlcmd=re.findall("<DiffPath>(.*)?</DiffPath>", self.configInfor,re.S)
return xqlcmd[0]
def getRequirementDocPath(self):
xqlcmd=re.findall("<RequirementDoc>(.*)?</RequirementDoc>", self.configInfor,re.S)
return xqlcmd[0]
def closeFile(self):
self.configHandler.close()
def test():
path="E:\PythonDemo\AutonXQL_V1.0\config.xml"
'''
创建一个测试脚本,执行冒烟测试。
用来验证程序功能能正常运行。
在运行该程序时,需要修改self.configPath
如果没有修改,会出现异常信息。
'''
config=Config(path)
print config.getDownPath()
print config.getSavePath()
config.closeFile()
print config.configPath
print config.ExecResutlImage()
print config.getRequirementDocPath()
print config.getXQLCMD()
if __name__=="__main__":
test()