#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------------
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------
import os
from common.log import log_error
from common.device import DeviceInfo
@ASYS_CHIP_HANDLER_IMPORT_STR@
class ChipHandler:
def __init__(self):
self.__support_chip_with_handler = {
@ASYS_CHIP_HANDLER_LIST_STR@
}
def get_support_chip_list(self):
return list(self.__support_chip_with_handler.keys())
def get_support_chip_regex(self, chip_type):
if chip_type not in self.get_support_chip_list():
return None
return self.__support_chip_with_handler.get(chip_type).get("regex")
def get_support_chip_regex_list(self):
return [item.get("regex") for item in self.__support_chip_with_handler.values()]
def get_handler(self, chip_type_str):
for support_type, item in self.__support_chip_with_handler.items():
if support_type in chip_type_str:
return item.get("handler")
return DeviceInfo()
g_device_map = {}
def get_device(device_id=None):
"""get device by chip, default is DeviceInfo"""
if device_id in g_device_map:
return g_device_map[device_id]
if device_id is None:
g_device_map[device_id] = DeviceInfo()
else:
chip_info = DeviceInfo().get_chip_info(device_id)
g_device_map[device_id] = ChipHandler().get_handler(chip_info)
return g_device_map[device_id]