From 50fea4febace8ad7504a6a1d31f212148fd3922d Mon Sep 17 00:00:00 2001 From: Vincent Guittot Date: Fri, 19 Sep 2014 09:03:51 -0700 Subject: rename check_id into workgen check unique key in the json file and call rt-app with the output file --- doc/check-id.py | 102 ------------------------------------------------ doc/workgen | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 2 +- 3 files changed, 120 insertions(+), 103 deletions(-) delete mode 100755 doc/check-id.py create mode 100755 doc/workgen diff --git a/doc/check-id.py b/doc/check-id.py deleted file mode 100755 index 91f1982..0000000 --- a/doc/check-id.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/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() - - - - - - - - diff --git a/doc/workgen b/doc/workgen new file mode 100755 index 0000000..7bef6e8 --- /dev/null +++ b/doc/workgen @@ -0,0 +1,119 @@ +#!/usr/bin/env python + +import os +import sys +import getopt +import subprocess +import signal + +def check_unikid_json(infile, outfile, verbose=0): + if not os.path.exists(infile): + print "WARN: %s does not exist", infile + + try: + fi = open(infile, "r") + except IOError: + print "WARN: Unable to open %s", infile + sys.exit(2) + + try: + fo = open(outfile, "w+") + except IOError: + print "WARN: Unable to open %s", f + sys.exit(2) + + lines = fi.readlines() + fi.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) + + fo.close() + + return + +if __name__ == '__main__': + + def handleSigTERM(signum, frame): + sys.exit + + signal.signal(signal.SIGTERM, handleSigTERM) + signal.signal(signal.SIGINT, handleSigTERM) + + 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 + + if selfupdate: + outfile = f + + for f in args: + check_unikid_json(f, outfile) + + subprocess.call(["rt-app", outfile]) + + + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am index 600d468..ca734d2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,4 +4,4 @@ bin_PROGRAMS = rt-app rt_app_SOURCES= rt-app_types.h rt-app_args.h rt-app_utils.h rt-app_utils.c rt-app_args.c rt-app.h rt-app.c rt_app_SOURCES += rt-app_parse_config.h rt-app_parse_config.c rt_app_LDADD = $(QRESLIB) ../libdl/libdl.a $(LIBJSON) - +dist_bin_SCRIPTS = $(srcdir)/../doc/workgen -- cgit v1.2.3