Esempio n. 1
0
    def init_default_vars(self, initial_vars):
        def get_now_date_time(val):
            return str(datetime.datetime.fromtimestamp(time.time()))

        config_vars.set_dynamic_var("__NOW__", get_now_date_time)

        config_vars.update(initial_vars)

        # settings these configVar requires setting global values in files.py as soon as possible
        config_vars["ACTING_UID"].set_callback_when_value_is_set(
            utils.set_active_user_or_group_config_var_callback),
        config_vars["ACTING_GID"].set_callback_when_value_is_set(
            utils.set_active_user_or_group_config_var_callback),

        # read defaults/main.yaml
        self.read_defaults_file("main", ignore_if_not_exist=False)

        # read defaults/compile-info.yaml
        self.read_defaults_file("compile-info")
        if "__COMPILATION_TIME__" not in config_vars:
            if bool(config_vars["__INSTL_COMPILED__"]):
                config_vars[
                    "__COMPILATION_TIME__"] = "unknown compilation time"
            else:
                config_vars["__COMPILATION_TIME__"] = "(not compiled)"

        self.read_user_config()
Esempio n. 2
0
 def get_version_str(self, short=False):
     instl_ver_str = ".".join(list(config_vars["__INSTL_VERSION__"]))
     if not short:
         if "__PLATFORM_NODE__" not in config_vars:
             config_vars.update({"__PLATFORM_NODE__": platform.node()})
         instl_ver_str = config_vars.resolve_str(
             "$(INSTL_EXEC_DISPLAY_NAME) version " + instl_ver_str +
             " $(__COMPILATION_TIME__) $(__PLATFORM_NODE__)")
     return instl_ver_str
Esempio n. 3
0
    def __call__(self, *args, **kwargs) -> None:
        pybatch.PythonBatchCommandBase.__call__(self, *args, **kwargs)
        with config_vars.push_scope_context() as scope_context:
            if self.temp_config_vars:
                config_vars.update(self.temp_config_vars)
            if self.config_files is not None:
                reader = ConfigVarYamlReader(config_vars)
                for config_file in self.config_files:
                    reader.read_yaml_file(config_file)
            with utils.utf8_open_for_read(self.unresolved_file, "r") as rfd:
                text_to_resolve = rfd.read()
            resolved_text = config_vars.resolve_str(text_to_resolve)

            if self.raise_if_unresolved:
                unresolved_re = re.compile(r"""\$\(.*?\)""")
                all_unresolved = unresolved_re.findall(resolved_text)
                if all_unresolved:
                    unresolved_references = ", ".join(list(
                        set(all_unresolved)))
                    raise ValueError(
                        f"unresolved config_vars in {self.unresolved_file}: {unresolved_references}"
                    )
            with utils.utf8_open_for_write(self.resolved_file, "w") as wfd:
                wfd.write(resolved_text)