Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/agilepy/lib_misc/runner.py
169689 views
1
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
2
# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.
3
# SUMOPy module
4
# Copyright (C) 2012-2021 University of Bologna - DICAM
5
# This program and the accompanying materials are made available under the
6
# terms of the Eclipse Public License 2.0 which is available at
7
# https://www.eclipse.org/legal/epl-2.0/
8
# This Source Code may also be made available under the following Secondary
9
# Licenses when the conditions for such availability set forth in the Eclipse
10
# Public License 2.0 are satisfied: GNU General Public License, version 2
11
# or later which is available at
12
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14
15
# @file runner.py
16
# @author Joerg Schweizer
17
# @date 2012
18
19
20
class Runner:
21
"""Class to manage the execution of processes in a script.
22
The class initialized with the following list of tasks:
23
[
24
('taskname1', True|False),
25
('taskname2', True|False),
26
:
27
:
28
]
29
The first argument is the task name, the second is whether the task should be executed or not.
30
31
"""
32
33
def __init__(self, tasks):
34
self._tasknames = []
35
self._taskinfos = []
36
self._taskindex = -1
37
for taskname, info in tasks:
38
self._tasknames.append(taskname)
39
self._taskinfos.append(info)
40
41
def has_task(self, taskname):
42
"""Returns True if taskname must be executed"""
43
if self._tasknames.count(taskname) > 0:
44
ind = self._tasknames.index(taskname)
45
46
# check if info foresees this task
47
if self._taskinfos[ind]: # could be modified in the future
48
self._taskindex = ind
49
return True
50
51
else:
52
return False
53
54
else:
55
return False
56
57
def get_index_current(self):
58
"""
59
Returns index of currently executed task
60
"""
61
return self._taskindex
62
63
def format_task_current(self):
64
# print 'format_task_current',self._taskindex,self._tasknames
65
return "%03d_%s" % (self._taskindex, self._tasknames[self._taskindex])
66
67