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 25 26def xml_node_find_by_name(node, name): 27 for item in node: 28 if item.tag == name: 29 return item.text 30 return None 31 32 33class SAParser(object): 34 @staticmethod 35 def load(mgr, out_root_path): 36 all_sa = {} 37 path = os.path.join(out_root_path, "packages/phone/system/profile") 38 if not os.path.exists(path): 39 return 40 41 for f in os.listdir(path): 42 full_name = os.path.join(path, f) 43 if os.path.isfile(full_name) and f.endswith(".json"): 44 try: 45 SAParser.__parse_sa_profile(all_sa, full_name) 46 except: 47 pass 48 49 SAParser.__add_sa_info(all_sa, mgr) 50 51 @staticmethod 52 def __parse_sa_profile(all_sa, full_name): 53 with open(full_name, "r") as f: 54 profile = json.load(f) 55 process = profile["process"] 56 for sa in profile["systemability"]: 57 libpath = sa["libpath"] 58 sa_key = os.path.basename(libpath) 59 sa["process"] = process 60 all_sa[sa_key] = sa 61 62 @staticmethod 63 def __add_sa_info(all_sa, mgr): 64 if not mgr: 65 return 66 for mod in mgr.get_all(): 67 mod["sa_id"] = 0 68 if mod["name"] not in all_sa: 69 continue 70 mod["sa_id"] = int(all_sa[mod["name"]]["name"]) 71 72 73if __name__ == '__main__': 74 parser = SAParser() 75 parser.load(None, "/home/handy/qemu/out/rk3568") 76