示例#1
0
def evaluate(*params):
    parser = ArgumentParser(
        "Evaluates parameter values for a descriptor and invocation")
    parser.add_argument("descriptor",
                        action="store",
                        help="The Boutiques descriptor.")
    parser.add_argument("invocation",
                        action="store",
                        help="Input JSON complying to invocation.")
    parser.add_argument("query",
                        action="store",
                        nargs="*",
                        help="The query to be performed. Simply request keys "
                        "from the descriptor (i.e. output-files), and chain "
                        "together queries (i.e. id=myfile or optional=false) "
                        "slashes between them and commas connecting them. "
                        "(i.e. output-files/optional=false,id=myfile). "
                        "Perform multiple queries by separating them with a "
                        "space.")
    result = parser.parse_args(params)

    # Generate object that will parse the invocation and descriptor
    from boutiques.localExec import LocalExecutor
    executor = LocalExecutor(result.descriptor, {
        "forcePathType": True,
        "destroyTempScripts": True,
        "changeUser": True
    })
    executor.readInput(result.invocation)

    from boutiques.evaluate import evaluateEngine
    query_results = []
    for query in result.query:
        query_results += [evaluateEngine(executor, query)]
    return query_results[0] if len(query_results) == 1 else query_results
示例#2
0
def get_bosh_cmdline(descriptor_filepath, invocation_filepath):

    executor = LocalExecutor(descriptor_filepath, {
        "forcePathType": True,
        "destroyTempScripts": True,
        "changeUser": True,
    })
    executor.readInput(invocation_filepath)

    old_stdout = sys.stdout
    sys.stdout = mystdout = StringIO()
    executor.printCmdLine()

    sys.stdout = old_stdout

    return mystdout.getvalue()[19:]
示例#3
0
def execute(*params):
    parser = ArgumentParser("Boutiques local executor", add_help=False)
    parser.add_argument("mode",
                        action="store",
                        help="Mode of operation to use. Launch: takes a "
                        "set of inputs compliant with invocation schema "
                        "and launches the tool. Simulate: shows sample "
                        "command-lines based on the provided descriptor"
                        " based on provided or randomly generated "
                        "inputs.",
                        choices=["launch", "simulate"])
    parser.add_argument("--help",
                        "-h",
                        action="store_true",
                        help="show this help message and exit")

    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 = ArgumentParser("Launches an invocation.")
        parser.add_argument("descriptor",
                            action="store",
                            help="The Boutiques descriptor.")
        parser.add_argument("input",
                            action="store",
                            help="Input JSON complying to invocation.")
        parser.add_argument("-v",
                            "--volumes",
                            action="store",
                            type=str,
                            help="Volumes to mount when launching the "
                            "container. Format consistently the following:"
                            " /a:/b will mount local direcotry /a to "
                            "container directory /b.",
                            nargs="*")
        parser.add_argument("-x",
                            "--debug",
                            action="store_true",
                            help="Keeps temporary scripts used during "
                            "execution.")
        parser.add_argument(
            "-u",
            "--user",
            action="store_true",
            help="Runs the container as local user ({0}) instead of root.".
            format(os.getenv("USER")))
        results = parser.parse_args(params)
        descriptor = results.descriptor

        # Do some basic input scrubbing
        inp = results.input
        if not os.path.isfile(inp):
            raise SystemExit("Input file {} does not exist".format(inp))
        if not inp.endswith(".json"):
            raise SystemExit("Input file {} must end in json".format(inp))
        if not os.path.isfile(descriptor):
            raise SystemExit(
                "JSON descriptor {} does not exist".format(descriptor))

        # Generate object that will perform the commands
        from boutiques.localExec import LocalExecutor
        executor = LocalExecutor(
            descriptor, {
                "forcePathType": True,
                "destroyTempScripts": not results.debug,
                "changeUser": results.user
            })
        executor.readInput(inp)
        # Execute it
        exit_code = executor.execute(results.volumes)
        if exit_code:
            raise SystemExit(exit_code)

    if mode == "simulate":
        parser = ArgumentParser("Simulates an invocation.")
        parser.add_argument("descriptor",
                            action="store",
                            help="The Boutiques descriptor.")
        parser.add_argument("-i",
                            "--input",
                            action="store",
                            help="Input JSON complying to invocation.")
        parser.add_argument("-r",
                            "--random",
                            action="store",
                            type=int,
                            nargs="*",
                            help="Generate random set of inputs.")
        results = parser.parse_args(params)
        descriptor = results.descriptor

        # Do some basic input scrubbing
        inp = results.input
        rand = results.random is not None
        numb = results.random[0] if rand and len(results.random) > 0 else 1

        if numb and numb < 1:
            raise SystemExit("--number value must be positive.")
        if rand and inp:
            raise SystemExit(
                "--random setting and --input value cannot be used together.")
        if inp and not os.path.isfile(inp):
            raise SystemExit("Input file {} does not exist.".format(inp))
        if inp and not inp.endswith(".json"):
            raise SystemExit("Input file {} must end in 'json'.".format(inp))
        if not os.path.isfile(descriptor):
            raise SystemExit(
                "JSON descriptor {} does not seem to exist.".format(
                    descriptor))
        if not rand and not inp:
            raise SystemExit("The default mode requires an input (-i).")

        # Generate object that will perform the commands
        from boutiques.localExec import LocalExecutor
        executor = LocalExecutor(descriptor, {
            "forcePathType": True,
            "destroyTempScripts": True,
            "changeUser": True
        })
        if rand:
            executor.generateRandomParams(numb)
            executor.printCmdLine()
        else:
            executor.readInput(inp)
            executor.printCmdLine()