hdctools: servo: Properly import HwDriverError

When catching exception from drivers, we want to be able to catch
HwDriverError. However, since HwDriverError is not properly imported to
current namespace, we actually generate an AttributeError when trying to
catch the original exception. This CL imports HwDriverError so that this
doesn't happen.

BUG=chrome-os-partner:10908
TEST=Generate an 'ecError' in EC driver and see the correct error
message using dut-control.

Signed-off-by: Vic Yang <victoryang@chromium.org>
Change-Id: I9cfeb0c42b92f86b6ab8c967f1593d3373b3991e
Reviewed-on: https://gerrit.chromium.org/gerrit/26223
Reviewed-by: Doug Anderson <dianders@chromium.org>
diff --git a/servo/drv/ec.py b/servo/drv/ec.py
index 7b3ef40..7b85cf0 100644
--- a/servo/drv/ec.py
+++ b/servo/drv/ec.py
@@ -18,7 +18,7 @@
 import pexpect
 
 
-import drv.hw_driver
+import hw_driver
 
 # Default setting values
 DEFAULT_DICT = {'kbd_en': 0,
@@ -39,7 +39,7 @@
   """Exception class for ec."""
 
 
-class ec(drv.hw_driver.HwDriver):
+class ec(hw_driver.HwDriver):
   """Object to access drv=ec controls.
 
   Note, instances of this object get dispatched via base class,
diff --git a/servo/drv/gpio.py b/servo/drv/gpio.py
index 44204b2..d2214a4 100644
--- a/servo/drv/gpio.py
+++ b/servo/drv/gpio.py
@@ -6,14 +6,14 @@
 import logging
 
 
-import drv.hw_driver
+import hw_driver
 
 
 class gpioError(Exception):
   """Error class for gpio class."""
 
 
-class gpio(drv.hw_driver.HwDriver):
+class gpio(hw_driver.HwDriver):
   """Object to access type=gpio controls.
 
   Mandatory Params:
diff --git a/servo/drv/ina219.py b/servo/drv/ina219.py
index c5e78ed..115d52b 100644
--- a/servo/drv/ina219.py
+++ b/servo/drv/ina219.py
@@ -9,7 +9,8 @@
 import numpy
 
 
-import drv.hw_driver
+import hw_driver
+import i2c_reg
 
 
 # TODO(tbroch) Need to investigate modal uses and need to change configuration
@@ -75,7 +76,7 @@
   """Error occurred accessing INA219."""
 
 
-class ina219(drv.hw_driver.HwDriver):
+class ina219(hw_driver.HwDriver):
   """Object to access drv=ina219 controls.
 
   Note, instances of this object get dispatched via base class,
@@ -111,10 +112,10 @@
     self._slave = int(self._params['slv'], 0)
     # TODO(tbroch) Re-visit enabling use_reg_cache once re-req's are
     # incorporated into cache's key field ( crosbug.com/p/2678 )
-    self._i2c_obj = drv.i2c_reg.I2cReg.get_device(self._interface, self._slave,
-                                                  addr_len=1, reg_len=2,
-                                                  msb_first=True, no_read=False,
-                                                  use_reg_cache=False)
+    self._i2c_obj = i2c_reg.I2cReg.get_device(self._interface, self._slave,
+                                              addr_len=1, reg_len=2,
+                                              msb_first=True, no_read=False,
+                                              use_reg_cache=False)
     if 'subtype' not in self._params:
       raise Ina219Error("Unable to find subtype param")
     subtype = self._params['subtype']
@@ -421,7 +422,7 @@
                (slv, wbuf[0], rbuf[0], rbuf[1]))
 
   # same read of cfg (0x399f) using ina219 module
-  adc = drv.ina219.ina219(i2c, slv, 'foo', 0.010)
+  adc = ina219.ina219(i2c, slv, 'foo', 0.010)
 
   adc.calibrate()
   testit("POR  ", adc)
diff --git a/servo/drv/ltc1663.py b/servo/drv/ltc1663.py
index 3070076..f5bde2f 100644
--- a/servo/drv/ltc1663.py
+++ b/servo/drv/ltc1663.py
@@ -13,7 +13,8 @@
 2.5V. Selecting the supply as the reference sets the output voltage range
 to the supply voltage.
 """
-import drv.hw_driver
+import hw_driver
+import i2c_reg
 
 
 # TODO(tbroch)
@@ -32,7 +33,7 @@
   """Error class for LTC1663"""
 
 
-class ltc1663(drv.hw_driver.HwDriver):
+class ltc1663(hw_driver.HwDriver):
   """Object to access drv=ltc1663 controls."""
   def __init__(self, interface, params):
     """Constructor.
@@ -52,7 +53,7 @@
     super(ltc1663, self).__init__(interface, params)
     self._logger.debug("")
     self._slave = int(self._params['slv'], 0)
-    self._i2c_obj = drv.i2c_reg.I2cReg.get_device(
+    self._i2c_obj = i2c_reg.I2cReg.get_device(
       self._interface, self._slave, addr_len=1, reg_len=2, msb_first=False,
       no_read=True, use_reg_cache=False)
 
diff --git a/servo/drv/parrot_ec.py b/servo/drv/parrot_ec.py
index 167f74c..6118d89 100644
--- a/servo/drv/parrot_ec.py
+++ b/servo/drv/parrot_ec.py
@@ -10,13 +10,13 @@
 import os
 import pexpect
 
-import drv.hw_driver
+import hw_driver
 
 class parrotEcError(Exception):
   """Exception class for parrot ec."""
 
 
-class parrotEc(drv.hw_driver.HwDriver):
+class parrotEc(hw_driver.HwDriver):
   """Object to access drv=parrot_ec controls.
 
   Note, instances of this object get dispatched via base class,
diff --git a/servo/drv/pca9500.py b/servo/drv/pca9500.py
index d2a34a1..0a5bcb1 100644
--- a/servo/drv/pca9500.py
+++ b/servo/drv/pca9500.py
@@ -29,7 +29,7 @@
 import logging
 
 
-import drv.hw_driver
+import hw_driver
 
 
 REG_CTRL_LEN = 1
@@ -40,7 +40,7 @@
   """Error class for pca9500 class."""
 
 
-class pca9500(drv.hw_driver.HwDriver):
+class pca9500(hw_driver.HwDriver):
   """Object to access type=pca9500 controls."""
 
   _byte_addr = 0
diff --git a/servo/drv/pca9537.py b/servo/drv/pca9537.py
index 9c03d2b..be2a7b4 100644
--- a/servo/drv/pca9537.py
+++ b/servo/drv/pca9537.py
@@ -3,10 +3,11 @@
 # found in the LICENSE file.
 """Driver for board config controls pca9537, a 4-bit ioexpander.
 """
-import drv.hw_driver
+import hw_driver
+import tca6416
 
 
-class pca9537(drv.tca6416.tca6416):
+class pca9537(tca6416.tca6416):
   """Object to access drv=pca9537 controls.
 
   Note, This gpio expander is compatible to the tca6416 driver.  Only
diff --git a/servo/drv/pca9546.py b/servo/drv/pca9546.py
index 94ea48d..2e71a00 100644
--- a/servo/drv/pca9546.py
+++ b/servo/drv/pca9546.py
@@ -3,7 +3,7 @@
 # found in the LICENSE file.
 """
 """
-import drv.hw_driver
+import hw_driver
 
 
 CMD_MASK = 0xf
@@ -12,7 +12,7 @@
   """Error class for PCA9546"""
 
 
-class pca9546(drv.hw_driver.HwDriver):
+class pca9546(hw_driver.HwDriver):
   """Object to access drv=pca9546 controls."""
   def __init__(self, interface, params):
     """Constructor.
diff --git a/servo/drv/tca6416.py b/servo/drv/tca6416.py
index 105fddb..66cef4f 100644
--- a/servo/drv/tca6416.py
+++ b/servo/drv/tca6416.py
@@ -3,7 +3,8 @@
 # found in the LICENSE file.
 """Driver for board config controls tca6416 dual port (16bit) ioexpander.
 """
-import drv.hw_driver
+import hw_driver
+import i2c_reg
 
 
 class Tca6416Error(Exception):
@@ -12,7 +13,7 @@
 
 # TODO(tbroch) style guide wants these to be camel-case but can we have
 # exception as these get loaded dynamically
-class tca6416(drv.hw_driver.HwDriver):
+class tca6416(hw_driver.HwDriver):
   """Object to access drv=tca6416 controls."""
 
 
@@ -61,10 +62,10 @@
     """
     super(tca6416, self).__init__(interface, params)
     slave = self._get_slave()
-    self._i2c_obj = drv.i2c_reg.I2cReg.get_device(self._interface, slave,
-                                                  addr_len=1, reg_len=1,
-                                                  msb_first=True, no_read=False,
-                                                  use_reg_cache=False)
+    self._i2c_obj = i2c_reg.I2cReg.get_device(self._interface, slave,
+                                              addr_len=1, reg_len=1,
+                                              msb_first=True, no_read=False,
+                                              use_reg_cache=False)
     self._port = self._get_port()
 
 
diff --git a/servo/drv/uart.py b/servo/drv/uart.py
index 004df7f..934f753 100644
--- a/servo/drv/uart.py
+++ b/servo/drv/uart.py
@@ -6,14 +6,14 @@
 import logging
 
 
-import drv.hw_driver
+import hw_driver
 
 
 class uartError(Exception):
   """Error class for uart class."""
 
 
-class uart(drv.hw_driver.HwDriver):
+class uart(hw_driver.HwDriver):
   """Object to access type=uart controls.
 
   Note, instances of this object get dispatched via base class,
diff --git a/servo/servo_server.py b/servo/servo_server.py
index 449a4cf..194bfbb 100644
--- a/servo/servo_server.py
+++ b/servo/servo_server.py
@@ -14,6 +14,7 @@
 import urllib
 
 # TODO(tbroch) deprecate use of relative imports
+from drv.hw_driver import HwDriverError
 import ftdigpio
 import ftdii2c
 import ftdi_common
@@ -456,7 +457,7 @@
     except AttributeError, error:
       self._logger.error("Getting %s: %s" % (name, error))
       raise
-    except drv.hw_driver.HwDriverError:
+    except HwDriverError:
       self._logger.error("Getting %s" % (name))
       raise
 
@@ -504,7 +505,7 @@
     wr_val = self._syscfg.resolve_val(params, wr_val_str)
     try:
       drv.set(wr_val)
-    except drv.hw_driver.HwDriverError:
+    except HwDriverError:
       self._logger.error("Setting %s -> %s" % (name, wr_val_str))
       raise
     # TODO(tbroch) Figure out why despite allow_none=True for both xmlrpc server