cleanup etherlab: pep8, E722 do not use bare except
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 28 Sep 2018 17:14:42 +0300
changeset 2353 8f1a2846b2f5
parent 2352 fec90dc70e16
child 2354 9460872f1440
cleanup etherlab: pep8, E722 do not use bare except
bacnet/bacnet.py
etherlab/CommonEtherCATFunction.py
etherlab/ConfigEditor.py
etherlab/EtherCATManagementEditor.py
etherlab/EthercatMaster.py
etherlab/EthercatSlave.py
etherlab/runtime_etherlab.py
--- a/bacnet/bacnet.py	Fri Sep 28 13:21:06 2018 +0300
+++ b/bacnet/bacnet.py	Fri Sep 28 17:14:42 2018 +0300
@@ -416,7 +416,7 @@
             self.ObjTables["MSO_Obj"].ChangesToSave = False
             self.ObjTables["MSI_Obj"].ChangesToSave = False
             return True
-        except:
+        except Exception:
             return _("Unable to save to file \"%s\"!") % filepath
 
     def LoadFromFile(self, filepath):
@@ -426,7 +426,7 @@
             self.ObjTablesData = pickle.load(fd)
             fd.close()
             return True
-        except:
+        except Exception:
             return _("Unable to load file \"%s\"!") % filepath
 
     def _ExportBacnetSlave(self):
--- a/etherlab/CommonEtherCATFunction.py	Fri Sep 28 13:21:06 2018 +0300
+++ b/etherlab/CommonEtherCATFunction.py	Fri Sep 28 17:14:42 2018 +0300
@@ -21,12 +21,12 @@
     """
     try:
         return int(value)
-    except:
+    except Exception:
         pass
     try:
         return int(value.replace("#", "0"), 16)
         
-    except:
+    except Exception:
         raise ValueError, "Invalid value for HexDecValue \"%s\"" % value
 
 def ExtractName(names, default=None):
--- a/etherlab/ConfigEditor.py	Fri Sep 28 13:21:06 2018 +0300
+++ b/etherlab/ConfigEditor.py	Fri Sep 28 17:14:42 2018 +0300
@@ -183,7 +183,7 @@
                     self.CurrentFilter = (index, index)
                     self.VariablesFilter.SetValue(VARIABLE_INDEX_FILTER_FORMAT % index)
                 self.RefreshView()
-            except:
+            except Exception:
                 if self.CurrentFilter in self.Filters:
                     self.VariablesFilter.SetSelection(self.Filters.index(self.CurrentFilter))
                 else:
@@ -400,7 +400,7 @@
         message = None
         try:
             values = eval(data)
-        except:
+        except Exception:
             message = _("Invalid value \"%s\" for process variable")%data
             values = None
         if not isinstance(values, TupleType):
@@ -460,7 +460,7 @@
         message = None
         try:
             values = eval(data)
-        except:
+        except Exception:
             message = _("Invalid value \"%s\" for startup command")%data
             values = None
         if not isinstance(values, TupleType):
@@ -854,7 +854,7 @@
             try:
                 int(value)
                 self.NodesFilter.SetValue(value)
-            except:
+            except Exception:
                 self.NodesFilter.SetSelection(0)
         self.RefreshCurrentNodesFilter()
     
@@ -872,7 +872,7 @@
                     position = int(self.NodesFilter.GetValue())
                     self.CurrentNodesFilter = {"slave_pos": position}
                     self.NodesFilter.SetValue(NODE_POSITION_FILTER_FORMAT % position)
-            except:
+            except Exception:
                 if self.CurrentNodesFilter in self.NodesFilterValues:
                     self.NodesFilter.SetSelection(self.NodesFilterValues.index(self.CurrentNodesFilter))
                 else:
--- a/etherlab/EtherCATManagementEditor.py	Fri Sep 28 13:21:06 2018 +0300
+++ b/etherlab/EtherCATManagementEditor.py	Fri Sep 28 17:14:42 2018 +0300
@@ -267,7 +267,7 @@
             line = returnVal.split("\n")
             try :
                 self.SetCurrentState(line[self.Controler.GetSlavePos()])
-            except :
+            except Exception:
                 pass  
             
     def SetCurrentState(self, line):
@@ -282,7 +282,7 @@
             token = line.split("  ")
             if token[2] in state_array:
                 self.TextCtrlDic["CurrentState"].SetValue(token[2])           
-        except :
+        except Exception:
             pass     
         
     def StartTimer(self, event):
@@ -303,7 +303,7 @@
         """
         try:
             self.SlaveStateThread.Stop()
-        except:
+        except Exception:
             pass
         
 #-------------------------------------------------------------------------------
@@ -402,7 +402,7 @@
                 # SDO data is not return "dec value"
                 # line example : 
                 # 0x1702:01,rwr-r-,uint32,32 bit," 1st mapping", ---- 
-                except :
+                except Exception:
                     empty, hex_val = token_tail
                 
                 name_after_check = self.StringTest(name)
@@ -965,7 +965,7 @@
                         # for fast loading when slave plugin node is reopened.
                         self.Controler.CommonMethod.SiiData = self.SiiBinary
                         self.SetEEPROMData()
-                    except:
+                    except Exception:
                         self.Controler.CommonMethod.CreateErrorDialog('The file does not exist!')
                         dialog.Destroy()
     
@@ -1349,10 +1349,10 @@
                 binfile = open(filepath, "rb")
                 self.SiiBinary = binfile.read()
                 self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary)
-                self.UpdateSiiGridTable(self.HexRow, self.HexCol)
+                self.UpdateSiiGridTable(self.HexRow, self.HexCol)

                 self.SiiGrid.SetValue(self.HexCode)
                 self.SiiGrid.Update()
-            except:
+            except Exception:
                 self.Controler.CommonMethod.CreateErrorDialog('The file does not exist!')
             
         dialog.Destroy()
--- a/etherlab/EthercatMaster.py	Fri Sep 28 13:21:06 2018 +0300
+++ b/etherlab/EthercatMaster.py	Fri Sep 28 17:14:42 2018 +0300
@@ -31,7 +31,7 @@
 try:
     from EthercatCIA402Slave import _EthercatCIA402SlaveCTN
     HAS_MCL = True
-except:
+except Exception:
     HAS_MCL = False
 
 #--------------------------------------------------
--- a/etherlab/EthercatSlave.py	Fri Sep 28 13:21:06 2018 +0300
+++ b/etherlab/EthercatSlave.py	Fri Sep 28 17:14:42 2018 +0300
@@ -34,11 +34,11 @@
 def ExtractHexDecValue(value):
     try:
         return int(value)
-    except:
+    except Exception:
         pass
     try:
         return int(value.replace("#", "0"), 16)
-    except:
+    except Exception:
         raise ValueError, "Invalid value for HexDecValue \"%s\"" % value
 
 def GenerateHexDecValue(value, base=10):
--- a/etherlab/runtime_etherlab.py	Fri Sep 28 13:21:06 2018 +0300
+++ b/etherlab/runtime_etherlab.py	Fri Sep 28 17:14:42 2018 +0300
@@ -100,7 +100,7 @@
     global KMSGPollThread, StopKMSGThread, SDOProc, SDOThread
     try:
         os.kill(SDOProc.pid, SIGTERM)
-    except:
+    except Exception:
         pass
     SDOThread = None
     StopKMSGThread = True