def __call__(cls, *args, **kwargs): inst = super(Register, cls).__call__(*args, **kwargs) # manually set the root task once root_task(inst) # check for interactive parameters for param in inst.interactive_params: value = getattr(inst, param) if value: skip_abort = False try: logger.debug( "evaluating interactive parameter '{}' with value {}". format(param, value)) skip_abort = getattr(inst, "_" + param)(value) # reset the interactive parameter setattr(inst, param, ()) except KeyboardInterrupt: print("\naborted") # abort the process if not explicitly skipped if not skip_abort: abort(exitcode=0) print("") return inst
def _get_env(self): # environment variables to set env = OrderedDict() # default sandboxing variables env["LAW_SANDBOX"] = self.key.replace("$", r"\$") env["LAW_SANDBOX_SWITCHED"] = "1" if self.task: env["LAW_SANDBOX_TASK_ID"] = self.task.live_task_id env["LAW_SANDBOX_ROOT_TASK_ID"] = root_task().task_id env["LAW_SANDBOX_IS_ROOT_TASK"] = str(int( self.task.is_root_task())) if getattr(self.task, "_worker_id", None): env["LAW_SANDBOX_WORKER_ID"] = self.task._worker_id if getattr(self.task, "_worker_first_task_id", None): env["LAW_SANDBOX_WORKER_FIRST_TASK_ID"] = self.task._worker_first_task_id # extend by variables from the config file cfg = Config.instance() section = self.get_config_section(postfix="env") for name, value in cfg.items(section): if is_pattern(name): names = [ key for key in os.environ.keys() if fnmatch(key, name) ] else: names = [name] for name in names: # when there is only a key present, i.e., no value is set, # get it from the current environment env[name] = value if value is not None else os.getenv(name, "") # extend by variables defined on task level if self.task: task_env = self.task.sandbox_env(env) if task_env: env.update(task_env) return env
def is_root_task(self): return root_task() == self