summaryrefslogtreecommitdiffstats
path: root/pyanaconda/ui/__init__.py
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2012-07-27 15:20:10 +0200
committerMartin Sivak <msivak@redhat.com>2012-08-06 13:32:21 +0200
commit6bd51dab1fc8875220b37f5bad05645728aca982 (patch)
treeabfd596877494c6bb707fddbdcc7a964d4401b19 /pyanaconda/ui/__init__.py
parenta85bc03ec1ed1814de728898a1a4fee13d610658 (diff)
downloadanaconda-6bd51dab1fc8875220b37f5bad05645728aca982.tar.gz
anaconda-6bd51dab1fc8875220b37f5bad05645728aca982.tar.xz
anaconda-6bd51dab1fc8875220b37f5bad05645728aca982.zip
Make collect and part of UserInterface setup more generic
Diffstat (limited to 'pyanaconda/ui/__init__.py')
-rw-r--r--pyanaconda/ui/__init__.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/pyanaconda/ui/__init__.py b/pyanaconda/ui/__init__.py
index 128f67c56..4fafd4971 100644
--- a/pyanaconda/ui/__init__.py
+++ b/pyanaconda/ui/__init__.py
@@ -19,6 +19,8 @@
# Red Hat Author(s): Chris Lumens <clumens@redhat.com>
#
+__all__ = ["UserInterface", "collect"]
+
class UserInterface(object):
"""This is the base class for all kinds of install UIs. It primarily
defines what kinds of dialogs and entry widgets every interface must
@@ -92,3 +94,39 @@ class UserInterface(object):
want to overwhelm the user with choices.
"""
raise NotImplementedError
+
+ def getActionClasses(module_pattern, path, hubs, standalone_class):
+ standalones = collect(module_pattern, path, lambda obj: issubclass(obj, standalone_class) and \
+ getattr(obj, "preForHub", False) or getattr(obj, "postForHub", False))
+
+ actionClasses = []
+ for hub in hubs:
+ actionClasses.extend(sorted(filter(lambda obj: getattr(obj, "preForHub", None) == hub, standalones),
+ key=lambda obj: obj.priority))
+ actionClasses.append(hub)
+ actionClasses.extend(sorted(filter(lambda obj: getattr(obj, "postForHub", None) == hub, standalones),
+ key=lambda obj: obj.priority))
+
+ return actionClasses
+
+def collect(module_pattern, path, pred):
+ """Traverse the directory (given by path) and find all classes that match
+ the given predicate. This is then returned as a list of classes.
+
+ It is suggested you use collect_categories or collect_spokes instead of
+ this lower-level method.
+ """
+ retval = []
+ for module_file in os.listdir(path):
+ if not module_file.endswith(".py") or module_file == "__init__.py":
+ continue
+
+ mod_name = module_file[:-3]
+ module = importlib.import_module(module_pattern % mod_name))
+
+ p = lambda obj: inspect.isclass(obj) and pred(obj)
+
+ for (name, val) in inspect.getmembers(module, p):
+ retval.append(val)
+
+ return retval