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