1#!/usr/bin/env python 2#coding=utf-8 3 4# 5# Copyright (c) 2022 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 string 20import json 21import sys 22import os 23import xml.etree.ElementTree as ET 24 25def xml_node_find_by_name(node, name): 26 for item in node: 27 if item.tag == name: 28 return item.text 29 return None 30 31class SAParser(object): 32 @staticmethod 33 def __parse_sa_profile(all_sa, f): 34 root = ET.parse(f).getroot() 35 process = xml_node_find_by_name(root, "process") 36 for sa in root.findall("systemability"): 37 libpath = xml_node_find_by_name(sa, "libpath") 38 sa_key = os.path.basename(libpath) 39 sa_item = {} 40 for item in sa: 41 sa_item[item.tag] = item.text 42 sa_item["process"] = process 43 all_sa[sa_key] = sa_item 44 45 @staticmethod 46 def __add_sa_info(all_sa, mgr): 47 if not mgr: 48 return 49 for mod in mgr.get_all(): 50 mod["sa_id"] = 0 51 if mod["name"] not in all_sa: 52 continue 53 mod["sa_id"] = int(all_sa[mod["name"]]["name"]) 54 55 @staticmethod 56 def load(mgr, out_root_path): 57 all_sa = {} 58 path = os.path.join(out_root_path, "packages/phone/system/profile") 59 if not os.path.exists(path): 60 return 61 62 for f in os.listdir(path): 63 full_name = os.path.join(path, f) 64 if os.path.isfile(full_name) and f.endswith(".xml"): 65 try: 66 SAParser.__parse_sa_profile(all_sa, full_name) 67 except: 68 pass 69 70 SAParser.__add_sa_info(all_sa, mgr) 71