Exemplo n.º 1
0
    def generate(self) -> XMLLuigi:
        exp_def = XMLLuigi(input_fpath=self.template_input_file)
        wr_config = XMLWriterConfig([])

        if exp_def.has_tag('./params'):
            self.logger.debug("Using shared XML parameter file")
            wr_config.add({
                'src_parent': '.',
                'src_tag': 'params',
                'opath_leaf': config.kROS['param_file_ext'],
                'create_tags': None,
                'dest_parent': None,
                'rename_to': None
            })

        else:
            self.ros_param_server = True

        exp_def.write_config_set(wr_config)

        # Add <master> tag
        if not exp_def.has_tag("./master"):
            exp_def.tag_add(".", "master", {})
        if not exp_def.has_tag("./master/group/[@ns='sierra']"):
            exp_def.tag_add("./master", "group", {'ns': 'sierra'})
        # Add <robot> tag
        if not exp_def.has_tag("./robot"):
            exp_def.tag_add(".", "robot", {})
        if not exp_def.has_tag("./robot/group/[@ns='sierra']"):
            exp_def.tag_add("./robot", "group", {'ns': 'sierra'})

        # Generate core experiment definitions
        self._generate_experiment(exp_def)

        return exp_def
Exemplo n.º 2
0
    def _scaffold_expi(self,
                       expi_def: xml.XMLLuigi,
                       modsi: tp.Union[xml.XMLAttrChangeSet, xml.XMLTagAddList],
                       i: int,
                       cmdopts: types.Cmdopts) -> None:
        exp_dirname = self.gen_exp_dirnames(cmdopts)[i]
        self.logger.debug("Applying %s XML modifications from '%s' for exp%s in %s",
                          len(modsi),
                          self.cli_arg,
                          i,
                          exp_dirname)

        exp_input_root = os.path.join(self.batch_input_root,
                                      str(exp_dirname))

        utils.dir_create_checked(exp_input_root,
                                 exist_ok=cmdopts['exp_overwrite'])

        for mod in modsi:
            if isinstance(mod, xml.XMLAttrChange):
                expi_def.attr_change(mod.path, mod.attr, mod.value)
            elif isinstance(mod, xml.XMLTagAdd):
                expi_def.tag_add(mod.path, mod.tag, mod.attr, mod.allow_dup)
            else:
                assert False,\
                    "Batch criteria can only modify or remove XML tags"

        # This will be the "template" input file used to generate the input
        # files for each experimental run in the experiment
        wr_config = xml.XMLWriterConfig([{'src_parent': None,
                                          'src_tag': '.',
                                          'opath_leaf': None,
                                          'create_tags': None,
                                          'dest_parent': None
                                          }])
        expi_def.write_config_set(wr_config)
        opath = utils.batch_template_path(cmdopts,
                                          self.batch_input_root,
                                          exp_dirname)
        expi_def.write(opath)