172 # First case, value starts with "0x" or "-0x", then it's an hexadecimal value |
172 # First case, value starts with "0x" or "-0x", then it's an hexadecimal value |
173 if value.startswith("0x") or value.startswith("-0x"): |
173 if value.startswith("0x") or value.startswith("-0x"): |
174 try: |
174 try: |
175 computed_value = int(value, 16) |
175 computed_value = int(value, 16) |
176 except: |
176 except: |
177 raise SyntaxError, "\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\""%(value, keyname, section_name) |
177 raise SyntaxError, _("\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\"")%(value, keyname, section_name) |
178 elif value.isdigit() or value.startswith("-") and value[1:].isdigit(): |
178 elif value.isdigit() or value.startswith("-") and value[1:].isdigit(): |
179 # Second case, value is a number and starts with "0" or "-0", then it's an octal value |
179 # Second case, value is a number and starts with "0" or "-0", then it's an octal value |
180 if value.startswith("0") or value.startswith("-0"): |
180 if value.startswith("0") or value.startswith("-0"): |
181 computed_value = int(value, 8) |
181 computed_value = int(value, 8) |
182 # Third case, value is a number and don't start with "0", then it's a decimal value |
182 # Third case, value is a number and don't start with "0", then it's a decimal value |
191 nodename_result = nodename_model.match(keyname.upper()) |
191 nodename_result = nodename_model.match(keyname.upper()) |
192 nodedcfname_result = nodedcfname_model.match(keyname.upper()) |
192 nodedcfname_result = nodedcfname_model.match(keyname.upper()) |
193 |
193 |
194 if keyname.upper() == "NETNAME": |
194 if keyname.upper() == "NETNAME": |
195 if not is_string(computed_value): |
195 if not is_string(computed_value): |
196 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name) |
196 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name) |
197 topology["Name"] = computed_value |
197 topology["Name"] = computed_value |
198 elif keyname.upper() == "NODES": |
198 elif keyname.upper() == "NODES": |
199 if not is_integer(computed_value): |
199 if not is_integer(computed_value): |
200 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name) |
200 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name) |
201 topology["Number"] = computed_value |
201 topology["Number"] = computed_value |
202 elif keyname.upper() == "EDSBASENAME": |
202 elif keyname.upper() == "EDSBASENAME": |
203 if not is_string(computed_value): |
203 if not is_string(computed_value): |
204 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name) |
204 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name) |
205 topology["Path"] = computed_value |
205 topology["Path"] = computed_value |
206 elif nodepresent_result: |
206 elif nodepresent_result: |
207 if not is_boolean(computed_value): |
207 if not is_boolean(computed_value): |
208 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name) |
208 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name) |
209 nodeid = int(nodepresent_result.groups()[0]) |
209 nodeid = int(nodepresent_result.groups()[0]) |
210 if nodeid not in topology["Nodes"].keys(): |
210 if nodeid not in topology["Nodes"].keys(): |
211 topology["Nodes"][nodeid] = {} |
211 topology["Nodes"][nodeid] = {} |
212 topology["Nodes"][nodeid]["Present"] = computed_value |
212 topology["Nodes"][nodeid]["Present"] = computed_value |
213 elif nodename_result: |
213 elif nodename_result: |
214 if not is_string(value): |
214 if not is_string(value): |
215 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name) |
215 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name) |
216 nodeid = int(nodename_result.groups()[0]) |
216 nodeid = int(nodename_result.groups()[0]) |
217 if nodeid not in topology["Nodes"].keys(): |
217 if nodeid not in topology["Nodes"].keys(): |
218 topology["Nodes"][nodeid] = {} |
218 topology["Nodes"][nodeid] = {} |
219 topology["Nodes"][nodeid]["Name"] = computed_value |
219 topology["Nodes"][nodeid]["Name"] = computed_value |
220 elif nodedcfname_result: |
220 elif nodedcfname_result: |
221 if not is_string(computed_value): |
221 if not is_string(computed_value): |
222 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name) |
222 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name) |
223 nodeid = int(nodedcfname_result.groups()[0]) |
223 nodeid = int(nodedcfname_result.groups()[0]) |
224 if nodeid not in topology["Nodes"].keys(): |
224 if nodeid not in topology["Nodes"].keys(): |
225 topology["Nodes"][nodeid] = {} |
225 topology["Nodes"][nodeid] = {} |
226 topology["Nodes"][nodeid]["DCFName"] = computed_value |
226 topology["Nodes"][nodeid]["DCFName"] = computed_value |
227 else: |
227 else: |
228 raise SyntaxError, "Keyname \"%s\" not recognised for section \"[%s]\""%(keyname, section_name) |
228 raise SyntaxError, _("Keyname \"%s\" not recognised for section \"[%s]\"")%(keyname, section_name) |
229 |
229 |
230 # All lines that are not empty and are neither a comment neither not a valid assignment |
230 # All lines that are not empty and are neither a comment neither not a valid assignment |
231 elif assignment.strip() != "": |
231 elif assignment.strip() != "": |
232 raise SyntaxError, "\"%s\" is not a valid CPJ line"%assignment.strip() |
232 raise SyntaxError, _("\"%s\" is not a valid CPJ line")%assignment.strip() |
233 |
233 |
234 if "Number" not in topology.keys(): |
234 if "Number" not in topology.keys(): |
235 raise SyntaxError, "\"Nodes\" keyname in \"[%s]\" section is missing"%section_name |
235 raise SyntaxError, _("\"Nodes\" keyname in \"[%s]\" section is missing")%section_name |
236 |
236 |
237 if topology["Number"] != len(topology["Nodes"]): |
237 if topology["Number"] != len(topology["Nodes"]): |
238 raise SyntaxError, "\"Nodes\" value not corresponding to number of nodes defined" |
238 raise SyntaxError, _("\"Nodes\" value not corresponding to number of nodes defined") |
239 |
239 |
240 for nodeid, node in topology["Nodes"].items(): |
240 for nodeid, node in topology["Nodes"].items(): |
241 if "Present" not in node.keys(): |
241 if "Present" not in node.keys(): |
242 raise SyntaxError, "\"Node%dPresent\" keyname in \"[%s]\" section is missing"%(nodeid, section_name) |
242 raise SyntaxError, _("\"Node%dPresent\" keyname in \"[%s]\" section is missing")%(nodeid, section_name) |
243 |
243 |
244 networks.append(topology) |
244 networks.append(topology) |
245 |
245 |
246 # In other case, there is a syntax problem into CPJ file |
246 # In other case, there is a syntax problem into CPJ file |
247 else: |
247 else: |
248 raise SyntaxError, "Section \"[%s]\" is unrecognized"%section_name |
248 raise SyntaxError, _("Section \"[%s]\" is unrecognized")%section_name |
249 |
249 |
250 return networks |
250 return networks |
251 |
251 |
252 # Function that parse an EDS file and returns a dictionary of the informations |
252 # Function that parse an EDS file and returns a dictionary of the informations |
253 def ParseEDSFile(filepath): |
253 def ParseEDSFile(filepath): |
328 if value.upper().startswith("$NODEID"): |
328 if value.upper().startswith("$NODEID"): |
329 try: |
329 try: |
330 test = int(value.upper().replace("$NODEID+", ""), 16) |
330 test = int(value.upper().replace("$NODEID+", ""), 16) |
331 computed_value = "\"%s\""%value |
331 computed_value = "\"%s\""%value |
332 except: |
332 except: |
333 raise SyntaxError, "\"%s\" is not a valid formula for attribute \"%s\" of section \"[%s]\""%(value, keyname, section_name) |
333 raise SyntaxError, _("\"%s\" is not a valid formula for attribute \"%s\" of section \"[%s]\"")%(value, keyname, section_name) |
334 # Second case, value starts with "0x", then it's an hexadecimal value |
334 # Second case, value starts with "0x", then it's an hexadecimal value |
335 elif value.startswith("0x") or value.startswith("-0x"): |
335 elif value.startswith("0x") or value.startswith("-0x"): |
336 try: |
336 try: |
337 computed_value = int(value, 16) |
337 computed_value = int(value, 16) |
338 except: |
338 except: |
339 raise SyntaxError, "\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\""%(value, keyname, section_name) |
339 raise SyntaxError, _("\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\"")%(value, keyname, section_name) |
340 elif value.isdigit() or value.startswith("-") and value[1:].isdigit(): |
340 elif value.isdigit() or value.startswith("-") and value[1:].isdigit(): |
341 # Third case, value is a number and starts with "0", then it's an octal value |
341 # Third case, value is a number and starts with "0", then it's an octal value |
342 if value.startswith("0") or value.startswith("-0"): |
342 if value.startswith("0") or value.startswith("-0"): |
343 computed_value = int(value, 8) |
343 computed_value = int(value, 8) |
344 # Forth case, value is a number and don't start with "0", then it's a decimal value |
344 # Forth case, value is a number and don't start with "0", then it's a decimal value |
352 if computed_value != "": |
352 if computed_value != "": |
353 # If entry is an index or a subindex |
353 # If entry is an index or a subindex |
354 if is_entry: |
354 if is_entry: |
355 # Verify that keyname is a possible attribute |
355 # Verify that keyname is a possible attribute |
356 if keyname.upper() not in ENTRY_ATTRIBUTES: |
356 if keyname.upper() not in ENTRY_ATTRIBUTES: |
357 raise SyntaxError, "Keyname \"%s\" not recognised for section \"[%s]\""%(keyname, section_name) |
357 raise SyntaxError, _("Keyname \"%s\" not recognised for section \"[%s]\"")%(keyname, section_name) |
358 # Verify that value is valid |
358 # Verify that value is valid |
359 elif not ENTRY_ATTRIBUTES[keyname.upper()](computed_value): |
359 elif not ENTRY_ATTRIBUTES[keyname.upper()](computed_value): |
360 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name) |
360 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name) |
361 else: |
361 else: |
362 values[keyname.upper()] = computed_value |
362 values[keyname.upper()] = computed_value |
363 else: |
363 else: |
364 values[keyname.upper()] = computed_value |
364 values[keyname.upper()] = computed_value |
365 # All lines that are not empty and are neither a comment neither not a valid assignment |
365 # All lines that are not empty and are neither a comment neither not a valid assignment |
366 elif assignment.strip() != "": |
366 elif assignment.strip() != "": |
367 raise SyntaxError, "\"%s\" is not a valid EDS line"%assignment.strip() |
367 raise SyntaxError, _("\"%s\" is not a valid EDS line")%assignment.strip() |
368 |
368 |
369 # If entry is an index or a subindex |
369 # If entry is an index or a subindex |
370 if is_entry: |
370 if is_entry: |
371 # Verify that entry has an ObjectType |
371 # Verify that entry has an ObjectType |
372 values["OBJECTTYPE"] = values.get("OBJECTTYPE", 7) |
372 values["OBJECTTYPE"] = values.get("OBJECTTYPE", 7) |
379 required = set(ENTRY_TYPES[values["OBJECTTYPE"]]["require"]) |
379 required = set(ENTRY_TYPES[values["OBJECTTYPE"]]["require"]) |
380 # Verify that parameters defined contains all the parameters required |
380 # Verify that parameters defined contains all the parameters required |
381 if not keys.issuperset(required): |
381 if not keys.issuperset(required): |
382 missing = required.difference(keys)._data.keys() |
382 missing = required.difference(keys)._data.keys() |
383 if len(missing) > 1: |
383 if len(missing) > 1: |
384 attributes = "Attributes %s are"%", ".join(["\"%s\""%attribute for attribute in missing]) |
384 attributes = _("Attributes %s are")%_(", ").join(["\"%s\""%attribute for attribute in missing]) |
385 else: |
385 else: |
386 attributes = "Attribute \"%s\" is"%missing[0] |
386 attributes = _("Attribute \"%s\" is")%missing[0] |
387 raise SyntaxError, "Error on section \"[%s]\":\n%s required for a%s entry"%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"]) |
387 raise SyntaxError, _("Error on section \"[%s]\":\n%s required for a %s entry")%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"]) |
388 # Verify that parameters defined are all in the possible parameters |
388 # Verify that parameters defined are all in the possible parameters |
389 if not keys.issubset(possible): |
389 if not keys.issubset(possible): |
390 unsupported = keys.difference(possible)._data.keys() |
390 unsupported = keys.difference(possible)._data.keys() |
391 if len(unsupported) > 1: |
391 if len(unsupported) > 1: |
392 attributes = "Attributes %s are"%", ".join(["\"%s\""%attribute for attribute in unsupported]) |
392 attributes = _("Attributes %s are")%_(", ").join(["\"%s\""%attribute for attribute in unsupported]) |
393 else: |
393 else: |
394 attributes = "Attribute \"%s\" is"%unsupported[0] |
394 attributes = _("Attribute \"%s\" is")%unsupported[0] |
395 raise SyntaxError, "Error on section \"[%s]\":\n%s unsupported for a%s entry"%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"]) |
395 raise SyntaxError, _("Error on section \"[%s]\":\n%s unsupported for a %s entry")%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"]) |
396 |
396 |
397 VerifyValue(values, section_name, "ParameterValue") |
397 VerifyValue(values, section_name, "ParameterValue") |
398 VerifyValue(values, section_name, "DefaultValue") |
398 VerifyValue(values, section_name, "DefaultValue") |
399 |
399 |
400 return eds_dict |
400 return eds_dict |
694 # First case, entry is a DOMAIN or VAR |
694 # First case, entry is a DOMAIN or VAR |
695 if values["OBJECTTYPE"] in [2, 7]: |
695 if values["OBJECTTYPE"] in [2, 7]: |
696 if values["OBJECTTYPE"] == 2: |
696 if values["OBJECTTYPE"] == 2: |
697 values["DATATYPE"] = values.get("DATATYPE", 0xF) |
697 values["DATATYPE"] = values.get("DATATYPE", 0xF) |
698 if values["DATATYPE"] != 0xF: |
698 if values["DATATYPE"] != 0xF: |
699 raise SyntaxError, "Domain entry 0x%4.4X DataType must be 0xF(DOMAIN) if defined"%entry |
699 raise SyntaxError, _("Domain entry 0x%4.4X DataType must be 0xF(DOMAIN) if defined")%entry |
700 # Add mapping for entry |
700 # Add mapping for entry |
701 Node.AddMappingEntry(entry, name = values["PARAMETERNAME"], struct = 1) |
701 Node.AddMappingEntry(entry, name = values["PARAMETERNAME"], struct = 1) |
702 # Add mapping for first subindex |
702 # Add mapping for first subindex |
703 Node.AddMappingEntry(entry, 0, values = {"name" : values["PARAMETERNAME"], |
703 Node.AddMappingEntry(entry, 0, values = {"name" : values["PARAMETERNAME"], |
704 "type" : values["DATATYPE"], |
704 "type" : values["DATATYPE"], |