summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Client/Tools/POSIX
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-27 20:48:15 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-27 21:00:37 -0400
commit9d4f01972775eb6c601f5a7f55715002df2fecb1 (patch)
tree76d50c71915e19767495301abb34fed42ac3a1a4 /src/lib/Bcfg2/Client/Tools/POSIX
parentc07cc475cbafec24e747d6907f3bf7257e441934 (diff)
downloadbcfg2-9d4f01972775eb6c601f5a7f55715002df2fecb1.tar.gz
bcfg2-9d4f01972775eb6c601f5a7f55715002df2fecb1.tar.bz2
bcfg2-9d4f01972775eb6c601f5a7f55715002df2fecb1.zip
added better common walk_packages implementation for python 2.4 and 2.5
Conflicts: src/lib/Bcfg2/Client/Tools/__init__.py
Diffstat (limited to 'src/lib/Bcfg2/Client/Tools/POSIX')
-rw-r--r--src/lib/Bcfg2/Client/Tools/POSIX/__init__.py26
1 files changed, 6 insertions, 20 deletions
diff --git a/src/lib/Bcfg2/Client/Tools/POSIX/__init__.py b/src/lib/Bcfg2/Client/Tools/POSIX/__init__.py
index 6316c749c..a0a8ac9f2 100644
--- a/src/lib/Bcfg2/Client/Tools/POSIX/__init__.py
+++ b/src/lib/Bcfg2/Client/Tools/POSIX/__init__.py
@@ -4,9 +4,9 @@ import os
import re
import sys
import shutil
-import pkgutil
from datetime import datetime
import Bcfg2.Client.Tools
+from Bcfg2.Compat import walk_packages
try:
from base import POSIXTool
except ImportError:
@@ -45,26 +45,12 @@ class POSIX(Bcfg2.Client.Tools.Tool):
# this must be called at run-time, not at compile-time, or we
# get wierd circular import issues.
self._handlers = dict()
- if hasattr(pkgutil, 'walk_packages'):
- submodules = pkgutil.walk_packages(path=__path__)
- else:
- # python 2.4
- import glob
- submodules = []
- for path in __path__:
- for submodule in glob.glob(os.path.join(path, "*.py")):
- mod = os.path.splitext(os.path.basename(submodule))[0]
- if mod not in ['__init__']:
- submodules.append((None, mod, True))
-
- for submodule in submodules:
- if submodule[1] == 'base':
+ for submodule in walk_packages(path=__path__, prefix=__name__ + "."):
+ mname = submodule[1].rsplit('.', 1)[-1]
+ if mname == 'base':
continue
- module = getattr(__import__("%s.%s" %
- (__name__,
- submodule[1])).Client.Tools.POSIX,
- submodule[1])
- hdlr = getattr(module, "POSIX" + submodule[1])
+ module = getattr(__import__(submodule[1]).Client.Tools.POSIX, mname)
+ hdlr = getattr(module, "POSIX" + mname)
if POSIXTool in hdlr.__mro__:
# figure out what entry type this handler handles
etype = hdlr.__name__[5:].lower()