--- a/objdictgen/eds_utils.py Mon Jul 20 16:11:20 2009 +0200
+++ b/objdictgen/eds_utils.py Mon Jul 27 16:29:59 2009 +0200
@@ -174,7 +174,7 @@
try:
computed_value = int(value, 16)
except:
- raise SyntaxError, "\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\""%(value, keyname, section_name)
+ raise SyntaxError, _("\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
elif value.isdigit() or value.startswith("-") and value[1:].isdigit():
# Second case, value is a number and starts with "0" or "-0", then it's an octal value
if value.startswith("0") or value.startswith("-0"):
@@ -193,59 +193,59 @@
if keyname.upper() == "NETNAME":
if not is_string(computed_value):
- raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
+ raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
topology["Name"] = computed_value
elif keyname.upper() == "NODES":
if not is_integer(computed_value):
- raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
+ raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
topology["Number"] = computed_value
elif keyname.upper() == "EDSBASENAME":
if not is_string(computed_value):
- raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
+ raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
topology["Path"] = computed_value
elif nodepresent_result:
if not is_boolean(computed_value):
- raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
+ raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
nodeid = int(nodepresent_result.groups()[0])
if nodeid not in topology["Nodes"].keys():
topology["Nodes"][nodeid] = {}
topology["Nodes"][nodeid]["Present"] = computed_value
elif nodename_result:
if not is_string(value):
- raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
+ raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
nodeid = int(nodename_result.groups()[0])
if nodeid not in topology["Nodes"].keys():
topology["Nodes"][nodeid] = {}
topology["Nodes"][nodeid]["Name"] = computed_value
elif nodedcfname_result:
if not is_string(computed_value):
- raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
+ raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
nodeid = int(nodedcfname_result.groups()[0])
if nodeid not in topology["Nodes"].keys():
topology["Nodes"][nodeid] = {}
topology["Nodes"][nodeid]["DCFName"] = computed_value
else:
- raise SyntaxError, "Keyname \"%s\" not recognised for section \"[%s]\""%(keyname, section_name)
+ raise SyntaxError, _("Keyname \"%s\" not recognised for section \"[%s]\"")%(keyname, section_name)
# All lines that are not empty and are neither a comment neither not a valid assignment
elif assignment.strip() != "":
- raise SyntaxError, "\"%s\" is not a valid CPJ line"%assignment.strip()
+ raise SyntaxError, _("\"%s\" is not a valid CPJ line")%assignment.strip()
if "Number" not in topology.keys():
- raise SyntaxError, "\"Nodes\" keyname in \"[%s]\" section is missing"%section_name
+ raise SyntaxError, _("\"Nodes\" keyname in \"[%s]\" section is missing")%section_name
if topology["Number"] != len(topology["Nodes"]):
- raise SyntaxError, "\"Nodes\" value not corresponding to number of nodes defined"
+ raise SyntaxError, _("\"Nodes\" value not corresponding to number of nodes defined")
for nodeid, node in topology["Nodes"].items():
if "Present" not in node.keys():
- raise SyntaxError, "\"Node%dPresent\" keyname in \"[%s]\" section is missing"%(nodeid, section_name)
+ raise SyntaxError, _("\"Node%dPresent\" keyname in \"[%s]\" section is missing")%(nodeid, section_name)
networks.append(topology)
# In other case, there is a syntax problem into CPJ file
else:
- raise SyntaxError, "Section \"[%s]\" is unrecognized"%section_name
+ raise SyntaxError, _("Section \"[%s]\" is unrecognized")%section_name
return networks
@@ -275,7 +275,7 @@
if section_name.upper() not in eds_dict:
eds_dict[section_name.upper()] = values
else:
- raise SyntaxError, "\"[%s]\" section is defined two times"%section_name
+ raise SyntaxError, _("\"[%s]\" section is defined two times")%section_name
# Second case, section name is an index name
elif index_result:
# Extract index number
@@ -288,7 +288,7 @@
values["subindexes"] = eds_dict[index]["subindexes"]
eds_dict[index] = values
else:
- raise SyntaxError, "\"[%s]\" section is defined two times"%section_name
+ raise SyntaxError, _("\"[%s]\" section is defined two times")%section_name
is_entry = True
# Third case, section name is a subindex name
elif subindex_result:
@@ -301,14 +301,14 @@
if subindex not in eds_dict[index]["subindexes"]:
eds_dict[index]["subindexes"][subindex] = values
else:
- raise SyntaxError, "\"[%s]\" section is defined two times"%section_name
+ raise SyntaxError, _("\"[%s]\" section is defined two times")%section_name
is_entry = True
# Third case, section name is a subindex name
elif index_objectlinks_result:
pass
# In any other case, there is a syntax problem into EDS file
else:
- raise SyntaxError, "Section \"[%s]\" is unrecognized"%section_name
+ raise SyntaxError, _("Section \"[%s]\" is unrecognized")%section_name
for assignment in assignments:
# Escape any comment
@@ -330,13 +330,13 @@
test = int(value.upper().replace("$NODEID+", ""), 16)
computed_value = "\"%s\""%value
except:
- raise SyntaxError, "\"%s\" is not a valid formula for attribute \"%s\" of section \"[%s]\""%(value, keyname, section_name)
+ raise SyntaxError, _("\"%s\" is not a valid formula for attribute \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
# Second case, value starts with "0x", then it's an hexadecimal value
elif value.startswith("0x") or value.startswith("-0x"):
try:
computed_value = int(value, 16)
except:
- raise SyntaxError, "\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\""%(value, keyname, section_name)
+ raise SyntaxError, _("\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
elif value.isdigit() or value.startswith("-") and value[1:].isdigit():
# Third case, value is a number and starts with "0", then it's an octal value
if value.startswith("0") or value.startswith("-0"):
@@ -354,17 +354,17 @@
if is_entry:
# Verify that keyname is a possible attribute
if keyname.upper() not in ENTRY_ATTRIBUTES:
- raise SyntaxError, "Keyname \"%s\" not recognised for section \"[%s]\""%(keyname, section_name)
+ raise SyntaxError, _("Keyname \"%s\" not recognised for section \"[%s]\"")%(keyname, section_name)
# Verify that value is valid
elif not ENTRY_ATTRIBUTES[keyname.upper()](computed_value):
- raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
+ raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
else:
values[keyname.upper()] = computed_value
else:
values[keyname.upper()] = computed_value
# All lines that are not empty and are neither a comment neither not a valid assignment
elif assignment.strip() != "":
- raise SyntaxError, "\"%s\" is not a valid EDS line"%assignment.strip()
+ raise SyntaxError, _("\"%s\" is not a valid EDS line")%assignment.strip()
# If entry is an index or a subindex
if is_entry:
@@ -381,18 +381,18 @@
if not keys.issuperset(required):
missing = required.difference(keys)._data.keys()
if len(missing) > 1:
- attributes = "Attributes %s are"%", ".join(["\"%s\""%attribute for attribute in missing])
+ attributes = _("Attributes %s are")%_(", ").join(["\"%s\""%attribute for attribute in missing])
else:
- attributes = "Attribute \"%s\" is"%missing[0]
- raise SyntaxError, "Error on section \"[%s]\":\n%s required for a%s entry"%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"])
+ attributes = _("Attribute \"%s\" is")%missing[0]
+ raise SyntaxError, _("Error on section \"[%s]\":\n%s required for a %s entry")%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"])
# Verify that parameters defined are all in the possible parameters
if not keys.issubset(possible):
unsupported = keys.difference(possible)._data.keys()
if len(unsupported) > 1:
- attributes = "Attributes %s are"%", ".join(["\"%s\""%attribute for attribute in unsupported])
+ attributes = _("Attributes %s are")%_(", ").join(["\"%s\""%attribute for attribute in unsupported])
else:
- attributes = "Attribute \"%s\" is"%unsupported[0]
- raise SyntaxError, "Error on section \"[%s]\":\n%s unsupported for a%s entry"%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"])
+ attributes = _("Attribute \"%s\" is")%unsupported[0]
+ raise SyntaxError, _("Error on section \"[%s]\":\n%s unsupported for a %s entry")%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"])
VerifyValue(values, section_name, "ParameterValue")
VerifyValue(values, section_name, "DefaultValue")
@@ -412,7 +412,7 @@
if not isinstance(values[param.upper()], (IntType, LongType)) and values[param.upper()].upper().find("$NODEID") == -1:
raise
except:
- raise SyntaxError, "Error on section \"[%s]\":\n%s incompatible with DataType"%(section_name, param)
+ raise SyntaxError, _("Error on section \"[%s]\":\n%s incompatible with DataType")%(section_name, param)
# Function that write an EDS file after generate it's content
@@ -637,7 +637,7 @@
WriteFile(filepath, content)
return None
except ValueError, message:
- return "Unable to generate EDS file\n%s"%message
+ return _("Unable to generate EDS file\n%s")%message
# Function that generate the CPJ file content for the nodelist
def GenerateCPJContent(nodelist):
@@ -681,7 +681,7 @@
except:
pass
# Read all entries in the EDS dictionary
- for entry, values in eds_dict.items():
+ for entry, values in eds_dict.iteritems():
# All sections with a name in keynames are escaped
if entry in SECTION_KEYNAMES:
pass
@@ -696,7 +696,7 @@
if values["OBJECTTYPE"] == 2:
values["DATATYPE"] = values.get("DATATYPE", 0xF)
if values["DATATYPE"] != 0xF:
- raise SyntaxError, "Domain entry 0x%4.4X DataType must be 0xF(DOMAIN) if defined"%entry
+ raise SyntaxError, _("Domain entry 0x%4.4X DataType must be 0xF(DOMAIN) if defined")%entry
# Add mapping for entry
Node.AddMappingEntry(entry, name = values["PARAMETERNAME"], struct = 1)
# Add mapping for first subindex
@@ -774,10 +774,10 @@
value = GetDefaultValue(Node, entry, subindex)
Node.AddEntry(entry, subindex, value)
else:
- raise SyntaxError, "Array or Record entry 0x%4.4X must have a \"SubNumber\" attribute"%entry
+ raise SyntaxError, _("Array or Record entry 0x%4.4X must have a \"SubNumber\" attribute")%entry
return Node
except SyntaxError, message:
- return "Unable to import EDS file\n%s"%message
+ return _("Unable to import EDS file\n%s")%message
#-------------------------------------------------------------------------------
# Main Function