Skip to content

Commit 6f7d8a0

Browse files
authored
Fix some LGTM alerts; Add LGTM badges to README.md (#146)
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'
1 parent fa0aaa6 commit 6f7d8a0

File tree

10 files changed

+18
-34
lines changed

10 files changed

+18
-34
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[![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/)
2+
[![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)
3+
14
# SONiC: Software for Open Networking in the Cloud
25

36
## sonic-platform-common

sonic_platform_base/sonic_eeprom/eeprom_base.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,11 @@
1010

1111
from __future__ import print_function
1212

13-
try:
14-
import exceptions # Python 2
15-
except ImportError:
16-
import builtins as exceptions # Python 3
1713
try:
1814
import binascii
19-
import optparse
2015
import os
2116
import io
22-
import sys
2317
import struct
24-
import subprocess
2518
import fcntl
2619
except ImportError as e:
2720
raise ImportError (str(e) + "- required module not found")
@@ -224,7 +217,7 @@ def open_eeprom(self):
224217
if os.path.isfile(self.cache_name):
225218
eeprom_file = self.cache_name
226219
using_eeprom = False
227-
except:
220+
except Exception:
228221
pass
229222
self.cache_update_needed = using_eeprom
230223
return io.open(eeprom_file, "rb")

sonic_platform_base/sonic_eeprom/eeprom_tlvinfo.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@
1111
from __future__ import print_function
1212

1313
try:
14-
import exceptions # Python 2
15-
except ImportError:
16-
import builtins as exceptions # Python 3
17-
try:
18-
import binascii
19-
import optparse
20-
import os
2114
import sys
15+
2216
import redis
17+
2318
from . import eeprom_base # Dot module supports both Python 2 and Python 3 using explicit relative import methods
2419
except ImportError as e:
2520
raise ImportError (str(e) + "- required module not found")

sonic_platform_base/sonic_sfp/bcmshell.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def __del__(self):
116116

117117
try:
118118
self.close()
119-
except:
119+
except Exception:
120120
pass
121121

122122
#---------------
@@ -497,5 +497,5 @@ def __open__(self):
497497
raise IOError("Socket error: unable to flush %s on open: %s" % (self.socketname, errstr))
498498
except IOError as e:
499499
raise IOError("unable to flush %s on open: %s" % (self.socketname, e.message))
500-
except:
500+
except Exception:
501501
raise IOError("unable to flush %s on open" % self.socketname)

sonic_platform_base/sonic_sfp/sff8436.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import struct
1010
import sys
1111
import time
12-
import binascii
1312
import os
1413
import getopt
1514
import types

sonic_platform_base/sonic_sfp/sff8472.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import struct
1212
import sys
1313
import time
14-
import binascii
1514
import os
1615
import getopt
1716
import types
@@ -530,7 +529,7 @@ def _get_calibration_type(self, eeprom_data):
530529
return 2 # externally calibrated
531530
else:
532531
return 0 # Could not find calibration type
533-
except:
532+
except Exception:
534533
return 0
535534

536535
def __init__(self, eeprom_raw_data=None):

sonic_platform_base/sonic_sfp/sffbase.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ def test_bit(self, n, bitpos):
6363
return 0
6464
else:
6565
return 1
66-
except:
66+
except Exception:
6767
return -1
6868

6969
def twos_comp(self, num, bits):
7070
try:
7171
if ((num & (1 << (bits - 1))) != 0):
7272
num = num - (1 << bits)
7373
return num
74-
except:
74+
except Exception:
7575
return 0
7676

7777
def mw_to_dbm(self, mW):

sonic_platform_base/sonic_sfp/sfputilbase.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
try:
99
import abc
10-
import binascii
1110
import os
1211
import re
1312
import sys
@@ -18,7 +17,6 @@
1817
from sonic_py_common import device_info
1918
from sonic_py_common.interface import backplane_prefix
2019

21-
from . import bcmshell # Dot module supports both Python 2 and Python 3 using explicit relative import methods
2220
from sonic_eeprom import eeprom_dts
2321
from .sff8472 import sff8472InterfaceId # Dot module supports both Python 2 and Python 3 using explicit relative import methods
2422
from .sff8472 import sff8472Dom # Dot module supports both Python 2 and Python 3 using explicit relative import methods
@@ -283,7 +281,7 @@ def _sfp_eeprom_present(self, sysfs_sfp_i2c_client_eeprompath, offset):
283281
sysfsfile.read(1)
284282
except IOError:
285283
return False
286-
except:
284+
except Exception:
287285
return False
288286
else:
289287
return True
@@ -342,7 +340,7 @@ def _read_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes):
342340
try:
343341
for n in range(0, num_bytes):
344342
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
345-
except:
343+
except Exception:
346344
return None
347345

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

365363
try:
366364
sysfsfile_eeprom.close()
367-
except:
365+
except Exception:
368366
return None
369367

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

396394
try:
397395
sysfsfile_eeprom.close()
398-
except:
396+
except Exception:
399397
return False
400398

401399
return True
@@ -468,7 +466,7 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0):
468466

469467
try:
470468
f = open(porttabfile)
471-
except:
469+
except Exception:
472470
raise
473471

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

572570
try:
573571
f = open(phytabfile)
574-
except:
572+
except Exception:
575573
raise
576574

577575
# Read the phytab file and generate dicts

sonic_platform_base/sonic_sfp/sfputilhelper.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from __future__ import print_function
77

88
try:
9-
import abc
10-
import binascii
119
import os
1210
import re
1311
import sys
@@ -105,7 +103,7 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0):
105103

106104
try:
107105
f = open(porttabfile)
108-
except:
106+
except Exception:
109107
raise
110108

111109
# Read the porttab file and generate dicts

sonic_platform_base/thermal_base.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# to interact with a thermal module in SONiC
66
#
77

8-
import sys
98
from . import device_base
109

1110

0 commit comments

Comments
 (0)