Example #1
0
    def counting(self):
        # 每个COUNT_STATICS输出一个统计文件
        for i in COUNT_STATICS:
            ci = CountingItem(i)
            fs = ci.get_counting_files()
            fbasename = ci.get_counting_file_name()

            cr_one = CountingResult()
            if COUNTING_DETAILS:
                report_dirname = fbasename + time.strftime(FILE_TIME_FORMAT) + REPORT_SUFFIX
                report_file = codecs.open(report_dirname, mode="w", encoding="utf-8")
                assert report_file

            count_sum = len(fs)
            ncounter = 1
            usable.log("%s的文件总数: %d" % (fbasename, count_sum))
            stime = time.time()

            for j in fs:
                if j.endswith("rc"):
                    c = Counting_RC(j)
                else:
                    c = Couting_CPP(j)

                cr = c.counting()
                if not cr._success:
                    usable.error("统计文件%s 失败。" % (j))
                else:
                    cr_one += cr

                if COUNTING_DETAILS:
                    report_file.write(cr.get_details())

                if SHOW_PROCESSES:
                    usable.log("[%s:进度 %d/%d] :%s" % (fbasename, ncounter, count_sum, j))
                    ncounter += 1

            if COUNTING_DETAILS:
                report_file.close()

            fname = ci.get_counting_file_name() + COUNTING_RESULT_SUFFIX
            cr_one._filecount = len(fs)
            cr_one._filelist = fs

            cr_one.save_to(fname)
            usable.log("%s 统计耗时:%f" % (fbasename, time.time() - stime))
Example #2
0
 def log(self, msg, level=INFO):
     usable.log(msg, level)