Move duplicate module loading code into a function.
authorZac Medico <zmedico@gentoo.org>
Sat, 1 Dec 2007 12:45:37 +0000 (12:45 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 1 Dec 2007 12:45:37 +0000 (12:45 -0000)
svn path=/main/trunk/; revision=8789

pym/portage/elog/__init__.py

index d3e333534384ef693a6d77e1eb48741137e5c66b..5aa6930c721450192c4e04e49926c2a2182546e1 100644 (file)
@@ -43,11 +43,21 @@ def _combine_logentries(logentries):
        return "".join(rValue)
 
 _elog_mod_imports = {}
+def _load_mod(name):
+       global _elog_mod_imports
+       m = _elog_mod_imports.get(name)
+       if m is None:
+               m = __import__(name)
+               for comp in name.split(".")[1:]:
+                       m = getattr(m, comp)
+               _elog_mod_imports[name] = m
+       return m
+
 _elog_atexit_handlers = []
 _preserve_logentries = {}
 def elog_process(cpv, mysettings, phasefilter=None):
 
-       global _elog_mod_imports
+       
        logsystems = mysettings.get("PORTAGE_ELOG_SYSTEM","").split()
        for s in logsystems:
                # allow per module overrides of PORTAGE_ELOG_CLASSES
@@ -57,13 +67,7 @@ def elog_process(cpv, mysettings, phasefilter=None):
                # - is nicer than _ for module names, so allow people to use it.
                s = s.replace("-", "_")
                try:
-                       name = "portage.elog.mod_" + s
-                       m = _elog_mod_imports.get(name)
-                       if m is None:
-                               m = __import__(name)
-                               for comp in name.split(".")[1:]:
-                                       m = getattr(m, comp)
-                               _elog_mod_imports[name] = m
+                       _load_mod("portage.elog.mod_" + s)
                except ImportError:
                        pass
 
@@ -113,15 +117,7 @@ def elog_process(cpv, mysettings, phasefilter=None):
                        # - is nicer than _ for module names, so allow people to use it.
                        s = s.replace("-", "_")
                        try:
-                               # FIXME: ugly ad.hoc import code
-                               # TODO:  implement a common portage module loader
-                               name = "portage.elog.mod_" + s
-                               m = _elog_mod_imports.get(name)
-                               if m is None:
-                                       m = __import__(name)
-                                       for comp in name.split(".")[1:]:
-                                               m = getattr(m, comp)
-                                       _elog_mod_imports[name] = m
+                               m = _load_mod("portage.elog.mod_" + s)
                                def timeout_handler(signum, frame):
                                        raise PortageException("Timeout in elog_process for system '%s'" % s)
                                import signal