Package list ctdconverter / 548b918
Added validation against a schema Luis de la Garza 5 years ago
3 changed file(s) with 352 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
308308 parser.add_argument("-p", "--hardcoded-parameters", dest="hardcoded_parameters", default=None, required=False,
309309 help="File containing hardcoded values for the given parameters. Run with '-h' or '--help' "
310310 "to see a brief example on the format of this file.")
311 parser.add_argument("-v", "--validation-schema", dest="xsd_location", default="schema/CTD.xsd", required=False,
312 help="Location of the schema to use to validate CTDs. Default value is 'schema/CTD.xsd'")
311313
312314 # TODO: add verbosity, maybe?
313315 parser.add_argument("-V", "--version", action='version', version=program_version_message)
343345 skip_tools=skip_tools,
344346 macros_file_names=args.macros_files,
345347 macros_to_expand=macros_to_expand,
346 parameter_hardcoder=parameter_hardcoder)
348 parameter_hardcoder=parameter_hardcoder,
349 xsd_location=args.xsd_location)
347350
348351 #TODO: add some sort of warning if a macro that doesn't exist is to be expanded
349352
428431 # we do not need to "expand" the advanced_options macro
429432 macros_to_expand.remove(ADVANCED_OPTIONS_MACRO_NAME)
430433 return macros_to_expand
434
431435
432436 def parse_hardcoded_parameters(hardcoded_parameters_file):
433437 parameter_hardcoder = ParameterHardcoder()
519523 "existing directory.\n" % args.output_destination)
520524
521525 # check that the provided input files, if provided, contain a valid file path
522 input_variables_to_check = ["skip_tools_file", "required_tools_file", "macros_files",
526 input_variables_to_check = ["skip_tools_file", "required_tools_file", "macros_files", "xsd_location",
523527 "input_files", "formats_file", "hardcoded_parameters"]
524528
525529 for variable_name in input_variables_to_check:
557561 # first, generate a model
558562 is_converting_multiple_ctds = len(input_files) > 1
559563 parsed_models = []
564 schema = etree.XMLSchema(etree.parse(kwargs["xsd_location"]))
560565 for input_file in input_files:
561566 try:
567 validate_against_schema(input_file, schema)
562568 model = CTDModel(from_file=input_file)
563569 except Exception, e:
564570 error(str(e), 1)
594600 parsed_models.append([model, get_filename(output_file)])
595601
596602 return parsed_models
603
604
605 # validates a ctd file against the schema
606 def validate_against_schema(ctd_file, schema):
607 try:
608 parser = etree.XMLParser(schema=schema)
609 etree.parse(ctd_file, parser=parser)
610 except etree.XMLSyntaxError, e:
611 raise ApplicationException("Input ctd file %s is not valid. Reason: %s" % (ctd_file, str(e)))
597612
598613
599614 def write_header(tool, model):
0 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
1 <!-- Mit XMLSpy v2007 sp1 bearbeitet (http://www.altova.com) von Oliver Kohlbacher (Universität Tübingen) -->
2 <!-- Draft-Version 0.3 -->
3 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
4 <xs:include schemaLocation="Param_1_7_0.xsd" />
5 <xs:element name="tool">
6 <xs:complexType>
7 <xs:all>
8 <xs:element name="description" type="xs:string" minOccurs="0">
9 <xs:annotation>
10 <xs:documentation>One line description of the tool.</xs:documentation>
11 </xs:annotation>
12 </xs:element>
13 <xs:element name="manual" type="xs:string" minOccurs="0">
14 <xs:annotation>
15 <xs:documentation>More detailed description of the tool (about 10 lines).</xs:documentation>
16 </xs:annotation>
17 </xs:element>
18 <xs:element name="citations" type="citationsType" minOccurs="0">
19 <xs:annotation>
20 <xs:documentation />
21 </xs:annotation>
22 </xs:element>
23 <xs:element name="executableName" type="xs:string" minOccurs="0">
24 <xs:annotation>
25 <xs:documentation>Optionally a separate name for the executable can be specified here.</xs:documentation>
26 </xs:annotation>
27 </xs:element>
28 <xs:element name="executablePath" type="xs:anyURI" minOccurs="0">
29 <xs:annotation>
30 <xs:documentation>Contains the path were the tool can be found using either the name element or (if set) the executableName.</xs:documentation>
31 </xs:annotation>
32 </xs:element>
33 <xs:element name="cli" type="cliType" minOccurs="0" />
34 <xs:element name="logs" type="logCollectionType" minOccurs="0" />
35 <xs:element name="relocators" type="relocatorCollectionType" minOccurs="0">
36 <xs:annotation>
37 <xs:documentation>Defines rules to find the output of the tool and move it to the originally desired location.</xs:documentation>
38 </xs:annotation>
39 </xs:element>
40 <xs:element name="PARAMETERS" type="PARAMETERSType" />
41 </xs:all>
42 <xs:attribute name="version" type="xs:string" use="required" />
43 <xs:attribute name="name" use="required">
44 <xs:annotation>
45 <xs:documentation>Name of the tool. Needs to pass following regular expression [A-Za-z0-9]+</xs:documentation>
46 </xs:annotation>
47 <xs:simpleType>
48 <xs:restriction base="xs:string">
49 <xs:pattern value="[A-Za-z0-9]+" />
50 </xs:restriction>
51 </xs:simpleType>
52 </xs:attribute>
53 <xs:attribute name="docurl" type="xs:anyURI">
54 <xs:annotation>
55 <xs:documentation>URL to further documentation (WWW).</xs:documentation>
56 </xs:annotation>
57 </xs:attribute>
58 <xs:attribute name="category" type="xs:string" default="">
59 <xs:annotation>
60 <xs:documentation>The category gives information on the task the associated tool performs. It can be used to categorize different tools in a GUI.</xs:documentation>
61 </xs:annotation>
62 </xs:attribute>
63 <xs:attribute name="ctdVersion" type="versionString" use="required">
64 <xs:annotation>
65 <xs:documentation>Version of the CTD schema.</xs:documentation>
66 </xs:annotation>
67 </xs:attribute>
68 <xs:attribute name="tags" type="xs:string">
69 <xs:annotation>
70 <xs:documentation>List of tags for the tool.</xs:documentation>
71 </xs:annotation>
72 </xs:attribute>
73 </xs:complexType>
74 </xs:element>
75 <xs:complexType name="cliType">
76 <xs:annotation>
77 <xs:documentation>Wraps the information necessary to construct a command line call for the tool.</xs:documentation>
78 </xs:annotation>
79 <xs:sequence>
80 <xs:element name="clielement" type="cliElementType" maxOccurs="unbounded" />
81 </xs:sequence>
82 </xs:complexType>
83 <xs:complexType name="citationsType">
84 <xs:annotation>
85 <xs:documentation>List of citations for the this tool.</xs:documentation>
86 </xs:annotation>
87 <xs:sequence>
88 <xs:element name="citation" type="citationType" maxOccurs="unbounded" />
89 </xs:sequence>
90 </xs:complexType>
91 <xs:complexType name="citationType">
92 <xs:annotation>
93 <xs:documentation>Defines a single citation</xs:documentation>
94 </xs:annotation>
95 <xs:attribute name="doi" type="xs:string">
96 <xs:annotation>
97 <xs:documentation>The Digital Object Identifier for this citation.</xs:documentation>
98 </xs:annotation>
99 </xs:attribute>
100 <xs:attribute name="url" type="xs:anyURI">
101 <xs:annotation>
102 <xs:documentation>A URL for this documentation.</xs:documentation>
103 </xs:annotation>
104 </xs:attribute>
105 </xs:complexType>
106 <xs:complexType name="mappingType">
107 <xs:annotation>
108 <xs:documentation>Defines which ITEM from the parameter part is associated to cliElement.</xs:documentation>
109 </xs:annotation>
110 <xs:attribute name="referenceName" type="xs:string" />
111 <xs:attribute name="referenceID" type="xs:IDREF" />
112 </xs:complexType>
113 <xs:complexType name="cliElementType">
114 <xs:annotation>
115 <xs:documentation>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.</xs:documentation>
116 </xs:annotation>
117 <xs:sequence>
118 <xs:element name="mapping" type="mappingType" minOccurs="0" maxOccurs="unbounded">
119 <xs:annotation>
120 <xs:documentation>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.</xs:documentation>
121 </xs:annotation>
122 </xs:element>
123 </xs:sequence>
124 <xs:attribute name="optionIdentifier" type="xs:string" use="optional">
125 <xs:annotation>
126 <xs:documentation>A string used to prefix any associated values (e.g., "-v" for a boolean flag to turn on verbosity).</xs:documentation>
127 </xs:annotation>
128 </xs:attribute>
129 <xs:attribute name="isList" type="xs:boolean" use="optional">
130 <xs:annotation>
131 <xs:documentation>A boolean attribute indicating whether or not the given cliElement can be expended to occur more then once on the command line.</xs:documentation>
132 </xs:annotation>
133 </xs:attribute>
134 <xs:attribute name="required" type="xs:boolean" use="optional">
135 <xs:annotation>
136 <xs:documentation>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.</xs:documentation>
137 </xs:annotation>
138 </xs:attribute>
139 </xs:complexType>
140 <xs:complexType name="logCollectionType">
141 <xs:annotation>
142 <xs:documentation>Wraps the log informations from the call of the tool.</xs:documentation>
143 </xs:annotation>
144 <xs:sequence>
145 <xs:element name="log" type="logType" maxOccurs="unbounded">
146 <xs:annotation>
147 <xs:documentation>...</xs:documentation>
148 </xs:annotation>
149 </xs:element>
150 </xs:sequence>
151 </xs:complexType>
152 <xs:complexType name="logType">
153 <xs:annotation>
154 <xs:documentation>Wraps the log informations from the call of the tool.</xs:documentation>
155 </xs:annotation>
156 <xs:sequence>
157 <xs:element name="executionWarnings" type="xs:string" minOccurs="0" maxOccurs="unbounded">
158 <xs:annotation>
159 <xs:documentation>...</xs:documentation>
160 </xs:annotation>
161 </xs:element>
162 <xs:element name="executionErrors" type="xs:string" minOccurs="0" maxOccurs="unbounded">
163 <xs:annotation>
164 <xs:documentation>...</xs:documentation>
165 </xs:annotation>
166 </xs:element>
167 <xs:element name="executionMessage" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
168 </xs:sequence>
169 <xs:attribute name="executionTimeStart" type="xs:dateTime" use="required" />
170 <xs:attribute name="executionTimeStop" type="xs:dateTime" use="required" />
171 <xs:attribute name="executionStatus" type="xs:int" use="required" />
172 </xs:complexType>
173 <xs:complexType name="logMessageType">
174 <xs:sequence>
175 <xs:element name="logMessage" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
176 </xs:sequence>
177 <xs:attribute name="NODEref" type="xs:IDREF" />
178 </xs:complexType>
179 <xs:complexType name="relocatorCollectionType">
180 <xs:sequence>
181 <xs:element name="relocator" type="relocatorType" />
182 </xs:sequence>
183 </xs:complexType>
184 <xs:complexType name="relocatorType">
185 <xs:sequence>
186 <xs:annotation>
187 <xs:documentation>Defines a relocation rule using a pattern to find the file and the targeted output file where the found file should be moved to.</xs:documentation>
188 </xs:annotation>
189 <xs:element name="reference" type="xs:string">
190 <xs:annotation>
191 <xs:documentation>The referenced parameter which should be relocated.</xs:documentation>
192 </xs:annotation>
193 </xs:element>
194 <xs:element name="location" type="xs:string">
195 <xs:annotation>
196 <xs:documentation>The location of the output file defined using following variables:
197 %TEMP% - the temporary directory while executing
198 %PWD% - the working directory while executing
199 %BASENAME[PARAM]% - the base name of PARAM</xs:documentation>
200 </xs:annotation>
201 </xs:element>
202 </xs:sequence>
203 </xs:complexType>
204 </xs:schema>
0 <?xml version="1.0" encoding="UTF-8"?>
1 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
2 <xs:element name="PARAMETERS" type="PARAMETERSType">
3 <xs:annotation>
4 <xs:documentation>Main parameters node.</xs:documentation>
5 </xs:annotation>
6 </xs:element>
7 <xs:complexType name="PARAMETERSType">
8 <xs:sequence>
9 <xs:group ref="ITEMS" minOccurs="0" maxOccurs="unbounded" />
10 <xs:element name="NODE" type="NODEType" minOccurs="0" maxOccurs="unbounded" />
11 </xs:sequence>
12 <xs:attribute name="version" type="versionString" />
13 </xs:complexType>
14 <xs:complexType name="AbstractITEMType" abstract="true">
15 <xs:attribute name="name" use="required">
16 <xs:simpleType>
17 <xs:restriction base="xs:string">
18 <xs:minLength value="1" />
19 </xs:restriction>
20 </xs:simpleType>
21 </xs:attribute>
22 <xs:attribute name="type" type="PossibleITEMType" use="required">
23 <xs:annotation>
24 <xs:documentation>The type of the specified ITEM. Either input or output.</xs:documentation>
25 </xs:annotation>
26 </xs:attribute>
27 <xs:attribute name="description" type="xs:string" default="" />
28 <xs:attribute name="short_description" type="xs:string">
29 <xs:annotation>
30 <xs:documentation>A short description of the parameter.</xs:documentation>
31 </xs:annotation>
32 </xs:attribute>
33 <xs:attribute name="tags" type="xs:string" default="false">
34 <xs:annotation>
35 <xs:documentation>Additional annotations of the parameter incl. required, advanced, thread, debug, internal, file-type-override, log</xs:documentation>
36 </xs:annotation>
37 </xs:attribute>
38 <xs:attribute name="restrictions" type="xs:string" default="" />
39 <xs:attribute name="supported_formats" type="xs:string" default="false">
40 <xs:annotation>
41 <xs:documentation>Defines the expected file types. Only valid for input-file, output-file, input-prefix, and output-prefix parameters.</xs:documentation>
42 </xs:annotation>
43 </xs:attribute>
44 <xs:attribute name="required" type="xs:boolean" default="false">
45 <xs:annotation>
46 <xs:documentation>Deprecated, embed as tag into tags attribute. Will be removed in v2.0.0 of the schema.</xs:documentation>
47 </xs:annotation>
48 </xs:attribute>
49 <xs:attribute name="advanced" type="xs:boolean" default="false">
50 <xs:annotation>
51 <xs:documentation>Deprecated, embed as tag into tags attribute. Will be removed in v2.0.0 of the schema.</xs:documentation>
52 </xs:annotation>
53 </xs:attribute>
54 </xs:complexType>
55 <xs:complexType name="ITEMLISTType">
56 <xs:complexContent>
57 <xs:extension base="AbstractITEMType">
58 <xs:sequence>
59 <xs:element name="LISTITEM" type="LISTITEMType" minOccurs="0" maxOccurs="unbounded" />
60 </xs:sequence>
61 </xs:extension>
62 </xs:complexContent>
63 </xs:complexType>
64 <xs:complexType name="LISTITEMType">
65 <xs:attribute name="value" use="required" />
66 </xs:complexType>
67 <xs:complexType name="ITEMType">
68 <xs:complexContent>
69 <xs:extension base="AbstractITEMType">
70 <xs:attribute name="value" type="xs:string" use="required">
71 <xs:annotation>
72 <xs:documentation>The actual value of the parameter.</xs:documentation>
73 </xs:annotation>
74 </xs:attribute>
75 <xs:attribute name="default" type="xs:string" use="optional">
76 <xs:annotation>
77 <xs:documentation>If available, the default value of the given parameter.</xs:documentation>
78 </xs:annotation>
79 </xs:attribute>
80 </xs:extension>
81 </xs:complexContent>
82 </xs:complexType>
83 <xs:simpleType name="PossibleITEMType">
84 <xs:annotation>
85 <xs:documentation>Defines the possible types available in the type attribute of ITEM and ITEMLIST.</xs:documentation>
86 </xs:annotation>
87 <xs:restriction base="xs:string">
88 <xs:enumeration value="int" />
89 <xs:enumeration value="double" />
90 <xs:enumeration value="float" />
91 <xs:enumeration value="string" />
92 <xs:enumeration value="int-pair" />
93 <xs:enumeration value="double-pair" />
94 <xs:enumeration value="input-prefix" />
95 <xs:enumeration value="output-prefix" />
96 <xs:enumeration value="input-file" />
97 <xs:enumeration value="output-file" />
98 <xs:enumeration value="bool" />
99 </xs:restriction>
100 </xs:simpleType>
101 <xs:group name="ITEMS">
102 <xs:choice>
103 <xs:element name="ITEM" type="ITEMType" />
104 <xs:element name="ITEMLIST" type="ITEMLISTType" />
105 </xs:choice>
106 </xs:group>
107 <xs:complexType name="NODEType">
108 <xs:annotation>
109 <xs:documentation />
110 </xs:annotation>
111 <xs:choice minOccurs="0" maxOccurs="unbounded">
112 <xs:group ref="ITEMS" />
113 <xs:element name="NODE" type="NODEType" />
114 </xs:choice>
115 <xs:attribute name="name" use="required">
116 <xs:simpleType>
117 <xs:restriction base="xs:string">
118 <xs:minLength value="1" />
119 </xs:restriction>
120 </xs:simpleType>
121 </xs:attribute>
122 <xs:attribute name="description" type="xs:string" default="" />
123 </xs:complexType>
124 <xs:simpleType name="versionString">
125 <xs:restriction base="xs:string">
126 <xs:pattern value="\d+\.\d+(\.\d+)?" />
127 </xs:restriction>
128 </xs:simpleType>
129 </xs:schema>