#!/usr/bin/env python1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2# Copyright (C) 2009-2025 German Aerospace Center (DLR) and others.3# This program and the accompanying materials are made available under the4# terms of the Eclipse Public License 2.0 which is available at5# https://www.eclipse.org/legal/epl-2.0/6# This Source Code may also be made available under the following Secondary7# Licenses when the conditions for such availability set forth in the Eclipse8# Public License 2.0 are satisfied: GNU General Public License, version 29# or later which is available at10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1213# @file xmlconnections_mapEdges.py14# @author Daniel Krajzewicz15# @author Michael Behrisch16# @date 2009-08-011718"""19Reads edge id replacements from "edgemap.txt"; the format of this file is20<OLD_EDGE_ID>-><NEW_EDGE_ID>21Reads the given connections file <CONNECTIONS> and replaces old edge names by new.22The result is written to <CONNECTIONS>.mod.xml2324Call: xmlconnections_mapEdges.py <CONNECTIONS>25"""26from __future__ import absolute_import27from __future__ import print_function2829import sys3031if len(sys.argv) < 2:32print("Usage: " + sys.argv[0] + " <CONNECTIONS>")33sys.exit()3435# read map36mmap = {}37fdi = open("edgemap.txt")38for line in fdi:39if line.find("->") < 0:40continue41(orig, dest) = line.strip().split("->")42dest = dest.split(",")43mmap[orig] = dest44fdi.close()4546fdi = open(sys.argv[1])47fdo = open(sys.argv[1] + ".mod.xml", "w")48for line in fdi:49for orig in mmap:50line = line.replace(51'from="' + orig + '"', 'from="' + mmap[orig][-1] + '"')52line = line.replace('to="' + orig + '"', 'to="' + mmap[orig][0] + '"')53fdo.write(line)54fdi.close()55fdo.close()565758