1#!/usr/bin/env python3 2# coding=utf-8 3 4# 5# Copyright (c) 2021 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 20 21from distributed.common.devices import DeviceShell 22 23 24############################################################################## 25############################################################################## 26 27class DeviceManager: 28 def __init__(self, result_path): 29 self.is_hdc = True 30 self.phone_device_list = [] 31 self.ivi_device_list = [] 32 self.tv_device_list = [] 33 self.watch_device_list = [] 34 self.make_device_list(result_path) 35 36 def make_device_adapter(self, device_info_list, device_name): 37 device = DeviceShell(self.is_hdc, device_sn=device_info_list[0], 38 remote_ip=device_info_list[2], 39 repote_port=device_info_list[3], 40 name=device_name) 41 return device 42 43 def make_device_list(self, result_path): 44 device_info_list = self.get_device_info_list(result_path) 45 for item in device_info_list: 46 if len(item) != 4: 47 continue 48 if item[1] == "phone": 49 index = len(self.phone_device_list) + 1 50 device_name = "PHONE%s" % index 51 device = self.make_device_adapter(item, device_name) 52 self.phone_device_list.append(device) 53 setattr(self, device.name, device) 54 elif item[1] == "ivi": 55 index = len(self.ivi_device_list) + 1 56 device_name = "IVI%s" % index 57 device = self.make_device_adapter(item, device_name) 58 self.ivi_device_list.append(device) 59 setattr(self, device.name, device) 60 elif item[1] == "tv": 61 index = len(self.tv_device_list) + 1 62 device_name = "TV%s" % index 63 device = self.make_device_adapter(item, device_name) 64 self.tv_device_list.append(device) 65 setattr(self, device.name, device) 66 elif item[1] == "watch": 67 index = len(self.watch_device_list) + 1 68 device_name = "WATCH%s" % index 69 device = self.make_device_adapter(item, device_name) 70 self.watch_device_list.append(device) 71 setattr(self, device.name, device) 72 return 73 74 @staticmethod 75 def get_device_info_list(result): 76 device_info_list = [] 77 tmp_path = os.path.join(result, "temp") 78 device_info_file_path = os.path.join(tmp_path, 79 "device_info_file.txt") 80 81 if os.path.exists(device_info_file_path): 82 with open(device_info_file_path, "r") as file_handle: 83 lines = file_handle.readlines() 84 for line in lines: 85 line = line.replace("\n", "") 86 line = line.strip() 87 temp = line.split(",") 88 device_info_list.append(temp) 89 return device_info_list 90 91############################################################################## 92############################################################################## 93