[PATCH 3/4] Allow new KS commands to be created by Addons

Martin Sivak msivak at redhat.com
Thu Mar 14 13:47:35 UTC 2013


---
 pyanaconda/addons.py    | 33 +++++++++++++++++++++++++++++++++
 pyanaconda/kickstart.py | 22 +++++++++++++++++++++-
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/pyanaconda/addons.py b/pyanaconda/addons.py
index 412e43a..2c1792d 100644
--- a/pyanaconda/addons.py
+++ b/pyanaconda/addons.py
@@ -90,6 +90,37 @@ class AddonRegistry(object):
             if hasattr(v, "setup"):
                 v.setup(storage, ksdata, instClass)
 
+class AddonCommand(object):
+    """This class represents a standalone command that belongs
+       to one AddonData parent.
+    """
+
+    writePriority = None
+
+    def __init__(self, commandName, data):
+        self.data = data
+        self.commandName = commandName
+        self.currentCmd = None
+        self.currentLine = None
+        self.lineno = None
+
+    def parse(self, args):
+        """This is called for every line which specifies
+           the registered command.
+
+           :param args: list of command arguments without
+                        the command name
+           :type args: list of strings
+        """
+        return self.data
+
+    def __str__(self):
+        return ""
+
+    def dataList(self):
+        """This method is required by KS API."""
+        return None
+
 
 class AddonData(object):
     """This is a common parent class for loading and storing
@@ -107,6 +138,8 @@ class AddonData(object):
        make all the described changes to the installed system.
     """
 
+    COMMAND_MAP = {}
+
     def __init__(self, name):
         self.name = name
         self.content = ""
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index 5ceaf19..b93be56 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -1431,7 +1431,27 @@ class AnacondaKSHandler(superclass):
 
             classes = collect(module_name, path, lambda cls: issubclass(cls, self.AddonClassType))
             if classes:
-                addons[addon_id] = classes[0](name = addon_id)
+                addon_class = classes[0]
+
+                # create data structure
+                addons[addon_id] = addon_class(name = addon_id)
+                for commandName, commandClass in addon_class.COMMAND_MAP.iteritems():
+                    # check for conflicts
+                    if commandName in self.commands:
+                        raise KeyError("Trying to override kickstart command %s" % commandName)
+
+                    # register all commands
+                    cmdObj = commandClass(commandName = commandName, data = addons[addon_id])
+                    self.commands[commandName] = cmdObj
+
+                    # Also, add the object into the _writeOrder dict in the right place.
+                    if cmdObj.writePriority is not None:
+                        if not self._writeOrder.has_key(cmdObj.writePriority):
+                            self._writeOrder[cmdObj.writePriority] = [cmdObj]
+                        else:
+                            self._writeOrder[cmdObj.writePriority].append(cmdObj)
+
+
 
         # Prepare the structure to track configured spokes
         self.configured_spokes = SpokeRegistry()
-- 
1.7.11.7



More information about the anaconda-patches mailing list