Пример #1
0
    def test_example_requires_group_complete_x10(self):
        descriptor = op.join(
            op.split(bfile)[0], 'tests/docopt/valid/test_valid.json')
        from boutiques.localExec import LocalExecutor
        executor = LocalExecutor(
            descriptor, None, {
                "forcePathType": True,
                "destroyTempScripts": True,
                "changeUser": True,
                "skipDataCollect": True,
                "requireComplete": True,
                "sandbox": False
            })

        # Can't create descriptors with mutex group but only one valid example
        # Bosh example is inherently random,
        # Couldn't even inject prederemined input to executor.in_dict
        # because _randomFillInDict clears it
        for _ in range(0, 100):
            executor.generateRandomParams()
            self.assertGreater(len(executor.in_dict), 0)
            executor.in_dict = None
Пример #2
0
def execute(*params):
    parser = parser_execute()
    helps = any([True for ht in ["--help", "-h"] if ht in params])
    if len(params) <= 1 and helps:
        parser.print_help()
        raise SystemExit

    args, params = parser.parse_known_args(params)
    mode = args.mode
    params += ["--help"] if args.help is True else []

    if mode == "launch":
        parser = parser_executeLaunch()
        results = parser.parse_args(params)
        descriptor = results.descriptor
        inp = results.invocation

        # Validate invocation and descriptor
        arguments = [descriptor, '-i', inp]
        if results.sandbox:
            arguments.append('--sandbox')
        valid = invocation(*arguments)

        # Generate object that will perform the commands
        from boutiques.localExec import LocalExecutor
        executor = LocalExecutor(
            descriptor, inp, {
                "forcePathType": True,
                "debug": results.debug,
                "changeUser": results.user,
                "stream": results.stream,
                "imagePath": results.imagepath,
                "skipDataCollect": results.skip_data_collection,
                "forceDocker": results.force_docker,
                "forceSingularity": results.force_singularity,
                "provenance": results.provenance,
                "noContainer": results.no_container,
                "sandbox": results.sandbox
            })
        # Execute it
        return executor.execute(results.volumes)

    if mode == "simulate":
        parser = parser_executeSimulate()
        results = parser.parse_args(params)

        descriptor = results.descriptor

        # Do some basic input scrubbing
        inp = results.input

        arguments = [descriptor]
        if inp:
            arguments.append('-i')
            arguments.append(inp)
        if results.sandbox:
            arguments.append('--sandbox')
        valid = invocation(*arguments)

        # Generate object that will perform the commands
        from boutiques.localExec import LocalExecutor
        executor = LocalExecutor(
            descriptor, inp, {
                "forcePathType": True,
                "destroyTempScripts": True,
                "changeUser": True,
                "skipDataCollect": True,
                "requireComplete": results.complete,
                "sandbox": results.sandbox
            })
        if not inp:
            # Add optional inputs with default-value to inputs_dict,
            # which is then populated with random params
            executor.in_dict = addDefaultValues(executor.desc_dict, {})
            executor.generateRandomParams(generateCmdLineFromInDict=True)

        if results.json:
            sout = [
                json.dumps(customSortInvocationByInput(executor.in_dict,
                                                       descriptor),
                           indent=4)
            ]
            print(sout[0])
        else:
            executor.printCmdLine()
            sout = executor.cmd_line

        # for consistency with execute
        # Adding hide to "container location" field since it's an invalid
        # value, can parse that to hide the summary print
        return ExecutorOutput(os.linesep.join(sout), "", 0, "", [], [],
                              os.linesep.join(sout), "", "hide")

    if mode == "prepare":
        parser = parser_executePrepare()
        results = parser.parse_args(params)
        descriptor = results.descriptor

        # Validate descriptor
        arguments = [descriptor]
        if results.sandbox:
            arguments.append('--sandbox')
        valid = invocation(*arguments)

        # Generate object that will perform the commands
        from boutiques.localExec import LocalExecutor
        executor = LocalExecutor(
            descriptor, None, {
                "forcePathType": True,
                "debug": results.debug,
                "stream": results.stream,
                "imagePath": results.imagepath,
                "skipDataCollect": True,
                "sandbox": results.sandbox
            })
        container_location = executor.prepare()[1]
        print("Container location: " + container_location)

        # Adding hide to "container location" field since it's an invalid
        # value, and we can parse that to hide the summary print
        return ExecutorOutput(container_location, "", 0, "", [], [], "", "",
                              "hide")