This doesn't change the code behavior, but it just replaces a confusing "try: sys.modules[...] except KeyError:" block with a simple "if sys.modules.has_key(...)" check.
Signed-off-by: Eduardo Habkost <[email protected]> --- client/setup_modules.py | 54 +++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/client/setup_modules.py b/client/setup_modules.py index d662df1..ac31455 100644 --- a/client/setup_modules.py +++ b/client/setup_modules.py @@ -122,31 +122,33 @@ def setup(base_path, root_module_name=""): The setup must be different if you are running on an Autotest server or on a test machine that just has the client directories installed. """ + if sys.modules.has_key(root_module_name): + # already set up + return + setup_client_only = False - try: - sys.modules[root_module_name] - except KeyError: - # Hack... Any better ideas? - if root_module_name == 'autotest.client': - serverdir = os.path.join(os.path.dirname(__file__), '..', 'server') - full_source = os.path.exists(serverdir) - if full_source: - root_module_name = 'autotest' - base_path = os.path.abspath(os.path.join(base_path, '..')) - else: - setup_client_only = True - - if setup_client_only: - _create_module_and_parents(root_module_name) - imp.load_package(root_module_name, base_path) + + # Hack... Any better ideas? + if root_module_name == 'autotest.client': + serverdir = os.path.join(os.path.dirname(__file__), '..', 'server') + full_source = os.path.exists(serverdir) + if full_source: + root_module_name = 'autotest' + base_path = os.path.abspath(os.path.join(base_path, '..')) else: - _create_module_and_parents(root_module_name) - _import_children_into_module(root_module_name, base_path) - # Allow locally installed third party packages to be found - # before any that are installed on the system itself when not. - # running as a client. - # This is primarily for the benefit of frontend and tko so that they - # may use libraries other than those available as system packages. - sys.path.insert(0, os.path.join(base_path, "site-packages")) - - _monkeypatch_logging_handle_error() + setup_client_only = True + + if setup_client_only: + _create_module_and_parents(root_module_name) + imp.load_package(root_module_name, base_path) + else: + _create_module_and_parents(root_module_name) + _import_children_into_module(root_module_name, base_path) + # Allow locally installed third party packages to be found + # before any that are installed on the system itself when not. + # running as a client. + # This is primarily for the benefit of frontend and tko so that they + # may use libraries other than those available as system packages. + sys.path.insert(0, os.path.join(base_path, "site-packages")) + + _monkeypatch_logging_handle_error() -- 1.8.1 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
