Ejemplo n.º 1
0
def check_vTypeAttribs(sncfFileName):
	'''
Function that checks the number of meta-data present in the vType attributes. Returns True if the number of meta-data
is equal to 18 or returns False otherwise.
	'''
	tValue=True
	for itr in range(0,len(getattribs.getvTypeAttribs(sncfFileName))):
		if len(getattribs.getvTypeAttribs(sncfFileName)[itr])==18:
			oValue=True
			tValue=oValue and tValue
		else:
			oValue=False
			tValue=oValue and tValue
	return tValue
Ejemplo n.º 2
0
def writeRoute(sncfFileName,outputFileName):
	'''
Function that writes the *.rou.xml file from an existing sncf file sncfFileName.
	'''
	
	if dependencychecker.depChecker(sncfFileName)==True:
		# Initial setup
		# Routes start and end
		routesStart='''<?xml version="1.0" encoding="UTF-8"?>
<routes>'''
		routesEnd='</routes>'
		# vType start and end
		vTypeID='<vType id=\"'
		vTypeAccel='\" accel=\"'
		vTypeDecel='\" decel=\"'
		vTypeSigma='\" sigma=\"'
		vTypeTau='\" tau=\"'
		vTypeLength='\" length=\"'
		vTypeminGap='\" minGap=\"'
		vTypemaxSpeed='\" maxSpeed=\"'
		vTypespeedFactor='\" speedFactor=\"'
		vTypespeedDev='\" speedDev=\"'
		vTypecolor='\" color=\"'
		vTypevClass='\" vClass=\"'
		vTypeemissionClass='\" emissionClass=\"'
		vTypeguiShape='\" guiShape=\"'
		vTypewidth='\" width=\"'
		vTypeimgFile='\" imgFile=\"'
		vTypeimpatience='\" impatience=\"'
		vTypelaneChangeModel='\" laneChangeModel=\"'
		vTypeEnd='\" />'
		# route start and end
		routeID='<route id=\"'
		routeColor='\" color=\"'
		routeEdges='\" edges=\"'
		routeEnd='\" />'
		# vehicle start and end
		vehicleID='< vehicle id=\"'
		vehicleType='\" type=\"'
		vehicleRoute='\" route=\"'
		vehicleColor='\" color=\"'
		vehicleDepart='\" depart=\"'
		vehicledepartLane='\" departLane=\"'
		vehicledepartPos='\" departPos=\"'
		vehicledepartSpeed='\" departSpeed=\"'
		vehiclearrivalLane='\" arrivalLane=\"'
		vehiclearrivalPos='\" arrivalPos=\"'
		vehiclearrivalSpeed='\" arrivalSpeed=\"'
		vehicleline='\" line=\"'
		vehicleEnd='\" />'
		lenVtype=len(getattribs.getvTypeAttribs(sncfFileName))
		lenRoute=len(getattribs.getrouteEntryAttribs(sncfFileName))
		lenVehicle=len(getattribs.getvehicleAttribs(sncfFileName))
		# Begin writing the file
		try:
			fileHandler=open(outputFileName,'w')
			fileHandler.write(routesStart+sncfheaders.printNew())
			# Returns the list containing vType values.
			vType=getattribs.getvTypeDefaults(sncfFileName)
			for itr in range(0,lenVtype):
				vTypeWrite=vTypeID+vType[itr][0]+vTypeAccel+vType[itr][1]+vTypeDecel+vType[itr][2]+vTypeSigma+vType[itr][3]+vTypeTau+vType[itr][4]+vTypeLength+vType[itr][5]+vTypeminGap+vType[itr][6]+vTypemaxSpeed+vType[itr][7]+vTypespeedFactor+vType[itr][8]+vTypespeedDev+vType[itr][9]+vTypecolor+getattribs.getvTypeColor(sncfFileName)[itr]+vTypevClass+vType[itr][11]+vTypeemissionClass+vType[itr][12]+vTypeguiShape+vType[itr][13]+vTypewidth+vType[itr][14]+vTypeimgFile+vType[itr][15]+vTypeimpatience+vType[itr][16]+vTypelaneChangeModel+vType[itr][17]+vTypeEnd+sncfheaders.printNew()
				fileHandler.write(vTypeWrite)
				# Returns the list containing route entry values.
			routeEntry=getattribs.getrouteEntryAttribs(sncfFileName)
			for itr in range(0,lenRoute):
				routeWrite=routeID+routeEntry[itr][0]+routeColor+getattribs.getrouteColor(sncfFileName)[itr]+routeEdges+strutils.whatsInBetween('[',']',getattribs.getroute_edgeName(sncfFileName)[itr])+routeEnd+sncfheaders.printNew()
				fileHandler.write(routeWrite)
				# Returns the list containing vehicle values.
			vehicle=getattribs.getvehicleAttribs(sncfFileName)
			for itr in range(0,lenVehicle):
				vehicleWrite=vehicleID+vehicle[itr][0]+vehicleType+vehicle[itr][1]+vehicleRoute+vehicle[itr][2]+vehicleColor+getattribs.getvehicleColor(sncfFileName)[itr]+vehicleDepart+vehicle[itr][4]+vehicledepartLane+vehicle[itr][5]+vehicledepartPos+vehicle[itr][6]+vehicledepartSpeed+vehicle[itr][7]+vehiclearrivalLane+vehicle[itr][8]+vehiclearrivalPos+vehicle[itr][9]+vehiclearrivalSpeed+vehicle[itr][10]+vehicleline+vehicle[itr][11]+vehicleEnd+sncfheaders.printNew()
				fileHandler.write(vehicleWrite)
			fileHandler.write(routesEnd+sncfheaders.printNew())
			fileHandler.close()
			print'''
[writeRoute says]:The route file %s has been written to the location %s.
			'''%(outputFileName,os.getcwd())
		except IOError,WindowsError:
			print'''
[writeRoute says]:Error! Could not open the file %s for writing. Check the administrative rights or check if the location exists.
			'''%(outputFileName)