-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathvalidate-json.xsh
78 lines (63 loc) · 1.78 KB
/
validate-json.xsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env xonsh
# Copyright (c) 2025 Toradex
# SPDX-License-Identifier: MIT
##
# This script is used to configure a Torizon device to be ready for development.
# WARNING:
# This script is not meant to be run manually. It's make part of the internal
# validation process from CI/CD.
##
# use the xonsh environment to update the OS environment
$UPDATE_OS_ENVIRON = True
# Get the full log of error
$XONSH_SHOW_TRACEBACK = True
# always return if a cmd fails
$RAISE_SUBPROC_ERROR = True
import os
import sys
import tty
import json
$SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
# 1. go to the apollox directory
# 2. check recursively for all the .json files
# 3. check if the files are valid json
# 1.
cd $SCRIPT_PATH/..
# 2.
_files = !(find . -name "*.json")
_files_list = [os.path.abspath(f) for f in _files.out.split()]
_has_invalid_files = False
_allow_list = [
"vscode-torizon-templates/.vscode/settings.json",
"vscode-torizon-templates/scripts/.vscode/tasks.json",
"vscode-torizon-templates/scripts/.vscode/launch.json"
]
for _file in _files_list:
# 3.
try:
_can_skip = False
for _allow in _allow_list:
if _allow in _file:
_can_skip = True
break
if _can_skip:
continue
with open(_file, "r") as f:
json.load(f)
except json.JSONDecodeError as e:
_has_invalid_files = True
print(f"❌ :: {_file}:{e.lineno} :: ❌")
print(f"\t {e}")
print("")
continue
except Exception as e:
_has_invalid_files = True
print(f"❌ :: {_file} :: ❌")
print(f"\t {e}")
print("")
continue
if _has_invalid_files:
sys.exit(1)
else:
print("✅ :: All files are valid JSON :: ✅")
sys.exit(0)