diff --git a/sonic_eeprom/eeprom_base.py b/sonic_eeprom/eeprom_base.py index 623110f09..0fa1bad59 100644 --- a/sonic_eeprom/eeprom_base.py +++ b/sonic_eeprom/eeprom_base.py @@ -12,7 +12,10 @@ from __future__ import print_function try: - import exceptions + import exceptions # Python 2 +except ImportError: + import builtins as exceptions # Python 3 +try: import binascii import optparse import os diff --git a/sonic_eeprom/eeprom_dts.py b/sonic_eeprom/eeprom_dts.py index a21a3e7a0..df077d2c8 100644 --- a/sonic_eeprom/eeprom_dts.py +++ b/sonic_eeprom/eeprom_dts.py @@ -1,9 +1,12 @@ #!/usr/bin/python # Copyright 2012 Cumulus Networks LLC, all rights reserved +try: + import exceptions # Python 2 +except ImportError: + import builtins as exceptions # Python 3 try: import os - import exceptions import binascii import subprocess except ImportError as e: diff --git a/sonic_eeprom/eeprom_tlvinfo.py b/sonic_eeprom/eeprom_tlvinfo.py index 0ba5a402d..22381e0b9 100644 --- a/sonic_eeprom/eeprom_tlvinfo.py +++ b/sonic_eeprom/eeprom_tlvinfo.py @@ -12,13 +12,16 @@ from __future__ import print_function try: - import exceptions + import exceptions # Python 2 +except ImportError: + import builtins as exceptions # Python 3 +try: import binascii import optparse import os import sys - import eeprom_base 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") diff --git a/sonic_sfp/sff8436.py b/sonic_sfp/sff8436.py index 777cfa1ef..85776f31c 100644 --- a/sonic_sfp/sff8436.py +++ b/sonic_sfp/sff8436.py @@ -16,7 +16,7 @@ import types from math import log10 from sff8024 import type_of_transceiver - from sffbase import sffbase + from .sffbase import sffbase # 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") diff --git a/sonic_sfp/sff8472.py b/sonic_sfp/sff8472.py index 4a4c91ffc..549d3c402 100644 --- a/sonic_sfp/sff8472.py +++ b/sonic_sfp/sff8472.py @@ -18,7 +18,7 @@ import types from math import log10 from sff8024 import type_of_transceiver - from sffbase import sffbase + from .sffbase import sffbase # 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") diff --git a/sonic_sfp/sfputilbase.py b/sonic_sfp/sfputilbase.py index 7356e3d30..72f2e573d 100644 --- a/sonic_sfp/sfputilbase.py +++ b/sonic_sfp/sfputilbase.py @@ -10,12 +10,12 @@ import binascii import os import re - import bcmshell + 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 - from sff8472 import sff8472Dom - from sff8436 import sff8436InterfaceId - from sff8436 import sff8436Dom + 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 + from .sff8436 import sff8436InterfaceId # Dot module supports both Python 2 and Python 3 using explicit relative import methods + from .sff8436 import sff8436Dom # Dot module supports both Python 2 and Python 3 using explicit relative import methods from inf8628 import inf8628InterfaceId except ImportError as e: raise ImportError("%s - required module not found" % str(e))