1+ # Copyright 2018 Open Source Robotics Foundation, Inc.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
115"""Module for the ExecuteLocal action."""
216
317import asyncio
418import io
519import os
620import platform
7- import shlex
821import signal
922import threading
1023import traceback
1124from typing import Any # noqa: F401
1225from typing import Callable
1326from typing import cast
1427from typing import Dict
15- from typing import Iterable
1628from typing import List
1729from typing import Optional
1830from typing import Text
4759from ..events .process import ProcessStdout
4860from ..events .process import ShutdownProcess
4961from ..events .process import SignalProcess
50- from ..frontend import Entity
51- from ..frontend import expose_action
52- from ..frontend import Parser
5362from ..launch_context import LaunchContext
5463from ..launch_description import LaunchDescription
5564from ..launch_description_entity import LaunchDescriptionEntity
5867from ..substitution import Substitution # noqa: F401
5968from ..substitutions import LaunchConfiguration
6069from ..substitutions import PythonExpression
61- from ..substitutions import TextSubstitution
6270from ..utilities import create_future
6371from ..utilities import is_a_subclass
6472from ..utilities import normalize_to_list_of_substitutions
6977
7078
7179class ExecuteLocal (Action ):
72- """Action that begins executing a process on the local system and sets up event handlers for the process ."""
80+ """Action that begins executing a process on the local system and sets up event handlers."""
7381
7482 def __init__ (
7583 self ,
@@ -81,7 +89,6 @@ def __init__(
8189 sigkill_timeout : SomeSubstitutionsType = LaunchConfiguration (
8290 'sigkill_timeout' , default = 5 ),
8391 emulate_tty : bool = False ,
84- prefix : Optional [SomeSubstitutionsType ] = None ,
8592 output : Text = 'log' ,
8693 output_format : Text = '[{this.name}] {line}' ,
8794 log_cmd : bool = False ,
@@ -157,9 +164,6 @@ def __init__(
157164 :py:func:`evaluate_condition_expression`.
158165 Throws :py:exception:`InvalidConditionExpressionError` if the
159166 'emulate_tty' configuration does not represent a boolean.
160- :param: prefix a set of commands/arguments to preceed the cmd, used for
161- things like gdb/valgrind and defaults to the LaunchConfiguration
162- called 'launch-prefix'
163167 :param: output configuration for process output logging. Defaults to 'log'
164168 i.e. log both stdout and stderr to launch main log file and stderr to
165169 the screen.
@@ -183,9 +187,6 @@ def __init__(
183187 self .__sigterm_timeout = normalize_to_list_of_substitutions (sigterm_timeout )
184188 self .__sigkill_timeout = normalize_to_list_of_substitutions (sigkill_timeout )
185189 self .__emulate_tty = emulate_tty
186- self .__prefix = normalize_to_list_of_substitutions (
187- LaunchConfiguration ('launch-prefix' , default = '' ) if prefix is None else prefix
188- )
189190 self .__output = os .environ .get ('OVERRIDE_LAUNCH_PROCESS_OUTPUT' , output )
190191 self .__output_format = output_format
191192
@@ -216,11 +217,6 @@ def shell(self):
216217 """Getter for shell."""
217218 return self .__shell
218219
219- @property
220- def prefix (self ):
221- """Getter for prefix."""
222- return self .__prefix
223-
224220 @property
225221 def output (self ):
226222 """Getter for output."""
@@ -412,9 +408,10 @@ def __flush_buffers(self, event, context):
412408 self .__stderr_buffer .truncate (0 )
413409
414410 def __on_shutdown (self , event : Event , context : LaunchContext ) -> Optional [SomeActionsType ]:
411+ due_to_sigint = cast (Shutdown , event ).due_to_sigint
415412 return self ._shutdown_process (
416413 context ,
417- send_sigint = ( not cast ( Shutdown , event ). due_to_sigint ) ,
414+ send_sigint = not due_to_sigint or context . noninteractive ,
418415 )
419416
420417 def __get_shutdown_timer_actions (self ) -> List [Action ]:
@@ -591,10 +588,9 @@ async def __execute_process(self, context: LaunchContext) -> None:
591588 self .__cleanup ()
592589
593590 def prepare (self , context : LaunchContext ):
594- """
595- Prepares the action for execution.
596- """
591+ """Prepare the action for execution."""
597592 self .__process_description .apply_context (context )
593+ self .__expand_substitutions (context )
598594
599595 def execute (self , context : LaunchContext ) -> Optional [List [LaunchDescriptionEntity ]]:
600596 """
@@ -607,7 +603,7 @@ def execute(self, context: LaunchContext) -> Optional[List[LaunchDescriptionEnti
607603 - configures logging for the IO process event
608604 - create a task for the coroutine that monitors the process
609605 """
610- self .prepare (context )
606+ self .prepare (context )
611607 name = self .__process_description .final_name
612608
613609 if self .__executed :
@@ -653,7 +649,6 @@ def execute(self, context: LaunchContext) -> Optional[List[LaunchDescriptionEnti
653649 try :
654650 self .__completed_future = create_future (context .asyncio_loop )
655651 self .__shutdown_future = create_future (context .asyncio_loop )
656- self .__expand_substitutions (context )
657652 self .__logger = launch .logging .get_logger (name )
658653 self .__stdout_logger , self .__stderr_logger = \
659654 launch .logging .get_output_loggers (name , self .__output )
0 commit comments