Use python 3 compatible exception syntax everywhere
--- a/Beremiz_service.py Tue Oct 02 17:18:09 2018 +0300
+++ b/Beremiz_service.py Tue Oct 02 18:08:49 2018 +0300
@@ -70,7 +70,7 @@
opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:w:c:e:s:h", ["help", "version"])
-except getopt.GetoptError, err:
+except getopt.GetoptError as err: # print help information and exit:
print(str(err)) # will print something like "option -a not recognized"
--- a/CodeFileTreeNode.py Tue Oct 02 17:18:09 2018 +0300
+++ b/CodeFileTreeNode.py Tue Oct 02 18:08:49 2018 +0300
@@ -123,7 +123,7 @@
(fname, lnum, src) = ((self.CODEFILE_NAME,) + error)
self.GetCTRoot().logger.write_warning(XSDSchemaErrorMessage.format(a1=fname, a2=lnum, a3=src))
self.CreateCodeFileBuffer(True)
+ except Exception as exc: msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=self.CTNName(), a2=unicode(exc))
self.GetCTRoot().logger.write_error(msg)
self.GetCTRoot().logger.write_error(traceback.format_exc())
--- a/ConfigTreeNode.py Tue Oct 02 17:18:09 2018 +0300
+++ b/ConfigTreeNode.py Tue Oct 02 18:08:49 2018 +0300
@@ -626,7 +626,7 @@
self.GetCTRoot().logger.write_warning(XSDSchemaErrorMessage.format(a1=fname, a2=lnum, a3=src))
self.MandatoryParams = ("BaseParams", self.BaseParams)
+ except Exception as exc: msg = _("Couldn't load confnode base parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=unicode(exc))
self.GetCTRoot().logger.write_error(msg)
self.GetCTRoot().logger.write_error(traceback.format_exc())
@@ -643,7 +643,7 @@
self.CTNParams = (name, obj)
+ except Exception as exc: msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=unicode(exc))
self.GetCTRoot().logger.write_error(msg)
self.GetCTRoot().logger.write_error(traceback.format_exc())
@@ -656,7 +656,7 @@
pname, ptype = CTNDir.split(NameTypeSeparator)
self.CTNAddChild(pname, ptype)
+ except Exception as exc: msg = _("Could not add child \"{a1}\", type {a2} :\n{a3}\n").format(a1=pname, a2=ptype, a3=unicode(exc))
self.GetCTRoot().logger.write_error(msg)
self.GetCTRoot().logger.write_error(traceback.format_exc())
--- a/PLCControler.py Tue Oct 02 17:18:09 2018 +0300
+++ b/PLCControler.py Tue Oct 02 18:08:49 2018 +0300
@@ -460,7 +460,7 @@
self.ProgramFilePath = filepath
return program_text, errors, warnings
- except PLCGenException, ex:
+ except PLCGenException as ex: errors.append(ex.message)
errors.append("No project opened")
--- a/PLCGenerator.py Tue Oct 02 17:18:09 2018 +0300
+++ b/PLCGenerator.py Tue Oct 02 18:08:49 2018 +0300
@@ -1024,7 +1024,7 @@
format(a1=block_type, a2=self.Name))
self.GenerateBlock(instance, block_infos, body, None)
+ except ValueError as e: raise PLCGenException(e.message)
elif isinstance(instance, ConnectorClass):
connector = instance.getname()
@@ -1302,7 +1302,7 @@
format(a1=block_type, a2=self.Name))
paths.append(str(self.GenerateBlock(next, block_infos, body, connection, order, to_inout)))
+ except ValueError as e: raise PLCGenException(e.message)
elif isinstance(next, ContinuationClass):
--- a/ProjectController.py Tue Oct 02 17:18:09 2018 +0300
+++ b/ProjectController.py Tue Oct 02 18:08:49 2018 +0300
@@ -799,7 +799,7 @@
status, result, err_result = ProcessLogger(self.logger, buildcmd,
self.logger.write_error(buildcmd + "\n")
self.logger.write_error(repr(e) + "\n")
--- a/canfestival/canfestival.py Tue Oct 02 17:18:09 2018 +0300
+++ b/canfestival/canfestival.py Tue Oct 02 18:08:49 2018 +0300
@@ -451,7 +451,7 @@
# Create a new copy of the model with DCF loaded with PDO mappings for desired location
master, pointers = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs(), "OD_%s" % prefix)
- except config_utils.PDOmappingException, e:
+ except config_utils.PDOmappingException as e: raise Exception(e.message)
res = gen_cfile.GenerateFile(Gen_OD_path, master, pointers)
--- a/canfestival/config_utils.py Tue Oct 02 17:18:09 2018 +0300
+++ b/canfestival/config_utils.py Tue Oct 02 18:08:49 2018 +0300
@@ -765,7 +765,7 @@
# Generate MasterNode configuration
masternode, pointedvariables = GenerateConciseDCF(locations, (0, 1), nodelist, True, "TestNode")
- except ValueError, message:
+ except ValueError as message: print("%s\nTest Failed!" % message)
--- a/connectors/PYRO/__init__.py Tue Oct 02 17:18:09 2018 +0300
+++ b/connectors/PYRO/__init__.py Tue Oct 02 18:08:49 2018 +0300
@@ -120,12 +120,12 @@
def catcher_func(*args, **kwargs):
return func(*args, **kwargs)
- except Pyro.errors.ConnectionClosedError, e:
+ except Pyro.errors.ConnectionClosedError as e: confnodesroot.logger.write_error(_("Connection lost!\n"))
confnodesroot._SetConnector(None)
- except Pyro.errors.ProtocolError, e:
+ except Pyro.errors.ProtocolError as e: confnodesroot.logger.write_error(_("Pyro exception: %s\n") % e)
# confnodesroot.logger.write_error(traceback.format_exc())
errmess = ''.join(Pyro.util.getPyroTraceback(e))
confnodesroot.logger.write_error(errmess + "\n")
--- a/etherlab/EthercatMaster.py Tue Oct 02 17:18:09 2018 +0300
+++ b/etherlab/EthercatMaster.py Tue Oct 02 18:08:49 2018 +0300
@@ -249,7 +249,7 @@
EtherCATConfigParser.LoadXMLString(config_xmlfile.read())
@@ -270,7 +270,7 @@
ProcessVariablesParser.LoadXMLString(process_xmlfile.read())
--- a/etherlab/etherlab.py Tue Oct 02 17:18:09 2018 +0300
+++ b/etherlab/etherlab.py Tue Oct 02 18:08:49 2018 +0300
@@ -226,7 +226,7 @@
self.GetCTRoot().logger.write_warning(
XSDSchemaErrorMessage % (filepath + error))
+ except Exception as exc: self.modules_infos, error = None, unicode(exc)
--- a/i18n/mki18n.py Tue Oct 02 17:18:09 2018 +0300
+++ b/i18n/mki18n.py Tue Oct 02 18:08:49 2018 +0300
@@ -486,7 +486,7 @@
optionList, pargs = getopt.getopt(sys.argv[1:], validOptions, validLongOptions)
- except getopt.GetoptError, e:
+ except getopt.GetoptError as e: for (opt, val) in optionList:
@@ -512,7 +512,7 @@
makePO(appDirPath, option['domain'], option['verbose'])
printUsage(e[1] + '\n You must write a file app.fil that contains the list of all files to parse.')
makeMO(appDirPath, option['moTarget'], option['domain'], option['verbose'], option['forceEnglish'])
--- a/plcopen/plcopen.py Tue Oct 02 17:18:09 2018 +0300
+++ b/plcopen/plcopen.py Tue Oct 02 18:08:49 2018 +0300
@@ -298,7 +298,7 @@
--- a/py_ext/PythonFileCTNMixin.py Tue Oct 02 17:18:09 2018 +0300
+++ b/py_ext/PythonFileCTNMixin.py Tue Oct 02 18:08:49 2018 +0300
@@ -73,7 +73,7 @@
self.CreateCodeFileBuffer(False)
+ except Exception as exc: --- a/runtime/PLCObject.py Tue Oct 02 17:18:09 2018 +0300
+++ b/runtime/PLCObject.py Tue Oct 02 18:08:49 2018 +0300
@@ -497,7 +497,7 @@
self.python_runtime_vars["FBID"] = None
res = "#EXCEPTION : "+str(e)
self.LogMessage(1, ('PyEval@0x%x(Code="%s") Exception "%s"') % (FBID, cmd, str(e)))
--- a/runtime/WampClient.py Tue Oct 02 17:18:09 2018 +0300
+++ b/runtime/WampClient.py Tue Oct 02 18:08:49 2018 +0300
@@ -157,7 +157,7 @@
self.setProtocolOptions(**protocolOptions)
print(_("Custom protocol options failed :"), e)
--- a/svgui/pyjs/build.py Tue Oct 02 17:18:09 2018 +0300
+++ b/svgui/pyjs/build.py Tue Oct 02 18:08:49 2018 +0300
@@ -99,7 +99,7 @@
copytree_exists(srcname, dstname, symlinks)
shutil.copy2(srcname, dstname)
- except (IOError, os.error), why:
+ except (IOError, os.error) as why: errors.append((srcname, dstname, why))
@@ -184,7 +184,7 @@
print("Creating output directory")
- except StandardError, e:
+ except StandardError as e: print("Exception creating output directory %s: %s" % (output, e), file=sys.stderr)