diff --git a/generator.py b/generator.py index ea6be11..69f7db7 100755 --- a/generator.py +++ b/generator.py @@ -309,6 +309,8 @@ parser.add_argument("-p", "--hardcoded-parameters", dest="hardcoded_parameters", default=None, required=False, help="File containing hardcoded values for the given parameters. Run with '-h' or '--help' " "to see a brief example on the format of this file.") + parser.add_argument("-v", "--validation-schema", dest="xsd_location", default="schema/CTD.xsd", required=False, + help="Location of the schema to use to validate CTDs. Default value is 'schema/CTD.xsd'") # TODO: add verbosity, maybe? parser.add_argument("-V", "--version", action='version', version=program_version_message) @@ -344,7 +346,8 @@ skip_tools=skip_tools, macros_file_names=args.macros_files, macros_to_expand=macros_to_expand, - parameter_hardcoder=parameter_hardcoder) + parameter_hardcoder=parameter_hardcoder, + xsd_location=args.xsd_location) #TODO: add some sort of warning if a macro that doesn't exist is to be expanded @@ -429,6 +432,7 @@ # we do not need to "expand" the advanced_options macro macros_to_expand.remove(ADVANCED_OPTIONS_MACRO_NAME) return macros_to_expand + def parse_hardcoded_parameters(hardcoded_parameters_file): parameter_hardcoder = ParameterHardcoder() @@ -520,7 +524,7 @@ "existing directory.\n" % args.output_destination) # check that the provided input files, if provided, contain a valid file path - input_variables_to_check = ["skip_tools_file", "required_tools_file", "macros_files", + input_variables_to_check = ["skip_tools_file", "required_tools_file", "macros_files", "xsd_location", "input_files", "formats_file", "hardcoded_parameters"] for variable_name in input_variables_to_check: @@ -558,8 +562,10 @@ # first, generate a model is_converting_multiple_ctds = len(input_files) > 1 parsed_models = [] + schema = etree.XMLSchema(etree.parse(kwargs["xsd_location"])) for input_file in input_files: try: + validate_against_schema(input_file, schema) model = CTDModel(from_file=input_file) except Exception, e: error(str(e), 1) @@ -595,6 +601,15 @@ parsed_models.append([model, get_filename(output_file)]) return parsed_models + + +# validates a ctd file against the schema +def validate_against_schema(ctd_file, schema): + try: + parser = etree.XMLParser(schema=schema) + etree.parse(ctd_file, parser=parser) + except etree.XMLSyntaxError, e: + raise ApplicationException("Input ctd file %s is not valid. Reason: %s" % (ctd_file, str(e))) def write_header(tool, model): diff --git a/schema/CTD.xsd b/schema/CTD.xsd new file mode 100644 index 0000000..a8ecb26 --- /dev/null +++ b/schema/CTD.xsd @@ -0,0 +1,205 @@ + + + + + + + + + + + One line description of the tool. + + + + + More detailed description of the tool (about 10 lines). + + + + + + + + + + Optionally a separate name for the executable can be specified here. + + + + + Contains the path were the tool can be found using either the name element or (if set) the executableName. + + + + + + + Defines rules to find the output of the tool and move it to the originally desired location. + + + + + + + + Name of the tool. Needs to pass following regular expression [A-Za-z0-9]+ + + + + + + + + + + URL to further documentation (WWW). + + + + + The category gives information on the task the associated tool performs. It can be used to categorize different tools in a GUI. + + + + + Version of the CTD schema. + + + + + List of tags for the tool. + + + + + + + Wraps the information necessary to construct a command line call for the tool. + + + + + + + + List of citations for the this tool. + + + + + + + + Defines a single citation + + + + The Digital Object Identifier for this citation. + + + + + A URL for this documentation. + + + + + + Defines which ITEM from the parameter part is associated to cliElement. + + + + + + + Wraps a single element of a command line call (e.g., the -v flag for verbosity) and it's associated arguments. To model a non-option argument just leave the optionIdentifier empty. + + + + + The mapping defines the association between the cliElement and the PARAM part. Note: If the mapped parameter is boolean, the optionIdentifier will be added to the CLI only if the mapped value is true. + + + + + + A string used to prefix any associated values (e.g., "-v" for a boolean flag to turn on verbosity). + + + + + A boolean attribute indicating whether or not the given cliElement can be expended to occur more then once on the command line. + + + + + Defines if the cliElement is required to build the full command line, i.e., if required is set to false and the mapped parameter was not set the complete element will not be used on the final cli. + + + + + + Wraps the log informations from the call of the tool. + + + + + ... + + + + + + + Wraps the log informations from the call of the tool. + + + + + ... + + + + + ... + + + + + + + + + + + + + + + + + + + + + + + Defines a relocation rule using a pattern to find the file and the targeted output file where the found file should be moved to. + + + + The referenced parameter which should be relocated. + + + + + The location of the output file defined using following variables: +%TEMP% - the temporary directory while executing +%PWD% - the working directory while executing +%BASENAME[PARAM]% - the base name of PARAM + + + + + \ No newline at end of file diff --git a/schema/Param_1_7_0.xsd b/schema/Param_1_7_0.xsd new file mode 100644 index 0000000..1e75b63 --- /dev/null +++ b/schema/Param_1_7_0.xsd @@ -0,0 +1,130 @@ + + + + + Main parameters node. + + + + + + + + + + + + + + + + + + + + The type of the specified ITEM. Either input or output. + + + + + + A short description of the parameter. + + + + + Additional annotations of the parameter incl. required, advanced, thread, debug, internal, file-type-override, log + + + + + + Defines the expected file types. Only valid for input-file, output-file, input-prefix, and output-prefix parameters. + + + + + Deprecated, embed as tag into tags attribute. Will be removed in v2.0.0 of the schema. + + + + + Deprecated, embed as tag into tags attribute. Will be removed in v2.0.0 of the schema. + + + + + + + + + + + + + + + + + + + + + The actual value of the parameter. + + + + + If available, the default value of the given parameter. + + + + + + + + Defines the possible types available in the type attribute of ITEM and ITEMLIST. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file