Beispiel #1
0
    def evaluate(self, context: LaunchContext) -> Path:
        """Evaluate and return a parameter file path."""
        if self.__evaluated_param_file is not None:
            return self.__evaluated_param_file

        param_file = self.__param_file
        if isinstance(param_file, list):
            # list of substitutions
            param_file = perform_substitutions(context, self.__param_file)

        allow_substs = perform_typed_substitution(context,
                                                  self.__allow_substs,
                                                  data_type=bool)
        param_file_path: Path = Path(param_file)
        if allow_substs:
            with open(param_file_path,
                      'r') as f, NamedTemporaryFile(mode='w',
                                                    prefix='launch_params_',
                                                    delete=False) as h:
                parsed = perform_substitutions(context,
                                               parse_substitution(f.read()))
                try:
                    yaml.safe_load(parsed)
                except Exception:
                    raise SubstitutionFailure(
                        'The substituted parameter file is not a valid yaml file'
                    )
                h.write(parsed)
                param_file_path = Path(h.name)
                self.__created_tmp_file = True
        self.__evaluated_param_file = param_file_path
        return param_file_path
Beispiel #2
0
 def execute(self, context: LaunchContext):
     """Execute the action."""
     pushed_namespace = perform_substitutions(context, self.namespace)
     previous_namespace = context.launch_configurations.get(
         'ros_namespace', None)
     namespace = make_namespace_absolute(
         prefix_namespace(previous_namespace, pushed_namespace))
     try:
         validate_namespace(namespace)
     except Exception:
         raise SubstitutionFailure(
             'The resulting namespace is invalid:'
             " [previous_namespace='{}', pushed_namespace='{}']".format(
                 previous_namespace, pushed_namespace))
     context.launch_configurations['ros_namespace'] = namespace
 def execute(self, context: LaunchContext):
     """Execute the action."""
     pushed_namespace = perform_substitutions(context, self.namespace)
     previous_namespace = context.launch_configurations.get(
         'ros_namespace', '')
     namespace = pushed_namespace
     if not pushed_namespace.startswith('/'):
         namespace = previous_namespace + '/' + pushed_namespace
     namespace = namespace.rstrip('/')
     if namespace != '':
         try:
             validate_namespace(namespace)
         except Exception:
             raise SubstitutionFailure(
                 'The resulting namespace is invalid:'
                 " [previous_namespace='{}', pushed_namespace='{}']".format(
                     previous_namespace, pushed_namespace))
     context.launch_configurations['ros_namespace'] = namespace