15ba71b47Sopenharmony_ci#!/usr/bin/env python3 25ba71b47Sopenharmony_ci#-*- coding: utf-8 -*- 35ba71b47Sopenharmony_ci 45ba71b47Sopenharmony_ci# Copyright (c) 2024 Huawei Device Co., Ltd. 55ba71b47Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 65ba71b47Sopenharmony_ci# you may not use this file except in compliance with the License. 75ba71b47Sopenharmony_ci# You may obtain a copy of the License at 85ba71b47Sopenharmony_ci# 95ba71b47Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 105ba71b47Sopenharmony_ci# 115ba71b47Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 125ba71b47Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 135ba71b47Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 145ba71b47Sopenharmony_ci# See the License for the specific language governing permissions and 155ba71b47Sopenharmony_ci# limitations under the License. 165ba71b47Sopenharmony_ci 175ba71b47Sopenharmony_ciimport json 185ba71b47Sopenharmony_ciimport os 195ba71b47Sopenharmony_ci 205ba71b47Sopenharmony_ci 215ba71b47Sopenharmony_cidef read_json_files_in_directory(path, type_device): 225ba71b47Sopenharmony_ci """ 235ba71b47Sopenharmony_ci @func:Configuration file to be modified 245ba71b47Sopenharmony_ci @param path: path name 255ba71b47Sopenharmony_ci @param type_device:Types that need to be modified 265ba71b47Sopenharmony_ci """ 275ba71b47Sopenharmony_ci if not os.path.exists(path): 285ba71b47Sopenharmony_ci print(f"path:'{path}'not exist") 295ba71b47Sopenharmony_ci return 305ba71b47Sopenharmony_ci for root, dirs, files in os.walk(path): 315ba71b47Sopenharmony_ci for filename in files: 325ba71b47Sopenharmony_ci if filename.endswith('.json'): 335ba71b47Sopenharmony_ci filepath = os.path.join(root, filename) 345ba71b47Sopenharmony_ci with open(filepath, 'r', encoding='utf-8') as f: 355ba71b47Sopenharmony_ci data = json.load(f) 365ba71b47Sopenharmony_ci for item in data['environment']: 375ba71b47Sopenharmony_ci item['label'] = type_device 385ba71b47Sopenharmony_ci data = json.dumps(data, indent=4, ensure_ascii=False) 395ba71b47Sopenharmony_ci with open(filepath, 'w', encoding='utf-8') as f: 405ba71b47Sopenharmony_ci f.write(data) 415ba71b47Sopenharmony_ci 425ba71b47Sopenharmony_ci 435ba71b47Sopenharmony_cijson_path = "testcases" 445ba71b47Sopenharmony_ci 455ba71b47Sopenharmony_ciall_types = ["phone", "car", "tv", "watch", "tablet", "2in1"] 465ba71b47Sopenharmony_ciall_types_name = ["phone", "car", "tv", "watch", "tablet", "pc"] 475ba71b47Sopenharmony_ciprint("Please enter the serial number of the device to be tested:1 2 3 4 5 6") 485ba71b47Sopenharmony_ciprint("1:phone") 495ba71b47Sopenharmony_ciprint("2:car") 505ba71b47Sopenharmony_ciprint("3:tv") 515ba71b47Sopenharmony_ciprint("4:watch") 525ba71b47Sopenharmony_ciprint("5:tablet") 535ba71b47Sopenharmony_ciprint("6:pc") 545ba71b47Sopenharmony_ciprint("please input:") 555ba71b47Sopenharmony_citype_number = int(input()) 565ba71b47Sopenharmony_cinumbers = [1, 2, 3, 4, 5, 6] 575ba71b47Sopenharmony_ciif type_number not in numbers: 585ba71b47Sopenharmony_ci print("Input error, please execute again") 595ba71b47Sopenharmony_cielse: 605ba71b47Sopenharmony_ci type_device = all_types[type_number - 1] 615ba71b47Sopenharmony_ci read_json_files_in_directory(json_path, type_device) 625ba71b47Sopenharmony_ci print("Select Test " + all_types_name[type_number - 1] + " successfully!") 63