def invocation(*params): parser = ArgumentParser("Creates invocation schema and validates" " invocations. Uses descriptor's invocation" " schema if it exists, otherwise creates one.") parser.add_argument("descriptor", action="store", help="The Boutiques descriptor as a JSON file, JSON " "string or Zenodo ID (prefixed by 'zenodo.').") parser.add_argument("-i", "--invocation", action="store", help="Input values in a JSON file or as a JSON " "object to be validated against " "the invocation schema.") parser.add_argument("-w", "--write-schema", action="store_true", help="If descriptor doesn't have an invocation " "schema, creates one and writes it to the descriptor" " file ") result = parser.parse_args(params) validate(result.descriptor) descriptor = loadJson(result.descriptor) if descriptor.get("invocation-schema"): invSchema = descriptor.get("invocation-schema") else: from boutiques.invocationSchemaHandler import generateInvocationSchema invSchema = generateInvocationSchema(descriptor) if result.write_schema: descriptor["invocation-schema"] = invSchema with open(result.descriptor, "w") as f: f.write(json.dumps(descriptor, indent=4, sort_keys=True)) if result.invocation: from boutiques.invocationSchemaHandler import validateSchema data = addDefaultValues(descriptor, loadJson(result.invocation)) validateSchema(invSchema, data)
def invocation(*params): parser = parser_invocation() result = parser.parse_args(params) validate(result.descriptor) descriptor = loadJson(result.descriptor) if descriptor.get("invocation-schema"): invSchema = descriptor.get("invocation-schema") else: from boutiques.invocationSchemaHandler import generateInvocationSchema invSchema = generateInvocationSchema(descriptor) if result.write_schema: descriptor["invocation-schema"] = invSchema with open(result.descriptor, "w") as f: f.write(json.dumps(descriptor, indent=4, sort_keys=True)) if result.invocation: from boutiques.invocationSchemaHandler import validateSchema data = addDefaultValues(descriptor, loadJson(result.invocation)) validateSchema(invSchema, data)
def invocation(*params): parser = parser_invocation() results = parser.parse_args(params) arguments = [results.descriptor] if results.sandbox: arguments.append('--sandbox') validate(*arguments) descriptor = loadJson(results.descriptor, sandbox=results.sandbox) if descriptor.get("invocation-schema"): invSchema = descriptor.get("invocation-schema") else: from boutiques.invocationSchemaHandler import generateInvocationSchema invSchema = generateInvocationSchema(descriptor) if results.write_schema: descriptor["invocation-schema"] = invSchema with open(results.descriptor, "w") as f: f.write(json.dumps(descriptor, indent=4)) if results.invocation: from boutiques.invocationSchemaHandler import validateSchema data = addDefaultValues(descriptor, loadJson(results.invocation)) validateSchema(invSchema, data)
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")