Skip to content

Commit

Permalink
[eeprom] Fix UnboundLocalError (#93)
Browse files Browse the repository at this point in the history
Fix the error, "UnboundLocalError: local variable 'F' referenced before assignment"
  • Loading branch information
vincentchiang-ec committed Jul 11, 2020
1 parent d4eb804 commit 7c8bed1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions sonic_platform_base/sonic_eeprom/eeprom_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ def __init__(self, path, format, start, status, readonly):

def check_status(self):
if self.u != '':
F = None
try:
F = open(self.u, "r")
d = F.readline().rstrip()
except IOError as e:
raise IOError("Failed to check status : %s" % (str(e)))
finally:
F.close()
if F is not None:
F.close()
return d
else:
return 'ok'
Expand Down Expand Up @@ -236,6 +238,7 @@ def read_eeprom(self):
return o

def read_eeprom_bytes(self, byteCount, offset=0):
F = None
try:
F = self.open_eeprom()
F.seek(self.s + offset)
Expand All @@ -259,35 +262,40 @@ def read_eeprom_bytes(self, byteCount, offset=0):
except IOError as e:
raise IOError("Failed to read eeprom : %s" % (str(e)))
finally:
F.close()
if F is not None:
F.close()

return o

def read_eeprom_db(self):
return 0

def write_eeprom(self, e):
F = None
try:
F = open(self.p, "wb")
F.seek(self.s)
F.write(e)
except IOError as e:
raise IOError("Failed to write eeprom : %s" % (str(e)))
finally:
F.close()
if F is not None:
F.close()

self.write_cache(e)

def write_cache(self, e):
if self.cache_name:
F = None
try:
F = open(self.cache_name, "wb")
F.seek(self.s)
F.write(e)
except IOError as e:
raise IOError("Failed to write cache : %s" % (str(e)))
finally:
F.close()
if F is not None:
F.close()

def update_cache(self, e):
if self.cache_update_needed:
Expand Down

0 comments on commit 7c8bed1

Please sign in to comment.