Skip to content

Commit

Permalink
Fix some LGTM alerts; Add LGTM badges to README.md (#146)
Browse files Browse the repository at this point in the history
LGTM tool is now active for the sonic-platform-common repo.

- Add LGTM badges to README.md
- Fix 26 LGTM alerts:
  - 17 for Unused import
  - 9 for Except block handles 'BaseException'
  • Loading branch information
jleveque authored Dec 2, 2020
1 parent fa0aaa6 commit 6f7d8a0
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 34 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![Total alerts](https://img.shields.io/lgtm/alerts/g/Azure/sonic-platform-common.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Azure/sonic-platform-common/alerts/)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Azure/sonic-platform-common.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Azure/sonic-platform-common/context:python)

# SONiC: Software for Open Networking in the Cloud

## sonic-platform-common
Expand Down
9 changes: 1 addition & 8 deletions sonic_platform_base/sonic_eeprom/eeprom_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@

from __future__ import print_function

try:
import exceptions # Python 2
except ImportError:
import builtins as exceptions # Python 3
try:
import binascii
import optparse
import os
import io
import sys
import struct
import subprocess
import fcntl
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
Expand Down Expand Up @@ -224,7 +217,7 @@ def open_eeprom(self):
if os.path.isfile(self.cache_name):
eeprom_file = self.cache_name
using_eeprom = False
except:
except Exception:
pass
self.cache_update_needed = using_eeprom
return io.open(eeprom_file, "rb")
Expand Down
9 changes: 2 additions & 7 deletions sonic_platform_base/sonic_eeprom/eeprom_tlvinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@
from __future__ import print_function

try:
import exceptions # Python 2
except ImportError:
import builtins as exceptions # Python 3
try:
import binascii
import optparse
import os
import sys

import redis

from . import eeprom_base # Dot module supports both Python 2 and Python 3 using explicit relative import methods
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
Expand Down
4 changes: 2 additions & 2 deletions sonic_platform_base/sonic_sfp/bcmshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __del__(self):

try:
self.close()
except:
except Exception:
pass

#---------------
Expand Down Expand Up @@ -497,5 +497,5 @@ def __open__(self):
raise IOError("Socket error: unable to flush %s on open: %s" % (self.socketname, errstr))
except IOError as e:
raise IOError("unable to flush %s on open: %s" % (self.socketname, e.message))
except:
except Exception:
raise IOError("unable to flush %s on open" % self.socketname)
1 change: 0 additions & 1 deletion sonic_platform_base/sonic_sfp/sff8436.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import struct
import sys
import time
import binascii
import os
import getopt
import types
Expand Down
3 changes: 1 addition & 2 deletions sonic_platform_base/sonic_sfp/sff8472.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import struct
import sys
import time
import binascii
import os
import getopt
import types
Expand Down Expand Up @@ -530,7 +529,7 @@ def _get_calibration_type(self, eeprom_data):
return 2 # externally calibrated
else:
return 0 # Could not find calibration type
except:
except Exception:
return 0

def __init__(self, eeprom_raw_data=None):
Expand Down
4 changes: 2 additions & 2 deletions sonic_platform_base/sonic_sfp/sffbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ def test_bit(self, n, bitpos):
return 0
else:
return 1
except:
except Exception:
return -1

def twos_comp(self, num, bits):
try:
if ((num & (1 << (bits - 1))) != 0):
num = num - (1 << bits)
return num
except:
except Exception:
return 0

def mw_to_dbm(self, mW):
Expand Down
14 changes: 6 additions & 8 deletions sonic_platform_base/sonic_sfp/sfputilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

try:
import abc
import binascii
import os
import re
import sys
Expand All @@ -18,7 +17,6 @@
from sonic_py_common import device_info
from sonic_py_common.interface import backplane_prefix

from . import bcmshell # Dot module supports both Python 2 and Python 3 using explicit relative import methods
from sonic_eeprom import eeprom_dts
from .sff8472 import sff8472InterfaceId # Dot module supports both Python 2 and Python 3 using explicit relative import methods
from .sff8472 import sff8472Dom # Dot module supports both Python 2 and Python 3 using explicit relative import methods
Expand Down Expand Up @@ -283,7 +281,7 @@ def _sfp_eeprom_present(self, sysfs_sfp_i2c_client_eeprompath, offset):
sysfsfile.read(1)
except IOError:
return False
except:
except Exception:
return False
else:
return True
Expand Down Expand Up @@ -342,7 +340,7 @@ def _read_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes):
try:
for n in range(0, num_bytes):
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
except:
except Exception:
return None

return eeprom_raw
Expand All @@ -364,7 +362,7 @@ def _read_eeprom_devid(self, port_num, devid, offset, num_bytes = 256):

try:
sysfsfile_eeprom.close()
except:
except Exception:
return None

return eeprom_raw
Expand Down Expand Up @@ -395,7 +393,7 @@ def _write_eeprom_devid(self, port_num, devid, offset, num_bytes, write_buffer):

try:
sysfsfile_eeprom.close()
except:
except Exception:
return False

return True
Expand Down Expand Up @@ -468,7 +466,7 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0):

try:
f = open(porttabfile)
except:
except Exception:
raise

# Read the porttab file and generate dicts
Expand Down Expand Up @@ -571,7 +569,7 @@ def read_phytab_mappings(self, phytabfile):

try:
f = open(phytabfile)
except:
except Exception:
raise

# Read the phytab file and generate dicts
Expand Down
4 changes: 1 addition & 3 deletions sonic_platform_base/sonic_sfp/sfputilhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from __future__ import print_function

try:
import abc
import binascii
import os
import re
import sys
Expand Down Expand Up @@ -105,7 +103,7 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0):

try:
f = open(porttabfile)
except:
except Exception:
raise

# Read the porttab file and generate dicts
Expand Down
1 change: 0 additions & 1 deletion sonic_platform_base/thermal_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# to interact with a thermal module in SONiC
#

import sys
from . import device_base


Expand Down

0 comments on commit 6f7d8a0

Please sign in to comment.