Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/ut/src/asys/common/path.py: 70%

40 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-08-21 15:37 +0800

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3# ---------------------------------------------------------------------------- 

4# Copyright (c) 2025 Huawei Technologies Co., Ltd. 

5# 

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 

20import re 

21import sys 

22 

23from common import log_error 

24 

25 

26__all__ = ["get_project_conf", "get_ascend_home", "get_log_conf_path"] 

27 

28 

29def get_project_conf(): 

30 project_conf_path = os.path.join(os.path.dirname(sys.argv[0]), "conf") 

31 project_path = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) 

32 if not os.path.exists(project_conf_path): 

33 project_conf_path = os.path.join(project_path, "conf") 

34 if not os.path.exists(project_conf_path): 

35 project_conf_path = os.path.join(project_path, "asys/conf") 

36 return project_conf_path 

37 

38 

39def get_ascend_home(): 

40 # TOOLCHAIN_HOME -> ${install_path}/latest/toolkit 

41 toolchain_home = os.getenv('TOOLCHAIN_HOME') 

42 if toolchain_home: 

43 latest_path = toolchain_home.split(":")[0] 

44 return os.path.abspath(os.path.join(latest_path, "../..")) 

45 else: 

46 return os.path.abspath('/usr/local/Ascend') 

47 

48 

49def get_log_conf_path(name): 

50 log_path = None 

51 if name == "slog": 

52 log_conf_paths = ["/etc/slog.conf", "/var/log/npu/conf/slog.conf", "/var/log/npu/conf/slog/slog.conf"] 

53 search_re = "logAgentFileDir=(.+?)\n" 

54 log_path = "/var/log/npu/slog/" 

55 elif name == "bbox": 

56 log_conf_paths = ["/var/bbox.conf", "/etc/bbox.conf", "/var/log/npu/conf/bbox.conf", 

57 "/var/log/npu/conf/bbox/bbox.conf"] 

58 search_re = "MNTN_PATH=(.+?)\n" 

59 log_path = "/var/log/npu/hisi_logs/" 

60 else: 

61 log_error("The input parameter is incorrect.") 

62 return log_path 

63 

64 for conf_path in log_conf_paths: 

65 if not os.path.exists(conf_path): 

66 continue 

67 with open(conf_path, "r", encoding="utf8") as conf_f: 

68 conf_info = conf_f.read() 

69 

70 log_path_f = re.search(search_re, conf_info) 

71 if log_path_f is not None: 

72 log_path = log_path_f.groups()[0] 

73 

74 return log_path