#!/usr/bin/env python
"""
@file    rebuildConstants.py
@author  Daniel.Krajzewicz@dlr.de
@date    2009-07-24
@version $Id: rebuildConstants.py 7553 2009-07-28 12:11:39Z behrisch $

This script extracts definitions from <SUMO>/src/traci-server/TraCIConstants.h
 and builds an according constants definition python file "traciconstants.py".

Copyright (C) 2009 DLR/TS, Germany
All rights reserved
"""
import os, sys, datetime

dirname = os.path.dirname(sys.argv[0])
fdo = open(os.path.join(dirname, "traciconstants.py"), "w")
print >> fdo, """\"\"\"
@file    traciconstants.py

This script contains TraCI constant definitions from <SUMO>/src/traci-server/TraCIConstants.h
generated by "%s" on %s.

Copyright (C) 2009 DLR/TS, Germany
All rights reserved
\"\"\"
""" % (os.path.basename(sys.argv[0]), datetime.datetime.now())

fdi = open(os.path.join(dirname, "..", "..", "src", "traci-server", "TraCIConstants.h"))
started = False
for line in fdi:
	if started:
		if line.find("#endif")>=0:
			started = False
			continue
		if line.find("#define ")>=0:
			vals = line.split(" ")
			line = vals[1] + " = " + vals[2]
		line = line.replace("//", "#")
		fdo.write(line)
	if line.find("#define TRACICONSTANTS_H")>=0:
		started = True
fdi.close()
fdo.close()
