資源簡介
從xml文件中讀取信息,存儲到csv文件
代碼片段和文件信息
#!/usr/bin/env?python
#?-*-?coding:utf-8?-*-
import?sysosstringiorecsvtime
from?datetime?import?datetime
class?CollectUTCoveragexml(object):
????def?__init__(self):
????????self.__coverage_xml_list?=?[]
????def?__Test2(self?src_dir):
????????for?lists?in?os.listdir(src_dir):
????????????path?=?os.path.join(src_dir?lists)
????????????if?‘coverage.xml‘?in?path?and?(‘a(chǎn)bc-ut‘?not?in?path):
????????????????print?path
????????????????self.__coverage_xml_list.append(path)
????????????if?os.path.isdir(path)?and?‘-ut‘?in?path?and?(‘a(chǎn)bc-ut‘?not?in?path):
????????????????self.Test2(path)
????def?__get_coverage_rate_list(self):
????????coverage_rate_list?=?[]
????????rate_info?={}
????????if?len(self.__coverage_xml_list)?>?0:
????????????for?one_xml?in?self.__coverage_xml_list:
????????????????one_xml_path_info?=?one_xml.split(‘/‘)
????????????????build_pattern?=?re.compile(‘[0-9]+‘)
????????????????build_info_temp?=?one_xml_path_info[-2]
????????????????result?=?build_pattern.match(build_info_temp)
????????????????if?result?is?not?None:
????????????????????with?open(one_xml)?as?f:
????????????????????????for?line?in?f:
????????????????????????????if?‘timestamp‘?in?line:
????????????????????????????????useful_line?=?line
????????????????????????????????line_rate?=?useful_line.split(‘?‘)[1].split(‘=‘)[1].replace(‘\‘‘‘‘)
????????????????????????????????branch_rate?=?useful_line.split(‘?‘)[2].split(‘=‘)[1].replace(‘\‘‘‘‘)
????????????????????????????????complexity?=?useful_line.split(‘?‘)[7].split(‘=‘)[1].replace(‘\‘‘‘‘)
????????????????????????????????timestamp?=?useful_line.split(‘?‘)[9].split(‘=‘)[1].replace(“>\n“‘‘).replace(‘\‘‘‘‘)
????????????????????????????????print?“##########xml_path?is###################“os.path.abspath(one_xml)
????????????????????????????????print?“###########timestamp####################“?timestamp
????????????????????????????????ut_run_time?=?datetime.fromtimestamp(float(timestamp)/1000.0).strftime(“%Y-%m-%d“)
????????????????????????????????rate_info?=?{“l(fā)ine_rate“:line_rate?“branch_rate“:branch_rate
?????????????????????????????????????????????“complexity“:complexity?“ut_run_time“:ut_run_time
- 上一篇:淘寶網(wǎng)頁數(shù)據(jù)爬蟲
- 下一篇:淘寶秒殺python腳本
評論
共有 條評論