1#!/usr/bin/env python3
2#-*- coding: utf-8 -*-
3
4# Copyright (c) 2024 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import json
18import os
19
20
21def read_json_files_in_directory(path, type_device):
22    """
23    @func:Configuration file to be modified
24    @param path: path name
25    @param type_device:Types that need to be modified
26    """
27    if not os.path.exists(path):
28        print(f"path:'{path}'not exist")
29        return
30    for root, dirs, files in os.walk(path):
31        for filename in files:
32            if filename.endswith('.json'):
33                filepath = os.path.join(root, filename)
34                with open(filepath, 'r', encoding='utf-8') as f:
35                    data = json.load(f)
36                for item in data['environment']:
37                    item['label'] = type_device
38                data = json.dumps(data, indent=4, ensure_ascii=False)
39                with open(filepath, 'w', encoding='utf-8') as f:
40                    f.write(data)
41
42
43json_path = "testcases"
44
45all_types = ["phone", "car", "tv", "watch", "tablet", "2in1"]
46all_types_name = ["phone", "car", "tv", "watch", "tablet", "pc"]
47print("Please enter the serial number of the device to be tested:1 2 3 4 5 6")
48print("1:phone")
49print("2:car")
50print("3:tv")
51print("4:watch")
52print("5:tablet")
53print("6:pc")
54print("please input:")
55type_number = int(input())
56numbers = [1, 2, 3, 4, 5, 6]
57if type_number not in numbers:
58    print("Input error, please execute again")
59else:
60    type_device = all_types[type_number - 1]
61    read_json_files_in_directory(json_path, type_device)
62    print("Select Test " + all_types_name[type_number - 1] + " successfully!")
63