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 invocation(*params): parser = ArgumentParser( "Creates invocation schema and validates invocations") parser.add_argument("descriptor", action="store", help="The Boutiques descriptor.") parser.add_argument( "-i", "--invocation", action="store", help="Input values in a JSON file to be validated against " "the invocation schema.") result = parser.parse_args(params) try: from jsonschema import ValidationError validate(result.descriptor) if result.invocation: data = json.loads(open(result.invocation).read()) except ValidationError as e: print("Error reading JSON:") raise ValidationError(e.message) descriptor = json.loads(open(result.descriptor).read()) if descriptor.get("invocation-schema"): invSchema = descriptor.get("invocation-schema") else: from boutiques.invocationSchemaHandler import generateInvocationSchema invSchema = generateInvocationSchema(descriptor) 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 try: validateSchema(invSchema, data) except ValidationError as e: print("Invalid invocation:") raise ValidationError(e.message)