def gen(self, name): ''' Atomically get/gen an EventBus and incref. (requires ctor during BusRef init) Args: name (str): The name/iden of the EventBus instance. ''' if self.ctor is None: raise s_common.NoSuchCtor(name=name, mesg='BusRef.gen() requires ctor') with self.lock: ebus = self.ebus_by_name.get(name) if ebus is None: ebus = self.ctor(name) if ebus is not None: def fini(): self.ebus_by_name.pop(name, None) ebus.onfini(fini) self.ebus_by_name[name] = ebus else: ebus.incref() return ebus
def getCellCtor(dirn, conf=None): ''' Find the ctor option for a cell and resolve the function. ''' ctor = None if conf is not None: ctor = conf.get('ctor') path = s_common.genpath(dirn, 'config.json') if ctor is None and os.path.isfile(path): subconf = s_common.jsload(path) ctor = subconf.get('ctor') if ctor is None: raise s_common.ReqConfOpt(mesg='Missing ctor, cannot divide', name='ctor') func = s_dyndeps.getDynLocal(ctor) if func is None: raise s_common.NoSuchCtor(mesg='Cannot resolve ctor', name=ctor) return ctor, func
def getCellCtor(dirn, conf=None): ''' Find the ctor option for a Cell and resolve the function. Args: dirn (str): The path to the Cell directory. This may contain the the ctor in the ``config.json`` file. conf (dict): Configuration dictionary for the cell. This may contain the ctor in the ``ctor`` key. Returns: ((str, function)): The python path to the ctor function and the resolved function. Raises: ReqConfOpt: If the ctor cannot be resolved from the cell path or conf NoSuchCtor: If the ctor function cannot be resolved. ''' ctor = None if conf is not None: ctor = conf.get('ctor') path = s_common.genpath(dirn, 'config.json') if ctor is None and os.path.isfile(path): subconf = s_common.jsload(path) ctor = subconf.get('ctor') if ctor is None: raise s_common.ReqConfOpt(mesg='Missing ctor, cannot divide', name='ctor') func = s_dyndeps.getDynLocal(ctor) if func is None: raise s_common.NoSuchCtor(mesg='Cannot resolve ctor', name=ctor) return ctor, func