Skip to content

Commit

Permalink
Make all 'except' statements compatible with both Python 2 and Python…
Browse files Browse the repository at this point in the history
… 3 (sonic-net#5)
  • Loading branch information
jleveque authored May 2, 2018
1 parent b553dba commit ba614d3
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion sonic_eeprom/eeprom_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import struct
import subprocess
import fcntl
except ImportError, e:
except ImportError as e:
raise ImportError (str(e) + "- required module not found")


Expand Down
6 changes: 3 additions & 3 deletions sonic_eeprom/eeprom_dts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import exceptions
import binascii
import subprocess
except ImportError, e:
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

i2c_root = '/sys/class/i2c-adapter/'
Expand Down Expand Up @@ -38,7 +38,7 @@ def get_dev_attr_from_dtb(tokens):
shell=False, stderr=subprocess.STDOUT)
cmdout = ph.communicate()[0]
ph.wait()
except OSError, e:
except OSError as e:
raise OSError("cannot access directory")

lines = cmdout.splitlines()
Expand Down Expand Up @@ -101,7 +101,7 @@ def get_dev_attr_from_dtb(tokens):
shell=False, stderr=subprocess.STDOUT)
cmdout = ph.communicate()[0]
ph.wait()
except OSError, e:
except OSError as e:
raise OSError("cannot access directory")

lines = cmdout.splitlines()
Expand Down
2 changes: 1 addition & 1 deletion sonic_eeprom/eeprom_tlvinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os
import sys
import eeprom_base
except ImportError, e:
except ImportError as e:
raise ImportError (str(e) + "- required module not found")


Expand Down
2 changes: 1 addition & 1 deletion sonic_led/led_control_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

try:
import abc
except ImportError, e:
except ImportError as e:
raise ImportError (str(e) + " - required module not found")

class LedControlBase(object):
Expand Down
2 changes: 1 addition & 1 deletion sonic_sfp/bcmshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import time
import socket
import re
except ImportError, e:
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

#-------------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions sonic_sfp/sff8436.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import types
from math import log10
from sffbase import sffbase
except ImportError, e:
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

class sff8436InterfaceId(sffbase):
Expand Down Expand Up @@ -436,7 +436,7 @@ def calc_temperature(self, eeprom_data, offset, size):
retval = '%.4f' %result + 'C'
else:
retval = 'Unknown'
except Exception, err:
except Exception as err:
retval = str(err)

return retval
Expand Down Expand Up @@ -480,7 +480,7 @@ def calc_voltage(self, eeprom_data, offset, size):
else:
#print indent, name, ' : Unknown'
retval = 'Unknown'
except Exception, err:
except Exception as err:
retval = str(err)

return retval
Expand Down Expand Up @@ -522,7 +522,7 @@ def calc_bias(self, eeprom_data, offset, size):
retval = '%.4f' %result + 'mA'
else:
retval = 'Unknown'
except Exception, err:
except Exception as err:
retval = str(err)

return retval
Expand Down Expand Up @@ -561,7 +561,7 @@ def calc_tx_power(self, eeprom_data, offset, size):
retval = self.power_in_dbm_str(result)
else:
retval = 'Unknown'
except Exception, err:
except Exception as err:
retval = str(err)

return retval
Expand Down Expand Up @@ -633,7 +633,7 @@ def calc_rx_power(self, eeprom_data, offset, size):
retval = self.power_in_dbm_str(result)
else:
retval = 'Unknown'
except Exception, err:
except Exception as err:
retval = str(err)

return retval
Expand Down
12 changes: 6 additions & 6 deletions sonic_sfp/sff8472.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import types
from math import log10
from sffbase import sffbase
except ImportError, e:
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

#------------------------------------------------------------------------------
Expand Down Expand Up @@ -551,7 +551,7 @@ def calc_temperature(self, eeprom_data, offset, size):
retval = '%.4f' %result + 'C'
else:
retval = 'Unknown'
except Exception, err:
except Exception as err:
retval = str(err)

return retval
Expand Down Expand Up @@ -595,7 +595,7 @@ def calc_voltage(self, eeprom_data, offset, size):
else:
#print indent, name, ' : Unknown'
retval = 'Unknown'
except Exception, err:
except Exception as err:
retval = str(err)

return retval
Expand Down Expand Up @@ -637,7 +637,7 @@ def calc_bias(self, eeprom_data, offset, size):
retval = '%.4f' %result + 'mA'
else:
retval = 'Unknown'
except Exception, err:
except Exception as err:
retval = str(err)

return retval
Expand Down Expand Up @@ -676,7 +676,7 @@ def calc_tx_power(self, eeprom_data, offset, size):
retval = self.power_in_dbm_str(result)
else:
retval = 'Unknown'
except Exception, err:
except Exception as err:
retval = str(err)

return retval
Expand Down Expand Up @@ -748,7 +748,7 @@ def calc_rx_power(self, eeprom_data, offset, size):
retval = self.power_in_dbm_str(result)
else:
retval = 'Unknown'
except Exception, err:
except Exception as err:
retval = str(err)

return retval
Expand Down
6 changes: 3 additions & 3 deletions sonic_sfp/sffbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import getopt
import types
from math import log10
except ImportError, e:
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

class sffbase(object):
Expand All @@ -35,7 +35,7 @@ def convert_hex_to_string(self, arr, start, end):
for n in range(start, end):
ret_str += arr[n]
return str.strip(binascii.unhexlify(ret_str))
except Exception, err:
except Exception as err:
return str(err)

# Convert Date to String
Expand All @@ -51,7 +51,7 @@ def convert_date_to_string(self, eeprom_data, offset, size):
date[month_offset:day_offset] + "-" + \
date[day_offset:lot_offset] + " " + \
date[lot_offset:size]
except Exception, err:
except Exception as err:
retval = str(err)
return retval

Expand Down
4 changes: 2 additions & 2 deletions sonic_sfp/sfputilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _add_new_sfp_device(self, sysfs_sfp_i2c_adapter_path, devaddr):
nd_file.write(nd_str)
nd_file.close()

except Exception, err:
except Exception as err:
print "Error writing to new device file: %s" % str(err)
return 1
else:
Expand All @@ -149,7 +149,7 @@ def _delete_sfp_device(self, sysfs_sfp_i2c_adapter_path, devaddr):
nd_file = open(sysfs_nd_path, "w")
nd_file.write(devaddr)
nd_file.close()
except Exception, err:
except Exception as err:
print "Error writing to new device file: %s" % str(err)
return 1
else:
Expand Down

0 comments on commit ba614d3

Please sign in to comment.