linuxOS_D21X/tools/scripts/image_cfg_parser.py

37 lines
1006 B
Python
Raw Normal View History

2024-11-29 08:13:19 +00:00
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
2024-11-29 08:33:21 +00:00
# SPDX-License-Identifier: Apache-2.0
2024-11-29 08:13:19 +00:00
#
2024-11-29 08:33:21 +00:00
# Copyright (C) 2021-2024 ArtInChip Technology Co., Ltd
2024-11-29 08:13:19 +00:00
# Dehuang Wu <dehuang.wu@artinchip.com>
import os
import sys
import json
import argparse
from collections import OrderedDict
2024-11-29 08:33:21 +00:00
2024-11-29 08:13:19 +00:00
def parse_image_cfg(cfgfile):
""" Load image configuration file
Args:
cfgfile: Configuration file name
"""
2024-11-29 08:33:21 +00:00
2024-11-29 08:13:19 +00:00
with open(cfgfile, "r") as f:
lines = f.readlines()
jsonstr = ""
for line in lines:
sline = line.strip()
if sline.startswith("//"):
continue
2024-11-29 08:33:21 +00:00
slash_start = sline.find("//")
if slash_start > 0:
jsonstr += sline[0:slash_start].strip()
else:
jsonstr += sline
2024-11-29 08:13:19 +00:00
# Use OrderedDict is important, we need to iterate FWC in order.
2024-11-29 08:33:21 +00:00
jsonstr = jsonstr.replace(",}", "}").replace(",]", "]")
2024-11-29 08:13:19 +00:00
cfg = json.loads(jsonstr, object_pairs_hook=OrderedDict)
return cfg