Skip to content

Commit d2935d6

Browse files
Expose shutdown action to xml frontend (#611)
* expose shutdown action to xml frontend Signed-off-by: Aditya <[email protected]>
1 parent f871054 commit d2935d6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

launch/launch/actions/shutdown_action.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
import logging
1818
from typing import Text
1919

20+
from launch.frontend import Entity
21+
from launch.frontend import expose_action
22+
from launch.frontend import Parser
23+
2024
from .emit_event import EmitEvent
2125
from ..events import Shutdown as ShutdownEvent
2226
from ..events.process import ProcessExited
@@ -25,12 +29,22 @@
2529
_logger = logging.getLogger(name='launch')
2630

2731

32+
@expose_action('shutdown')
2833
class Shutdown(EmitEvent):
2934
"""Action that shuts down a launched system by emitting Shutdown when executed."""
3035

3136
def __init__(self, *, reason: Text = 'reason not given', **kwargs):
3237
super().__init__(event=ShutdownEvent(reason=reason), **kwargs)
3338

39+
@classmethod
40+
def parse(cls, entity: Entity, parser: Parser):
41+
"""Return `Shutdown` action and kwargs for constructing it."""
42+
_, kwargs = super().parse(entity, parser)
43+
reason = entity.get_attr('reason', optional=True)
44+
if reason:
45+
kwargs['reason'] = parser.parse_substitution(reason)
46+
return cls, kwargs
47+
3448
def execute(self, context: LaunchContext):
3549
"""Execute the action."""
3650
try:

0 commit comments

Comments
 (0)