15f9996aaSopenharmony_ci#!/usr/bin/env python3 25f9996aaSopenharmony_ci# -*- coding: utf-8 -*- 35f9996aaSopenharmony_ci 45f9996aaSopenharmony_ci# 55f9996aaSopenharmony_ci# Copyright (c) 2023 Huawei Device Co., Ltd. 65f9996aaSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 75f9996aaSopenharmony_ci# you may not use this file except in compliance with the License. 85f9996aaSopenharmony_ci# You may obtain a copy of the License at 95f9996aaSopenharmony_ci# 105f9996aaSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 115f9996aaSopenharmony_ci# 125f9996aaSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 135f9996aaSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 145f9996aaSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 155f9996aaSopenharmony_ci# See the License for the specific language governing permissions and 165f9996aaSopenharmony_ci# limitations under the License. 175f9996aaSopenharmony_ci# 185f9996aaSopenharmony_ci 195f9996aaSopenharmony_ciimport json 205f9996aaSopenharmony_ci 215f9996aaSopenharmony_cifrom resources.global_var import STATUS_FILE 225f9996aaSopenharmony_ci 235f9996aaSopenharmony_ci 245f9996aaSopenharmony_ciclass OHOSException(Exception): 255f9996aaSopenharmony_ci 265f9996aaSopenharmony_ci def __init__(self, message: str, code: int = 0): 275f9996aaSopenharmony_ci super().__init__(message) 285f9996aaSopenharmony_ci self._code = code 295f9996aaSopenharmony_ci 305f9996aaSopenharmony_ci def get_solution(self) -> str: 315f9996aaSopenharmony_ci with open(STATUS_FILE, "r") as data: 325f9996aaSopenharmony_ci status_file = json.load(data) 335f9996aaSopenharmony_ci if not self._code in status_file.keys(): 345f9996aaSopenharmony_ci return 'UNKNOWN REASON' 355f9996aaSopenharmony_ci return status_file[str(self._code)]['solution'] 365f9996aaSopenharmony_ci 375f9996aaSopenharmony_ci def get_type(self) -> str: 385f9996aaSopenharmony_ci with open(STATUS_FILE, "r") as data: 395f9996aaSopenharmony_ci status_file = json.load(data) 405f9996aaSopenharmony_ci if not self._code in status_file.keys() or 'type' not in status_file[str(self._code)].keys(): 415f9996aaSopenharmony_ci return 'UNKNOWN ERROR TYPE' 425f9996aaSopenharmony_ci return status_file[str(self._code)]['type'] 435f9996aaSopenharmony_ci 445f9996aaSopenharmony_ci def get_desc(self) -> str: 455f9996aaSopenharmony_ci with open(STATUS_FILE, "r") as data: 465f9996aaSopenharmony_ci status_file = json.load(data) 475f9996aaSopenharmony_ci if not self._code in status_file.keys() or 'description' not in status_file[str(self._code)].keys(): 485f9996aaSopenharmony_ci return 'NO DESCRIPTION' 495f9996aaSopenharmony_ci return status_file[str(self._code)]['description'] 50