Exemplo n.º 1
0
def pubtest(
    spec,
    parfiles,
    state,
    parameter,
    read,
    write,
    toplevel,
    schemasource,
    validate,
    verbosity,
    backend,
):
    logging.basicConfig(level=getattr(logging, verbosity))
    spec = utils.load_packtivity(spec, toplevel, schemasource, validate)
    state = yaml.safe_load(open(state)) if state else {}
    if not state:
        state.setdefault("readwrite", []).extend(map(os.path.realpath, write))
        state.setdefault("readonly", []).extend(map(os.path.realpath, read))
    state = LocalFSState(state["readwrite"], state["readonly"])

    parameters = getinit_data(parfiles, parameter)

    is_sync, backend = bkutils.backend_from_string(backend)
    publish = backend.prepublish(spec, parameters, state)
    click.echo(str(publish))
Exemplo n.º 2
0
def validatecli(spec,toplevel,schemasource,schemaname,show):
    try:
        spec = utils.load_packtivity(spec,toplevel,schemasource,validate = True)
        if show:
            click.echo(json.dumps(dict(spec)))
        else:
            click.secho('packtivity definition is valid',fg = 'green')
    except jsonschema.exceptions.ValidationError as e:
        click.echo(e)
        raise click.ClickException(click.style('packtivity definition not valid',fg = 'red'))
Exemplo n.º 3
0
def runcli(
    spec,
    parfiles,
    state,
    parameter,
    read,
    write,
    toplevel,
    schemasource,
    asyncwait,
    validate,
    verbosity,
    backend,
    proxyfile,
    outfile,
):
    logging.basicConfig(level=getattr(logging, verbosity))

    spec = utils.load_packtivity(spec, toplevel, schemasource, validate)

    parameters = getinit_data(parfiles, parameter)

    state = yaml.safe_load(open(state)) if state else {}
    if not state:
        state.setdefault("readwrite", []).extend(map(os.path.realpath, write))
        state.setdefault("readonly", []).extend(map(os.path.realpath, read))
    state = LocalFSState(state["readwrite"], state["readonly"])
    state.ensure()

    is_sync, backend = bkutils.backend_from_string(backend)
    backend_kwargs = ({
        "syncbackend": backend
    } if is_sync else {
        "asyncbackend": backend,
        "asyncwait": asyncwait
    })

    prepub = backend.prepublish(spec, parameters, state)
    if prepub:
        click.echo(str(prepub) + (" (prepublished)"))

    pack = packtivity.pack_object(spec)

    result = pack(parameters, state, **backend_kwargs)

    if not is_sync and not asyncwait:
        click.secho("proxy-json {}".format(json.dumps(result.json())))
        with open(proxyfile, "w") as p:
            json.dump(result.json(), p)
    else:
        click.echo(str(result) + (" (post-run)" if prepub else ""))
        if outfile:
            with open(outfile, "w") as out:
                out.write(json.dumps(result.json()))
Exemplo n.º 4
0
def pubtest(spec,parfiles,state,parameter,read,write,toplevel,schemasource,validate,verbosity,backend):
    logging.basicConfig(level = getattr(logging,verbosity))
    spec = utils.load_packtivity(spec,toplevel,schemasource,validate)
    state    = yaml.load(open(state)) if state else {}
    if not state:
        state.setdefault('readwrite',[]).extend(map(os.path.realpath,write))
        state.setdefault('readonly',[]).extend(map(os.path.realpath,read))
    state = LocalFSState(state['readwrite'],state['readonly'])

    parameters = getinit_data(parfiles,parameter)

    is_sync, backend = bkutils.backend_from_string(backend)
    publish = backend.prepublish(spec,parameters,state)
    click.echo(str(publish))
