Add an __all__ to limit the names imported in the common case where code
does 'from autotest_lib.client.common_lib.errors import *' to only
those that we define ourselves.

Signed-off-by: Gregory Smith <gps@google.com>




git-svn-id: http://test.kernel.org/svn/autotest/trunk@2296 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/error.py b/client/common_lib/error.py
index b5148ec..16b742d 100644
--- a/client/common_lib/error.py
+++ b/client/common_lib/error.py
@@ -5,6 +5,12 @@
 import sys, traceback
 from traceback import format_exception
 
+# Add names you want to be imported by 'from errors import *' to this list.
+# This must be list not a tuple as we modify it to include all of our
+# the Exception classes we define below at the end of this file.
+__all__ = ['format_error']
+
+
 def format_error():
     t, o, tb = sys.exc_info()
     trace = format_exception(t, o, tb)
@@ -197,3 +203,14 @@
     def __str__(self):
         return ("Subcommand %s failed with exit code %d" %
                 (self.func, self.exit_code))
+
+
+# This MUST remain at the end of the file.
+# Limit 'from error import *' to only import the exception instances.
+for _name, _thing in locals().items():
+    try:
+        if issubclass(_thing, Exception):
+            __all__.append(_name)
+    except TypeError:
+        pass  # _thing not a class
+__all__ = tuple(__all__)