1#!/usr/bin/env python3 2# coding=utf-8 3 4# 5# Copyright (c) 2020-2023 Huawei Device Co., Ltd. 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19import os 20import subprocess 21import traceback 22import json 23 24 25if __name__ == '__main__': 26 try: 27 current_path = os.getcwd() 28 root_path = current_path.split("/test/testfwk/developer_test")[0] 29 subsystem_config_path = os.path.join( 30 root_path, "test/testfwk/developer_test/localCoverage/restore_comment/part_config.json") 31 if os.path.exists(subsystem_config_path): 32 with open(subsystem_config_path, "r", encoding="utf-8", errors="ignore") as fp: 33 data_dict = json.load(fp) 34 for key, value in data_dict.items(): 35 if "path" in value.keys(): 36 for path_str in value["path"]: 37 file_path = os.path.join(root_path, path_str) 38 if os.path.exists(file_path): 39 if os.path.exists(f"{file_path}_primal"): 40 subprocess.Popen("rm -rf %s" % file_path, shell=True).communicate() 41 subprocess.Popen("mv %s %s" % ( 42 f"{file_path}_primal", file_path), shell=True).communicate() 43 else: 44 print("The directory does not exist.", file_path) 45 except(FileNotFoundError, AttributeError, ValueError, KeyError): 46 print("restore source code Error") 47