资源简介

从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 (‘abc-ut‘ not in path):
                print path
                self.__coverage_xml_list.append(path)

            if os.path.isdir(path) and ‘-ut‘ in path and (‘abc-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 = {“line_rate“:line_rate “branch_rate“:branch_rate
                                             “complexity“:complexity “ut_run_time“:ut_run_time

评论

共有 条评论