Exemplo n.º 5
0
def validatecli(spec, toplevel, schemasource, schemaname, show):
    try:
        spec = utils.load_packtivity(spec,
                                     toplevel,
                                     schemasource,
                                     validate=True)
        if show:
            click.echo(json.dumps(dict(spec)))
        else:
            click.secho("packtivity definition is valid", fg="green")
    except jsonschema.exceptions.ValidationError as e:
        click.echo(e)
        raise click.ClickException(
            click.style("packtivity definition not valid", fg="red"))
Exemplo n.º 6
0
def shell(
    spec,
    parfiles,
    state,
    parameter,
    read,
    write,
    toplevel,
    schemasource,
    validate,
    verbosity,
    backend,
):
    logging.basicConfig(level=getattr(logging, verbosity))

    from .datamodel import create

    parameters = create(getinit_data(parfiles, parameter))

    spec = utils.load_packtivity(spec, toplevel, schemasource, validate)
    state = yaml.safe_load(open(state)) if state else {}
    if not state:
        state.setdefault("readwrite", []).extend(map(os.path.realpath, write))
        state.setdefault("readonly", []).extend(map(os.path.realpath, read))
    state = LocalFSState(state["readwrite"], state["readonly"])

    state.ensure()

    _, backend = packtivity.backendutils.backend_from_string("foregroundasync")

    env = packtivity.syncbackends.build_env(spec["environment"], parameters,
                                            state, backend.pack_config)

    if spec['process']['process_type'] == 'interpolated-script-cmd':
        job = {'interactive': spec['process']['interpreter']}
    else:
        job = {'interactive': 'sh'}
    metadata = {'name': 'test'}

    result = packtivity.syncbackends.run_in_env(job, env, state, metadata,
                                                backend.pack_config,
                                                backend.exec_config)

    print(result)
Exemplo n.º 7
0
def runcli(spec,parfiles,state,parameter,read,write,toplevel,schemasource,asyncwait,validate,verbosity,backend,proxyfile,outfile):
    logging.basicConfig(level = getattr(logging,verbosity))

    spec = utils.load_packtivity(spec,toplevel,schemasource,validate)

    parameters = getinit_data(parfiles,parameter)

    state    = yaml.load(open(state)) if state else {}
    if not state:
        state.setdefault('readwrite',[]).extend(map(os.path.realpath,write))
        state.setdefault('readonly',[]).extend(map(os.path.realpath,read))
    state = LocalFSState(state['readwrite'],state['readonly'])
    state.ensure()


    is_sync, backend = bkutils.backend_from_string(backend)
    backend_kwargs = {
        'syncbackend': backend
    } if is_sync else {
        'asyncbackend':backend,
        'asyncwait': asyncwait
    }

    prepub = backend.prepublish(spec,parameters,state)
    if prepub:
        click.echo(str(prepub)+(' (prepublished)'))

    pack = packtivity.pack_object(spec)

    result = pack(parameters,state,**backend_kwargs)

    if not is_sync and not asyncwait:
        click.secho('proxy-json {}'.format(json.dumps(result.json())))
        with open(proxyfile,'w') as p:
            json.dump(result.json(),p)
    else:
        click.echo(str(result)+(' (post-run)' if prepub else ''))
        if outfile:
            with open(outfile,'w') as out:
                out.write(json.dumps(result.json()))
Exemplo n.º 8
0
 def fromspec(cls, *args, **kwargs):
     return cls(load_packtivity(*args, **kwargs))
Exemplo n.º 9
0
def test_cliload_valid():
    load_packtivity('tests/testspecs/noop-test.yml', os.getcwd(), schemadir, True)
Exemplo n.º 10
0
def test_cliload_accept_non_valid():
    load_packtivity('tests/testspecs/noop-test-invalid.yml', os.getcwd(), schemadir, False)
Exemplo n.º 11
0
def test_cliload_non_valid():
    with pytest.raises(ValidationError):
        load_packtivity('tests/testspecs/noop-test-invalid.yml', os.getcwd(), schemadir, True)