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