macros: Add loop class for loop functionality
To keep the macro style of the program flow and explicitely state the command sequence with Macro.add, we need a mechanism that repeats several steps of the Macro depending on a given condition. This will be used by the repo checkout logic. Signed-off-by: Andreas Reichel <andreas.reichel.ext@siemens.com>
This commit is contained in:
parent
c7cc57c42f
commit
fc9ebf1104
@ -74,6 +74,38 @@ class Command:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Loop(Command):
|
||||||
|
"""
|
||||||
|
A class that defines a set of commands as a loop.
|
||||||
|
"""
|
||||||
|
def __init__(self, name):
|
||||||
|
self.commands = []
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def add(self, command):
|
||||||
|
"""
|
||||||
|
Appends commands to the loop.
|
||||||
|
"""
|
||||||
|
self.commands.append(command)
|
||||||
|
|
||||||
|
def execute(self, ctx):
|
||||||
|
"""
|
||||||
|
Executes the loop.
|
||||||
|
"""
|
||||||
|
loop_name = str(self)
|
||||||
|
|
||||||
|
def executor(command):
|
||||||
|
command_name = str(command)
|
||||||
|
logging.debug('Loop %s: execute %s', loop_name, command_name)
|
||||||
|
return command.execute(ctx)
|
||||||
|
|
||||||
|
while all(executor(c) for c in self.commands):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SetupHome(Command):
|
class SetupHome(Command):
|
||||||
"""
|
"""
|
||||||
Setups the home directory of kas.
|
Setups the home directory of kas.
|
||||||
|
Loading…
Reference in New Issue
Block a user