Пример #1
0
async def main(argv, outp=s_output.stdout):

    outp.printf(f'Resolving cellpath: {argv[0]}')
    ctor = s_dyndeps.getDynLocal(argv[0])
    if ctor is None:
        raise s_exc.NoSuchCtor(name=argv[0], mesg='No Cell ctor found.')

    return await ctor.initFromArgv(argv[1:], outp=outp)
Пример #2
0
async def getCell(ctor, conf):
    loc = s_dyndeps.getDynLocal(ctor)
    if loc is None:
        raise s_exc.NoSuchCtor(mesg=f'Unable to resolve ctor [{ctor}]',
                               ctor=ctor)
    with s_common.getTempDir() as dirn:
        async with await loc.anit(dirn, conf=conf) as cell:
            yield cell
Пример #3
0
 async def _handleStormVcrCallback(self, text):
     '''
     Get a callback function as a dynlocal
     '''
     cb = s_dyndeps.getDynLocal(text)
     if cb is None:
         raise s_exc.NoSuchCtor(mesg=f'Failed to get callback "{text}"',
                                ctor=text)
     self.context['storm-vcr-callback'] = cb
Пример #4
0
async def getCell(
    outp,
    celldir,
    ctorpath,
    httpport,
    telepath,
    name=None,
):

    outp.printf(f'Resolving cellpath: {ctorpath}')

    ctor = s_dyndeps.getDynLocal(ctorpath)
    if ctor is None:
        raise s_exc.NoSuchCtor(name=ctorpath, mesg='No Cell ctor found.')

    outp.printf(f'starting cell: {celldir}')

    cell = await ctor.anit(celldir)

    try:

        outp.printf(f'...cell API (telepath): {telepath}')
        await cell.dmon.listen(telepath)

        outp.printf(f'...cell API (https): {httpport}')
        await cell.addHttpsPort(httpport)

        if name:
            outp.printf(f'...cell additional share name: {name}')
            cell.dmon.share(name, cell)

        return cell

    except Exception:
        await cell.fini()
        raise
Пример #5
0
async def getCell(outp,
                  celldir,
                  ctorpath,
                  httpport,
                  telepath,
                  name=None,
                  ):

    outp.printf(f'Resolving cellpath: {ctorpath}')

    ctor = s_dyndeps.getDynLocal(ctorpath)
    if ctor is None:
        raise s_exc.NoSuchCtor(name=ctorpath,
                               mesg='No Cell ctor found.')

    outp.printf(f'starting cell: {celldir}')

    cell = await ctor.anit(celldir)

    try:

        outp.printf(f'...cell API (telepath): {telepath}')
        await cell.dmon.listen(telepath)

        outp.printf(f'...cell API (https): {httpport}')
        await cell.addHttpsPort(httpport)

        if name:
            outp.printf(f'...cell additional share name: {name}')
            cell.dmon.share(name, cell)

        return cell

    except Exception:
        await cell.fini()
        raise
Пример #6
0
def getStemCell(dirn):

    if not os.path.isdir(dirn):
        mesg = f'Directory {dirn} does not exist!'
        raise s_exc.NoSuchDir(mesg=mesg)

    ctorname = os.getenv('SYN_STEM_CELL_CTOR')

    cellyaml = os.path.join(dirn, 'cell.yaml')

    if os.path.isfile(cellyaml):
        conf = s_common.yamlload(cellyaml)
        ctorname = conf.get('cell:ctor', ctorname)

    if ctorname is not None:
        ctorname = ctorname.strip()
        ctor = s_dyndeps.getDynLocal(ctorname)
        if ctor is None:
            raise s_exc.NoSuchCtor(mesg=f'Unable to resolve ctor [{ctorname}]',
                                   ctor=ctorname)
        return ctor

    mesg = f'No such file: {cellyaml} and SYN_STEM_CELL_CTOR environmt variable is not set.'
    raise s_exc.NoSuchFile(mesg=mesg, path=cellyaml)
Пример #7
0
 def test_dyndeps_dynloc(self):
     self.none(s_dyndeps.getDynLocal('synapse.tests.test_lib_dyndeps.gronk'))
     self.nn(s_dyndeps.getDynLocal('synapse.tests.test_lib_dyndeps.hehe'))
Пример #8
0
async def genStormRst(path, debug=False):

    outp = []
    context = {}

    with open(path, 'r') as fd:
        lines = fd.readlines()

    for line in lines:

        if line.startswith('.. storm-cortex::'):
            ctor = line.split('::', 1)[1].strip()
            core = await (s_dyndeps.getDynLocal(ctor))()
            if context.get('cortex') is not None:
                await (context.pop('cortex')).fini()
            context['cortex'] = core
            continue

        if line.startswith('.. storm-opts::'):
            item = json.loads(line.split('::', 1)[1].strip())
            context['opts'] = item
            continue

        if line.startswith('.. storm-expect::'):
            # TODO handle some light weight output confirmation.
            continue

        if line.startswith('.. storm-pre::'):
            # runt a storm query to prepare the cortex (do not output)

            text = line.split('::', 1)[1].strip()

            core = context.get('cortex')
            if core is None:
                mesg = 'No cortex set.  Use .. storm-cortex::'
                raise s_exc.NoSuchVar(mesg=mesg)

            opts = context.get('opts')
            await core.callStorm(text, opts=opts)
            continue

        if line.startswith('.. storm::'):

            text = line.split('::', 1)[1].strip()

            core = context.get('cortex')
            if core is None:
                mesg = 'No cortex set.  Use .. storm-cortex::'
                raise s_exc.NoSuchVar(mesg=mesg)

            outp.append('::\n')
            outp.append('\n')

            outp.append(f'    > {text}\n')

            opts = context.get('opts')
            msgs = await core.stormlist(text, opts=opts)

            # TODO use StormOutput
            for mesg in await core.stormlist(text, opts=opts):

                if mesg[0] == 'print':
                    ptxt = mesg[1]['mesg']
                    outp.append(f'    {ptxt}\n')
                    continue

                if mesg[0] == 'warn':
                    ptxt = mesg[1]['mesg']
                    outp.append(f'    WARNING: {ptxt}\n')
                    continue

                if mesg[0] == 'err':
                    raise s_exc.StormRuntimeError(mesg=mesg)

            outp.append('\n')
            continue

        outp.append(line)

    core = context.get('cortex')
    if core is not None:
        await core.fini()

    return outp
Пример #9
0
async def getCell(ctor, conf):
    with s_common.getTempDir() as dirn:
        loc = s_dyndeps.getDynLocal(ctor)
        async with await loc.anit(dirn, conf=conf) as cell:
            yield cell