blob: 68ad10b3c494a3e2b965e9e5d8fa07c9f75ea508 [file] [log] [blame]
Balint Dobszay9e2573d2022-08-10 15:15:21 +02001#!/usr/bin/env python3
2# SPDX-License-Identifier: BSD-3-Clause
3#
4# Copyright (c) 2022, Arm Limited. All rights reserved.
5
6"""
7Merge two json files, the second is merged into the first. If the first file
8doesn't exists yet, it will be created, along with its parent directories.
9"""
10
11import json
12import os.path
13import sys
14
15if os.path.isfile(sys.argv[1]):
16 with open(sys.argv[1], "rt", encoding="ascii") as f:
17 combined = json.load(f)
18else:
19 os.makedirs(os.path.dirname(sys.argv[1]), exist_ok=True)
20 combined = {}
21
22with open(sys.argv[2], "rt", encoding="ascii") as f:
23 current = json.load(f)
24 combined = {**combined, **current}
25
26with open(sys.argv[1], "wt", encoding="ascii") as f:
27 json.dump(combined, f, indent=4)