예제 #1
0
    def __getattr__(self, name):
        path = self._tele_csides.get(name)
        if path is not None:
            func = s_dyndeps.getDynMeth(path)
            if func is None:
                return None

            meth = func.__get__(self)

        else:
            meth = Method(self, name)

        setattr(self, name, meth)
        return meth
예제 #2
0
 def test_dyndeps_meth(self):
     self.nn(s_dyndeps.getDynMeth('synapse.telepath.Proxy.on'))
     self.none(s_dyndeps.getDynMeth('synapse.telepath.Proxy.newp'))
예제 #3
0
파일: autodoc.py 프로젝트: thpatel/synapse
def docConfigables(outp, fd):
    rst = RstHelp()
    rst.addHead('Synapse Configable Classes', lvl=0)
    rst.addLines('The following objects are Configable objects. They have'
                 ' settings which may be provided at runtime or during object'
                 ' initialization which may change their behavior.')
    basename = 'synapse'
    confdetails = collections.defaultdict(list)

    for root, dirs, files in os.walk(base_synaspe_dir):

        if any([v for v in dir_skips if v in root]):
            continue

        for fn in files:
            if fn in fn_skips:
                continue
            if not fn.endswith('.py'):
                continue

            modname = fn.rsplit('.', 1)[0]
            _modpath = root[len(base_synaspe_dir) + 1:].replace(os.sep, '.')
            modpath = '.'.join([v for v in [basename, _modpath, modname] if v])

            mod = importlib.import_module(modpath)
            for modattr, valu, name, results in inspect_mod(mod, cls=s_config.Configable):
                confdetails[modpath].append((modattr, name, results))

    # Collapse details into a modpath -> Details struct
    detaildict = collections.defaultdict(list)

    for modpath, details in confdetails.items():
        for detail in details:
            modattr, name, results = detail
            obj_path = '.'.join([modpath, modattr])
            if obj_path in obj_path_skips:
                continue
            for rslt in results:
                if not rslt:
                    continue
                detaildict[obj_path].append(rslt)

    # Extract configable information from object instances
    cls_req_paths = tuple([s_dyndeps.getDynMeth(obj_path) for obj_path
                           in obj_instance_reqpath])
    tdir = tempfile.mkdtemp()
    for obj_path, conf in obj_instance_confs:
        fp = os.path.join(tdir, obj_path)
        cls = s_dyndeps.getDynMeth(obj_path)
        # Handle special configables which require additional args
        if issubclass(cls, cls_req_paths):
            os.makedirs(fp)
            obj = cls(fp, conf=conf)  # type: s_config.Config
        else:
            obj = cls(conf=conf)  # type: s_config.Config
        cdefs = obj.getConfDefs()
        cdefs = list(cdefs.items())
        detaildict[obj_path].extend(cdefs)
        obj.fini()
    shutil.rmtree(tdir, ignore_errors=True)

    # Now make the RST proper like
    keys = list(detaildict.keys())
    keys.sort()
    for obj_path in keys:
        details = detaildict.get(obj_path, [])
        details.sort(key=lambda x: x[0])
        rst.addHead(name=obj_path, lvl=1)
        for detail in details:
            confvalu, confdict = detail[0], detail[1]
            rst.addHead(confvalu, lvl=2)
            _keys = list(confdict.keys())
            _keys.sort()
            for _key in _keys:
                v = confdict.get(_key)
                line = '  - {}: {}'.format(_key, v)
                rst.addLines(line)

    outp.printf(rst.getRstText())
    if fd:
        fd.close()
    return 0
예제 #4
0
 def test_dyndeps_meth(self):
     self.nn(s_dyndeps.getDynMeth('synapse.eventbus.EventBus.fini'))
     self.none(s_dyndeps.getDynMeth('synapse.eventbus.EventBus.newp'))