1#!/usr/bin/env python
2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3# Copyright (C) 2008-2019 German Aerospace Center (DLR) and others.
4# This program and the accompanying materials
5# are made available under the terms of the Eclipse Public License v2.0
6# which accompanies this distribution, and is available at
7# http://www.eclipse.org/legal/epl-v20.html
8# SPDX-License-Identifier: EPL-2.0
9
10# @file    runner.py
11# @author  Daniel Krajzewicz
12# @author  Michael Behrisch
13# @date    2007-10-25
14# @version $Id$
15
16from __future__ import absolute_import
17from __future__ import print_function
18
19
20import os
21import subprocess
22import sys
23import shutil
24try:
25    sys.path.append(os.path.join(os.path.dirname(
26        __file__), '..', '..', '..', '..', "tools"))  # tutorial in tests
27    sys.path.append(os.path.join(os.environ.get("SUMO_HOME", os.path.join(
28        os.path.dirname(__file__), "..", "..", "..")), "tools"))  # tutorial in docs
29    from sumolib import checkBinary  # noqa
30except ImportError:
31    sys.exit("please declare environment variable 'SUMO_HOME'")
32
33netconvertBinary = checkBinary('netconvert')
34sumoBinary = checkBinary('sumo')
35# build/check network
36retcode = subprocess.call(
37    [netconvertBinary, "-c", "data/hello.netccfg"], stdout=sys.stdout, stderr=sys.stderr)
38try:
39    shutil.copy("data/hello.net.xml", "net.net.xml")
40except IOError:
41    print("Missing 'hello.net.xml'")
42print(">> Netbuilding closed with status %s" % retcode)
43sys.stdout.flush()
44# run simulation
45retcode = subprocess.call(
46    [sumoBinary, "-c", "data/hello.sumocfg", "--no-step-log"], stdout=sys.stdout, stderr=sys.stderr)
47print(">> Simulation closed with status %s" % retcode)
48sys.stdout.flush()
49