/usr/share/sumo/tools/traci/rebuildConstants.py is in sumo-tools 0.15.0~dfsg-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@file rebuildConstants.py
@author Daniel Krajzewicz
@author Michael Behrisch
@date 2009-07-24
@version $Id: rebuildConstants.py 11671 2012-01-07 20:14:30Z behrisch $
This script extracts definitions from <SUMO>/src/traci-server/TraCIConstants.h
and builds an according constants definition python file "constants.py".
SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
Copyright (C) 2009-2012 DLR (http://www.dlr.de/) and contributors
All rights reserved
"""
import os, sys, datetime
from optparse import OptionParser
dirname = os.path.dirname(__file__)
optParser = OptionParser()
optParser.add_option("-j", "--java", action="store_true",
default=False, help="generate Java output")
optParser.add_option("-o", "--output", default=os.path.join(dirname, "constants.py"),
help="File to save constants into", metavar="FILE")
(options, args) = optParser.parse_args()
fdo = open(options.output, "w")
if options.java:
print >> fdo, "/**"
else:
print >> fdo, '"""'
print >> fdo, """@file %s
This script contains TraCI constant definitions from <SUMO_HOME>/src/traci-server/TraCIConstants.h
generated by "%s" on %s.
SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
Copyright (C) 2009-2012 DLR (http://www.dlr.de/) and contributors
All rights reserved""" % (os.path.basename(options.output), os.path.basename(sys.argv[0]), datetime.datetime.now())
if options.java:
print >> fdo, "*/\n"
else:
print >> fdo, '"""\n'
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
if options.java:
fdo.write("}")
continue
if line.find("#define ")>=0:
vals = line.split(" ")
if options.java:
line = " public static final int " + vals[1] + " = " + vals[2].strip() + ";\n"
else:
line = vals[1] + " = " + vals[2]
if options.java:
line = line.replace("//", " //")
else:
line = line.replace("//", "#")
fdo.write(line)
if line.find("#define TRACICONSTANTS_H")>=0:
started = True
if options.java:
fdo.write("public class TraCIConstants {")
fdi.close()
fdo.close()
|