diff options
author | Zac Medico <zmedico@gentoo.org> | 2007-12-01 12:52:53 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2007-12-01 12:52:53 +0000 |
commit | eb9bbd0705ee69873302fd8446227ee945ed60a1 (patch) | |
tree | 2b5aeeb49263f93ca9c4c7adfff3536e51cea23a /pym | |
parent | 904fefaa6afd9f6cd9913be1cfc96c1c78e3e889 (diff) | |
download | portage-eb9bbd0705ee69873302fd8446227ee945ed60a1.tar.gz portage-eb9bbd0705ee69873302fd8446227ee945ed60a1.tar.bz2 portage-eb9bbd0705ee69873302fd8446227ee945ed60a1.zip |
Move duplicate module loading code into a function. (trunk r8789)
svn path=/main/branches/2.1.2/; revision=8790
Diffstat (limited to 'pym')
-rw-r--r-- | pym/portage.py | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/pym/portage.py b/pym/portage.py index 9d5c005f8..601c12f37 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -493,10 +493,20 @@ class digraph: print "(%s)" % self.nodes[node][0][child] _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 = [] def elog_process(cpv, mysettings): - global _elog_mod_imports + logsystems = mysettings.get("PORTAGE_ELOG_SYSTEM","").split() for s in logsystems: # allow per module overrides of PORTAGE_ELOG_CLASSES @@ -506,12 +516,7 @@ def elog_process(cpv, mysettings): # - is nicer than _ for module names, so allow people to use it. s = s.replace("-", "_") try: - name = "elog_modules.mod_"+s - m = _elog_mod_imports.get(name) - if m is None: - logmodule = __import__(name) - m = getattr(logmodule, "mod_"+s) - _elog_mod_imports[name] = m + _load_mod("elog_modules.mod_" + s) except ImportError: pass @@ -584,14 +589,7 @@ def elog_process(cpv, mysettings): # - 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 = "elog_modules.mod_"+s - m = _elog_mod_imports.get(name) - if m is None: - logmodule = __import__(name) - m = getattr(logmodule, "mod_"+s) - _elog_mod_imports[name] = m + m = _load_mod("elog_modules.mod_" + s) def timeout_handler(signum, frame): raise portage_exception.PortageException( "Timeout in elog_process for system '%s'" % s) |