summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorVincent Guittot <vincent.guittot@linaro.org>2014-09-10 09:01:38 +0200
committerVincent Guittot <vincent.guittot@linaro.org>2014-09-10 09:41:54 +0200
commit9b4378356d6cc46e4ab6606759bba76cc5fb871d (patch)
tree05d08686b55cd5045fb4ce9fab27528849780097 /doc
parent4da08f9546d11ffaea7670284a04a5602f2206e6 (diff)
check that each event has a unique id
so libjson will not remove the duplicated events
Diffstat (limited to 'doc')
-rwxr-xr-xdoc/check-id.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/doc/check-id.py b/doc/check-id.py
new file mode 100755
index 0000000..91f1982
--- /dev/null
+++ b/doc/check-id.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import getopt
+
+outfile = "unikid.json"
+selfupdate = 0
+verbose = 0
+
+try:
+ opts, args = getopt.getopt(sys.argv[1:], "o:av")
+except getopt.GetoptError as err:
+ print str(err) # will print something like "option -a not recognized"
+ sys.exit(2)
+
+for o, a in opts:
+ if o == "-o":
+ outfile = a
+ if o == "-a":
+ selfupate = 1
+ if o == "-v":
+ verbose = 1
+
+for f in args:
+ if not os.path.exists(f):
+ print "WARN: %s does not exist", f
+
+ try:
+ fp = open(f, "r")
+ except IOError:
+ print "WARN: Unable to open %s", f
+ sys.exit(2)
+
+ if selfupdate:
+ outfile = f
+ try:
+ fo = open(outfile, "w+")
+ except IOError:
+ print "WARN: Unable to open %s", f
+ sys.exit(2)
+
+ lines = fp.readlines()
+ fp.close()
+
+ curid = 1
+ refcount = 0
+ idlist = {}
+ myid = []
+ for myline in lines:
+
+ if "{" in myline:
+ refcount +=1
+ myid.append(curid)
+ curid = 1
+ #print "-->Entering level ", refcount
+ idlist[refcount] = {}
+
+ if "}" in myline:
+ #print "<--Leaving level ", refcount
+ del idlist[refcount]
+ curid = myid.pop()
+ refcount -=1
+
+ try:
+ key_id, value = myline.split(":", 1)
+ except ValueError:
+ #print "Nothing to do"
+ fo.write(myline)
+ continue
+
+ key_id = key_id.strip('\"\t\n\r ')
+
+ value = value.strip(',\"\t\n\r ')
+
+ if key_id in idlist[refcount]:
+ newkey_id = key_id + str(curid)
+ while newkey_id in idlist[refcount]:
+ curid +=1
+ newkey_id = key_id + str(curid)
+
+ if verbose:
+ print "key ", key_id, " changed into ", newkey_id
+
+ myline = myline.replace(key_id, newkey_id, 1)
+ key_id = newkey_id
+
+ #print "Add <", key_id, "> has value <", value, ">"
+ idlist[refcount][key_id] = value
+
+ fo.write(myline)
+
+fp.close()
+fo.close()
+
+
+
+
+
+
+
+