--- a/PLCGenerator.py Thu Aug 17 15:43:25 2017 +0300
+++ b/PLCGenerator.py Thu Aug 17 16:26:32 2017 +0300
@@ -254,7 +254,7 @@
program = pou_program.GenerateProgram(pou)
- raise PLCGenException, _("Undefined pou type \"%s\"") % pou_type
+ raise PLCGenException(_("Undefined pou type \"%s\"") % pou_type) # Generate a POU defined and used in text
def GeneratePouProgramInText(self, text):
@@ -397,9 +397,9 @@
# Single argument if exists
- msg = _("Source signal has to be defined for single task '{a1}' in resource '{a2}.{a3}'.").\
- format(a1=task.getname(), a2=config_name, a3=resource.getname())
- raise PLCGenException, msg
+ _("Source signal has to be defined for single task '{a1}' in resource '{a2}.{a3}'."). + format(a1=task.getname(), a2=config_name, a3=resource.getname())) if single[0] == '[' and single[-1] == ']':
@@ -775,7 +775,9 @@
self.ConnectionTypes[content["value"]] = "BOOL"
connections = content["value"].getconnections()
- raise PLCGenException, _("SFC transition in POU \"%s\" must be connected.") % self.Name
+ _("SFC transition in POU \"%s\" must be connected.") % self.Name) connected = self.GetLinkedConnector(link, body)
if connected is not None and not connected in self.ConnectionTypes:
@@ -788,8 +790,9 @@
for element in body.getcontentInstances():
if isinstance(element, ConnectorClass) and element.getname() == name:
if connector is not None:
- msg = _("More than one connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1=name, a2=self.Name)
- raise PLCGenException, msg
+ _("More than one connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU"). + format(a1=name, a2=self.Name)) if connector is not None:
undefined = [instance.connectionPointOut, connector.connectionPointIn]
@@ -808,8 +811,10 @@
for connection in related:
self.ConnectionTypes[connection] = var_type
- msg = _("No connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1=name, a2=self.Name)
- raise PLCGenException, msg
+ _("No connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU"). + format(a1=name, a2=self.Name)) elif isinstance(instance, BlockClass):
block_infos = self.GetBlockType(instance.gettypeName(), "undefined")
if block_infos is not None:
@@ -831,7 +836,8 @@
if block_infos is not None:
self.ComputeBlockInputTypes(instance, block_infos, body)
- raise PLCGenException, _("No informations found for \"%s\" block") % (instance.gettypeName())
+ _("No informations found for \"%s\" block") % (instance.gettypeName())) previous_tagname = self.TagName
for action in pou.getactionList():
@@ -963,11 +969,13 @@
block_infos = self.GetBlockType(block_type)
- raise PLCGenException, _("Undefined block type \"{a1}\" in \"{a2}\" POU").format(a1=block_type, a2=self.Name)
+ _("Undefined block type \"{a1}\" in \"{a2}\" POU"). + format(a1=block_type, a2=self.Name)) self.GenerateBlock(instance, block_infos, body, None)
- raise PLCGenException, e.message
+ raise PLCGenException(e.message) elif isinstance(instance, ConnectorClass):
connector = instance.getname()
if self.ComputedConnectors.get(connector, None):
@@ -1196,9 +1204,9 @@
blockname = "{a1}({a2})".format(a1=name, a2=type)
- msg = _("No output {a1} variable found in block {a2} in POU {a3}. Connection must be broken").\
- format(a1=output_parameter, a2=blockname, a3=self.Name)
+ _("No output {a1} variable found in block {a2} in POU {a3}. Connection must be broken"). + format(a1=output_parameter, a2=blockname, a3=self.Name)) def GeneratePaths(self, connections, body, order=False, to_inout=False):
@@ -1216,12 +1224,13 @@
block_infos = self.GetBlockType(block_type)
- msg = _("Undefined block type \"{a1}\" in \"{a2}\" POU").format(a1=block_type, a2=self.Name)
- raise PLCGenException, msg
+ _("Undefined block type \"{a1}\" in \"{a2}\" POU"). + format(a1=block_type, a2=self.Name)) paths.append(str(self.GenerateBlock(next, block_infos, body, connection, order, to_inout)))
- raise PLCGenException, e.message
+ raise PLCGenException(e.message) elif isinstance(next, ContinuationClass):
computed_value = self.ComputedConnectors.get(name, None)
@@ -1232,8 +1241,9 @@
for instance in body.getcontentInstances():
if isinstance(instance, ConnectorClass) and instance.getname() == name:
if connector is not None:
- msg = _("More than one connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1=name, a2=self.Name)
- raise PLCGenException, msg
+ _("More than one connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU"). + format(a1=name, a2=self.Name)) if connector is not None:
connections = connector.connectionPointIn.getconnections()
@@ -1243,8 +1253,9 @@
self.ComputedConnectors[name] = expression
paths.append(str(expression))
- msg = _("No connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU").format(a1=name, a2=self.Name)
- raise PLCGenException, msg
+ _("No connector found corresponding to \"{a1}\" continuation in \"{a2}\" POU"). + format(a1=name, a2=self.Name)) elif isinstance(next, ContactClass):
contact_info = (self.TagName, "contact", next.getlocalId())
variable = str(self.ExtractModifier(next, [(next.getvariable(), contact_info + ("reference",))], contact_info))
@@ -1394,8 +1405,10 @@
jump_target = jump.gettargetName()
if not pou.hasstep(jump_target):
- msg = _("SFC jump in pou \"{a1}\" refers to non-existent SFC step \"{a2}\"").format(a1=pname, a2=jump_target)
- raise PLCGenException, msg
+ _("SFC jump in pou \"{a1}\" refers to non-existent SFC step \"{a2}\""). + format(a1=pname, a2=jump_target)) if jump.connectionPointIn is not None:
connections = jump.connectionPointIn.getconnections()
@@ -1520,7 +1533,9 @@
self.SFCComputedBlocks += self.Program
if not "content" in transition_infos:
- raise PLCGenException, _("Transition \"%s\" body must contain an output variable or coil referring to its name") % transitionValues["value"]
+ _("Transition \"%s\" body must contain an output variable or coil referring to its name") + % transitionValues["value"]) self.TagName = previous_tagname
elif transitionValues["type"] == "connection":
@@ -1600,9 +1615,9 @@
elif len(transition_infos["from"]) == 1:
self.Program += transition_infos["from"][0]
- msg = _("Transition with content \"{a1}\" not connected to a previous step in \"{a2}\" POU").\
- format(a1=transition_infos["content"], a2=self.Name)
- raise PLCGenException, msg
+ _("Transition with content \"{a1}\" not connected to a previous step in \"{a2}\" POU"). + format(a1=transition_infos["content"], a2=self.Name)) self.Program += [(" TO ", ())]
if len(transition_infos["to"]) > 1:
self.Program += [("(", ())]
@@ -1611,9 +1626,9 @@
elif len(transition_infos["to"]) == 1:
self.Program += transition_infos["to"][0]
- msg = _("Transition with content \"{a1}\" not connected to a next step in \"{a2}\" POU").\
- format(a1=transition_infos["content"], a2=self.Name)
- raise PLCGenException, msg
+ _("Transition with content \"{a1}\" not connected to a next step in \"{a2}\" POU"). + format(a1=transition_infos["content"], a2=self.Name)) self.Program += transition_infos["content"]
self.Program += [("%sEND_TRANSITION\n\n" % self.CurrentIndent, ())]
for [(step_name, step_infos)] in transition_infos["to"]:
@@ -1631,9 +1646,9 @@
(self.ReturnType, (self.TagName, "return"))]
if len(self.Interface) == 0:
- raise PLCGenException, _("No variable defined in \"%s\" POU") % self.Name
+ raise PLCGenException(_("No variable defined in \"%s\" POU") % self.Name) if len(self.Program) == 0:
- raise PLCGenException, _("No body defined in \"%s\" POU") % self.Name
+ raise PLCGenException(_("No body defined in \"%s\" POU") % self.Name) for list_type, option, located, variables in self.Interface:
variable_type = errorVarTypes.get(list_type, "var_local")
--- a/canfestival/config_utils.py Thu Aug 17 15:43:25 2017 +0300
+++ b/canfestival/config_utils.py Thu Aug 17 16:26:32 2017 +0300
@@ -348,13 +348,13 @@
if name in self.IECLocations:
if self.IECLocations[name]["type"] != COlocationtype:
- raise PDOmappingException, _("Type conflict for location \"%s\"") % name
+ raise PDOmappingException(_("Type conflict for location \"%s\"") % name) # Get only the part of the location that concern this node
loc = location["LOC"][len(current_location):]
# loc correspond to (ID, INDEX, SUBINDEX [,BIT])
if len(loc) not in (2, 3, 4):
- raise PDOmappingException, _("Bad location size : %s") % str(loc)
+ raise PDOmappingException(_("Bad location size : %s") % str(loc)) @@ -367,7 +367,9 @@
# Check Id is in slave node list
if nodeid not in self.NodeList.SlaveNodes.keys():
- raise PDOmappingException, _("Non existing node ID : {a1} (variable {a2})").format(a1=nodeid, a2=name)
+ raise PDOmappingException( + _("Non existing node ID : {a1} (variable {a2})"). + format(a1=nodeid, a2=name)) # Get the model for this node (made from EDS)
node = self.NodeList.SlaveNodes[nodeid]["Node"]
@@ -376,7 +378,7 @@
if not node.IsEntry(index, subindex):
msg = _("No such index/subindex ({a1},{a2}) in ID : {a3} (variable {a4})").\
format(a1="%x" % index, a2="%x" % subindex, a3=nodeid, a4=name)
- raise PDOmappingException, msg
+ raise PDOmappingException(msg) subentry_infos = node.GetSubentryInfos(index, subindex)
@@ -386,15 +388,19 @@
if sizelocation == "X" and len(loc) > 3:
elif sizelocation != "X" and len(loc) > 3:
- msg = _("Cannot set bit offset for non bool '{a1}' variable (ID:{a2},Idx:{a3},sIdx:{a4}))").\
- format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex)
- raise PDOmappingException, msg
+ raise PDOmappingException( + _("Cannot set bit offset for non bool '{a1}' variable (ID:{a2},Idx:{a3},sIdx:{a4}))"). + format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex)) if location["IEC_TYPE"] != "BOOL" and subentry_infos["type"] != COlocationtype:
- raise PDOmappingException, _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\"").\
- format(a1=location["IEC_TYPE"], a2=COlocationtype, a3=subentry_infos["type"], a4=name)
+ raise PDOmappingException( + _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\""). + format(a1=location["IEC_TYPE"], + a3=subentry_infos["type"], typeinfos = node.GetEntryInfos(COlocationtype)
self.IECLocations[name] = {
@@ -408,8 +414,9 @@
"sizelocation": sizelocation
- raise PDOmappingException, _("Not PDO mappable variable : '{a1}' (ID:{a2},Idx:{a3},sIdx:{a4}))").\
- format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex)
+ raise PDOmappingException( + _("Not PDO mappable variable : '{a1}' (ID:{a2},Idx:{a3},sIdx:{a4}))"). + format(a1=name, a2=nodeid, a3="%x" % index, a4="%x" % subindex)) #-------------------------------------------------------------------------------
# Search for locations already mapped
@@ -481,7 +488,8 @@
result = self.GetEmptyPDO(nodeid, pdotype)
- raise PDOmappingException, _("Unable to define PDO mapping for node %02x") % nodeid
+ raise PDOmappingException( + _("Unable to define PDO mapping for node %02x") % nodeid) pdoindex, pdocobid, pdonbparams = result
for name, loc_infos in locations[pdotype]:
pdosize += loc_infos["size"]
@@ -495,7 +503,8 @@
pdomapping = [(name, loc_infos)]
result = self.GetEmptyPDO(nodeid, pdotype, pdoindex + 1)
- raise PDOmappingException, _("Unable to define PDO mapping for node %02x") % nodeid
+ raise PDOmappingException( + _("Unable to define PDO mapping for node %02x") % nodeid) pdoindex, pdocobid, pdonbparams = result
pdomapping.append((name, loc_infos))
@@ -645,13 +654,13 @@
if IECLocations[name] != COlocationtype:
- raise PDOmappingException, _("Type conflict for location \"%s\"") % name
+ raise PDOmappingException(_("Type conflict for location \"%s\"") % name) # Get only the part of the location that concern this node
loc = location["LOC"][len(current_location):]
# loc correspond to (ID, INDEX, SUBINDEX [,BIT])
if len(loc) not in (2, 3, 4):
- raise PDOmappingException, _("Bad location size : %s") % str(loc)
+ raise PDOmappingException(_("Bad location size : %s") % str(loc)) @@ -660,14 +669,19 @@
# Extract and check index and subindex
if not slave.IsEntry(index, subindex):
- raise PDOmappingException, _("No such index/subindex ({a1},{a2}) (variable {a3})").\
- format(a1="%x" % index, a2="%x" % subindex, a3=name)
+ raise PDOmappingException( + _("No such index/subindex ({a1},{a2}) (variable {a3})"). + format(a1="%x" % index, a2="%x" % subindex, a3=name)) subentry_infos = slave.GetSubentryInfos(index, subindex)
if subentry_infos["type"] != COlocationtype:
- raise PDOmappingException, _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\"").\
- format(a1=location["IEC_TYPE"], a2=COlocationtype, a3=subentry_infos["type"], a4=name)
+ raise PDOmappingException( + _("Invalid type \"{a1}\"-> {a2} != {a3} for location \"{a4}\""). + format(a1=location["IEC_TYPE"], + a3=subentry_infos["type"], IECLocations[name] = COlocationtype
pointers[(index, subindex)] = name
--- a/plcopen/plcopen.py Thu Aug 17 15:43:25 2017 +0300
+++ b/plcopen/plcopen.py Thu Aug 17 16:26:32 2017 +0300
@@ -450,7 +450,7 @@
def appenddataType(self, name):
if self.getdataType(name) is not None:
- raise ValueError, "\"%s\" Data Type already exists !!!" % name
+ raise ValueError("\"%s\" Data Type already exists !!!" % name) self.types.appenddataTypeElement(name)
setattr(cls, "appenddataType", appenddataType)
@@ -505,7 +505,7 @@
def addconfiguration(self, name):
if self.getconfiguration(name) is not None:
- raise ValueError, _("\"%s\" configuration already exists !!!") % name
+ raise ValueError(_("\"%s\" configuration already exists !!!") % name) new_configuration = PLCOpenParser.CreateElement("configuration", "configurations")
new_configuration.setname(name)
self.instances.configurations.appendconfiguration(new_configuration)
@@ -514,7 +514,7 @@
def removeconfiguration(self, name):
configuration = self.getconfiguration(name)
if configuration is None:
- raise ValueError, ("\"%s\" configuration doesn't exist !!!") % name
+ raise ValueError(_("\"%s\" configuration doesn't exist !!!") % name) self.instances.configurations.remove(configuration)
setattr(cls, "removeconfiguration", removeconfiguration)
@@ -530,8 +530,10 @@
def addconfigurationResource(self, config_name, name):
if self.getconfigurationResource(config_name, name) is not None:
- msg = _("\"{a1}\" resource already exists in \"{a2}\" configuration !!!").format(a1=name, a2=config_name)
+ _("\"{a1}\" resource already exists in \"{a2}\" configuration !!!"). + format(a1=name, a2=config_name)) configuration = self.getconfiguration(config_name)
if configuration is not None:
new_resource = PLCOpenParser.CreateElement("resource", "configuration")
@@ -548,8 +550,10 @@
configuration.remove(resource)
- msg = _("\"{a1}\" resource doesn't exist in \"{a2}\" configuration !!!").format(a1=name, a2=config_name)
+ _("\"{a1}\" resource doesn't exist in \"{a2}\" configuration !!!"). + format(a1=name, a2=config_name)) setattr(cls, "removeconfigurationResource", removeconfigurationResource)
def updateElementName(self, old_name, new_name):
@@ -928,7 +932,7 @@
- raise ValueError, _("\"%s\" Data Type doesn't exist !!!") % name
+ raise ValueError(_("\"%s\" Data Type doesn't exist !!!") % name) setattr(cls, "removedataTypeElement", removedataTypeElement)
def getpouElements(self):
@@ -946,7 +950,7 @@
def appendpouElement(self, name, pou_type, body_type):
for element in self.pous.getpou():
if TextMatched(element.getname(), name):
- raise ValueError, _("\"%s\" POU already exists !!!") % name
+ raise ValueError(_("\"%s\" POU already exists !!!") % name) new_pou = PLCOpenParser.CreateElement("pou", "pous")
self.pous.appendpou(new_pou)
@@ -967,7 +971,7 @@
- raise ValueError, _("\"%s\" POU doesn't exist !!!") % name
+ raise ValueError(_("\"%s\" POU doesn't exist !!!") % name) setattr(cls, "removepouElement", removepouElement)
def Search(self, criteria, parent_infos=[]):
@@ -1153,7 +1157,7 @@
if body_type in ["IL", "ST", "LD", "FBD", "SFC"]:
self.body[0].setcontent(PLCOpenParser.CreateElement(body_type, "body"))
- raise ValueError, "%s isn't a valid body type!" % type
+ raise ValueError("%s isn't a valid body type!" % type) setattr(cls, "setbodyType", setbodyType)
@@ -1373,7 +1377,7 @@
- raise ValueError, _("Transition with name %s doesn't exist!") % name
+ raise ValueError(_("Transition with name %s doesn't exist!") % name) setattr(cls, "removetransition", removetransition)
def addaction(self, name, body_type):
@@ -1414,7 +1418,7 @@
- raise ValueError, _("Action with name %s doesn't exist!") % name
+ raise ValueError(_("Action with name %s doesn't exist!") % name) setattr(cls, "removeaction", removeaction)
def updateElementName(self, old_name, new_name):
@@ -1507,7 +1511,7 @@
if body_type in ["IL", "ST", "LD", "FBD", "SFC"]:
self.body.setcontent(PLCOpenParser.CreateElement(body_type, "body"))
- raise ValueError, "%s isn't a valid body type!" % type
+ raise ValueError("%s isn't a valid body type!" % type) @@ -1656,7 +1660,7 @@
element.setexecutionOrderId(0)
self.checkedBlocksDict.clear()
- raise TypeError, _("Can only generate execution order on FBD networks!")
+ raise TypeError(_("Can only generate execution order on FBD networks!")) setattr(cls, "resetexecutionOrder", resetexecutionOrder)
def compileexecutionOrder(self):
@@ -1670,7 +1674,7 @@
self.compileelementExecutionOrder(connections[0])
element.setexecutionOrderId(self.getnewExecutionOrderId())
- raise TypeError, _("Can only generate execution order on FBD networks!")
+ raise TypeError(_("Can only generate execution order on FBD networks!")) setattr(cls, "compileexecutionOrder", compileexecutionOrder)
def compileelementExecutionOrder(self, link):
@@ -1694,7 +1698,7 @@
if connections and len(connections) == 1:
self.compileelementExecutionOrder(connections[0])
- raise TypeError, _("Can only generate execution order on FBD networks!")
+ raise TypeError(_("Can only generate execution order on FBD networks!")) setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder)
def setelementExecutionOrder(self, instance, new_executionOrder):
@@ -1710,21 +1714,21 @@
element.setexecutionOrderId(element_executionOrder + 1)
instance.setexecutionOrderId(new_executionOrder)
- raise TypeError, _("Can only generate execution order on FBD networks!")
+ raise TypeError(_("Can only generate execution order on FBD networks!")) setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
def appendcontentInstance(self, instance):
if self.content.getLocalTag() in ["LD", "FBD", "SFC"]:
self.content.appendcontent(instance)
- raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
+ raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) setattr(cls, "appendcontentInstance", appendcontentInstance)
def getcontentInstances(self):
if self.content.getLocalTag() in ["LD", "FBD", "SFC"]:
return self.content.getcontent()
- raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
+ raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) setattr(cls, "getcontentInstances", getcontentInstances)
instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]")
@@ -1737,7 +1741,7 @@
- raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
+ raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) setattr(cls, "getcontentInstance", getcontentInstance)
def getcontentInstancesIds(self):
@@ -1745,7 +1749,7 @@
return OrderedDict([(instance.getlocalId(), True)
for instance in self.content])
- raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
+ raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) setattr(cls, "getcontentInstancesIds", getcontentInstancesIds)
def getcontentInstanceByName(self, name):
@@ -1755,7 +1759,7 @@
- raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
+ raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) setattr(cls, "getcontentInstanceByName", getcontentInstanceByName)
def removecontentInstance(self, local_id):
@@ -1764,30 +1768,30 @@
self.content.remove(instance[0])
- raise ValueError, _("Instance with id %d doesn't exist!") % id
+ raise ValueError(_("Instance with id %d doesn't exist!") % id) - raise TypeError, "%s body don't have instances!" % self.content.getLocalTag()
+ raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) setattr(cls, "removecontentInstance", removecontentInstance)
if self.content.getLocalTag() in ["IL", "ST"]:
self.content.setanyText(text)
- raise TypeError, _("%s body don't have text!") % self.content.getLocalTag()
+ raise TypeError(_("%s body don't have text!") % self.content.getLocalTag()) setattr(cls, "settext", settext)
if self.content.getLocalTag() in ["IL", "ST"]:
return self.content.getanyText()
- raise TypeError, _("%s body don't have text!") % self.content.getLocalTag()
+ raise TypeError(_("%s body don't have text!") % self.content.getLocalTag()) setattr(cls, "gettext", gettext)
def hasblock(self, block_type):
if self.content.getLocalTag() in ["IL", "ST"]:
return self.content.hasblock(block_type)
- raise TypeError, _("%s body don't have text!") % self.content.getLocalTag()
+ raise TypeError(_("%s body don't have text!") % self.content.getLocalTag()) setattr(cls, "hasblock", hasblock)
def updateElementName(self, old_name, new_name):
@@ -2521,7 +2525,7 @@
- raise ValueError, _("\"%s\" is an invalid value!") % value
+ raise ValueError(_("\"%s\" is an invalid value!") % value)