autojson.py: Check the sensor name
We may be careless and write down duplicate sensor names
in the json, which will cause the entity-manager to
generate duplicate dbus paths and coredump.
This change counts the sensor name and outputs a red alert
message if there are duplicates
Signed-off-by: John Wang <wangzhiqiang.bj@bytedance.com>
Change-Id: I3363e744d7e0ddf8cb8894e120368a45af4f8de9
diff --git a/scripts/autojson.py b/scripts/autojson.py
index 1a499df..4a5fc5c 100755
--- a/scripts/autojson.py
+++ b/scripts/autojson.py
@@ -27,5 +27,13 @@
else:
j["Exposes"] = sorted(j["Exposes"], key=lambda k: k["Type"])
+ nl = [s['Name'] for s in j['Exposes']]
+ ns = set(nl)
+ for n in ns:
+ t = nl.count(n)
+ if t != 1:
+ print('\033[1;35mthe %s appears %d times\033[0m!'%(n, t))
+ os._exit(-1)
+
with open(file, 'w') as f:
f.write(json.dumps(j, indent=4, sort_keys=True, separators=(',', ': ')))