1ba991379Sopenharmony_ciimport os
2ba991379Sopenharmony_ciimport time
3ba991379Sopenharmony_ci# import shutil
4ba991379Sopenharmony_cilocal_path = 'D:\Local\ATLog'
5ba991379Sopenharmony_ciwait_count = 0
6ba991379Sopenharmony_citotal_count = 0
7ba991379Sopenharmony_cifail_count = 0
8ba991379Sopenharmony_cilog_path = 'D:/MobileUpgrade/fail_upgrade_list.log'
9ba991379Sopenharmony_ci
10ba991379Sopenharmony_ciif os.path.exists(log_path):
11ba991379Sopenharmony_ci    print("删除以往日志")
12ba991379Sopenharmony_ci    os.remove(log_path)
13ba991379Sopenharmony_ci
14ba991379Sopenharmony_ci
15ba991379Sopenharmony_ciwith open(log_path,'a+') as fw:
16ba991379Sopenharmony_ci    fw.write('开始遍历日志'.center(100,'*'))
17ba991379Sopenharmony_ci    fw.write('\n')
18ba991379Sopenharmony_cifor dir_path, dir_names, file_names in os.walk(local_path):
19ba991379Sopenharmony_ci    if 'upgrade.log' in file_names:
20ba991379Sopenharmony_ci        total_count += 1
21ba991379Sopenharmony_ci        # print(dir_path, dir_names, file_names)
22ba991379Sopenharmony_ci        try:
23ba991379Sopenharmony_ci            items = dir_path.split(os.sep)
24ba991379Sopenharmony_ci            block_name, task_name = (items[-1],items[-2])
25ba991379Sopenharmony_ci        except Exception as e:
26ba991379Sopenharmony_ci            print(dir_path)
27ba991379Sopenharmony_ci            print(str(e))
28ba991379Sopenharmony_ci        with open(os.path.join(dir_path, 'upgrade.log'),'r') as fr:
29ba991379Sopenharmony_ci            if 'upgrade failed' in fr.read():
30ba991379Sopenharmony_ci                fail_count += 1
31ba991379Sopenharmony_ci                with open(log_path,'a+') as fw:
32ba991379Sopenharmony_ci                    print(f'发现失败任务:{task_name}')
33ba991379Sopenharmony_ci                    fw.write(f'失败任务路径:{dir_path}\n')
34ba991379Sopenharmony_ci                    wait_count += 1
35ba991379Sopenharmony_ci    if wait_count == 5:
36ba991379Sopenharmony_ci        wait_count = 0
37ba991379Sopenharmony_ci        # time.sleep(30)
38ba991379Sopenharmony_ci
39ba991379Sopenharmony_ciwith open(log_path,'a+') as fw:
40ba991379Sopenharmony_ci    fw.write('失败日志遍历结束'.center(100,'*'))
41ba991379Sopenharmony_ci    fw.write('\n')
42ba991379Sopenharmony_ci    fw.write(f'总共检索日志:{total_count}个\n')
43ba991379Sopenharmony_ci    fw.write(f'其中存在失败的日志:{fail_count}个\n')