[PATCH] Move addon infrastructure to pykickstart

Martin Sivak msivak at redhat.com
Thu Mar 28 17:26:53 UTC 2013


---
 anaconda.spec.in        |   2 +-
 pyanaconda/addons.py    | 120 ------------------------------------------------
 pyanaconda/kickstart.py |  32 ++-----------
 3 files changed, 5 insertions(+), 149 deletions(-)

diff --git a/anaconda.spec.in b/anaconda.spec.in
index 6e4bb25..e4f7e15 100644
--- a/anaconda.spec.in
+++ b/anaconda.spec.in
@@ -21,7 +21,7 @@ Source0: %{name}-%{version}.tar.bz2
 %define gconfversion 2.28.1
 %define intltoolver 0.31.2-3
 %define libnlver 1.0
-%define pykickstartver 1.99.26
+%define pykickstartver 1.99.27
 %define yumver 3.4.3-32
 %define partedver 1.8.1
 %define pypartedver 2.5-2
diff --git a/pyanaconda/addons.py b/pyanaconda/addons.py
index 96eb813..2568d7b 100644
--- a/pyanaconda/addons.py
+++ b/pyanaconda/addons.py
@@ -18,12 +18,7 @@
 #
 # Red Hat Author(s): Martin Sivak <msivak at redhat.com>
 #
-
-__all__ = ["AddonSection", "AddonRegistry", "AddonData", "collect_addon_paths"]
-
 import os
-from pykickstart.sections import Section
-from pykickstart.options import KSOptionParser
 
 def collect_addon_paths(toplevel_addon_paths, ui_subdir="gui"):
     """This method looks into the directories present
@@ -61,118 +56,3 @@ def collect_addon_paths(toplevel_addon_paths, ui_subdir="gui"):
                 module_paths["categories"].append(("%s.%s.categories.%%s" % (addon_id, ui_subdir), addon_category_path))
 
     return module_paths
-
-class AddonRegistry(object):
-    """This class represents the ksdata.addons object and
-       maintains the ids and data structures for loaded
-       addons.
-
-       It acts as a proxy during kickstart save.
-    """
-
-    def __init__(self, dictionary):
-        self.__dict__ = dictionary
-
-    def __str__(self):
-        return reduce(lambda acc,(id, addon): acc + str(addon),
-                      self.__dict__.iteritems(), "")
-
-    # pylint: disable-msg=C0103
-    def execute(self, storage, ksdata, instClass, users):
-        """This method calls execute on all the registered addons."""
-        for k, v in self.__dict__.iteritems():
-            if hasattr(v, "execute"):
-                v.execute(storage, ksdata, instClass, users)
-
-    def setup(self, storage, ksdata, instClass):
-        """This method calls setup on all the registered addons."""
-        for k, v in self.__dict__.iteritems():
-            if hasattr(v, "setup"):
-                v.setup(storage, ksdata, instClass)
-
-
-class AddonData(object):
-    """This is a common parent class for loading and storing
-       3rd party data to kickstart. It is instantiated by
-       kickstart parser and stored as ksdata.addons.<name>
-       to be used in the user interfaces.
-
-       The mandatory method handle_line receives all lines
-       from the corresponding addon section in kickstart and
-       the mandatory __str__ implementation is responsible for
-       returning the proper kickstart text (to be placed into
-       the %addon section) back.
-
-       There is also a mandatory method execute, which should
-       make all the described changes to the installed system.
-    """
-
-    def __init__(self, name):
-        self.name = name
-        self.content = ""
-
-    def __str__(self):
-        return "%%addon %s\n%s%%end\n" % (self.name, self.content)
-
-    # pylint: disable-msg=C0103
-    def setup(self, storage, ksdata, instClass):
-        """Make the changes to the install system.
-
-           This method is called before the installation
-           is started and directly from spokes. It must be possible
-           to call it multiple times without breaking the environment."""
-        pass
-
-    def execute(self, storage, ksdata, instClass, users):
-        """Make the changes to the underlying system.
-
-           This method is called only once in the post-install
-           setup phase.
-        """
-        pass
-
-    def handle_line(self, line):
-        """Process one kickstart line."""
-        self.content += line
-
-    def finalize(self):
-        """No additional data will come.
-
-           Addon should check if all mandatory attributes were populated.
-        """
-        pass
-
-class AddonSection(Section):
-    sectionOpen = "%addon"
-
-    def __init__(self, *args, **kwargs):
-        Section.__init__(self, *args, **kwargs)
-        self.addon_id = None
-
-    def handleLine(self, line):
-        if not self.handler:
-            return
-
-        if not self.addon_id:
-            return
-
-        addon = getattr(self.handler.addons, self.addon_id)
-        addon.handle_line(line)
-
-    def handleHeader(self, lineno, args):
-        """Process the arguments to the %addon header."""
-        Section.handleHeader(self, lineno, args)
-        op = KSOptionParser(version=self.version)
-        (_opts, extra) = op.parse_args(args=args[1:], lineno=lineno)
-        self.addon_id = extra[0]
-
-        # if the addon is not registered, create dummy placeholder for it
-        if self.addon_id and not hasattr(self.handler.addons, self.addon_id):
-            setattr(self.handler.addons, self.addon_id, AddonData(self.addon_id))
-
-    def finalize(self):
-        """Let addon know no additional data will come."""
-        Section.finalize()
-
-        addon = getattr(self.handler.addons, self.addon_id)
-        addon.finalize()
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index 9060c58..b685bf6 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -56,7 +56,8 @@ from pyanaconda.simpleconfig import SimpleConfigFile
 from pyanaconda.users import getPassAlgo
 from pyanaconda.desktop import Desktop
 from .ui.common import collect
-from .addons import AddonSection, AddonData, AddonRegistry, collect_addon_paths
+from .addons import collect_addon_paths
+from pykickstart.addons import AddonSection
 
 from pykickstart.base import KickstartCommand
 from pykickstart.constants import *
@@ -1422,35 +1423,10 @@ dataMap = {
 superclass = returnClassForVersion()
     
 class AnacondaKSHandler(superclass):
-    AddonClassType = AddonData
-    
-    def __init__ (self, addon_paths = [], commandUpdates=commandMap, dataUpdates=dataMap):
-        superclass.__init__(self, commandUpdates=commandUpdates, dataUpdates=dataUpdates)
+    def __init__ (self, addonPaths = [], commandUpdates=commandMap, dataUpdates=dataMap):
+        superclass.__init__(self, addonPaths = addonPaths, commandUpdates=commandUpdates, dataUpdates=dataUpdates)
         self.onPart = {}
 
-        # collect all kickstart addons for anaconda to addons dictionary
-        # which maps addon_id to it's own data structure based on BaseData
-        # with execute method
-        addons = {}
-
-        # collect all AddonData subclasses from
-        # for p in addon_paths: <p>/<plugin id>/ks/*.(py|so)
-        # and register them under <plugin id> name
-        for module_name, path in addon_paths:
-            addon_id = os.path.basename(os.path.dirname(os.path.abspath(path)))
-            if not os.path.isdir(path):
-                continue
-
-            classes = collect(module_name, path, lambda cls: issubclass(cls, self.AddonClassType))
-            if classes:
-                addons[addon_id] = classes[0](name = addon_id)
-
-        # Prepare the structure to track configured spokes
-        self.configured_spokes = SpokeRegistry()
-
-        # Prepare the final structures for 3rd party addons
-        self.addons = AddonRegistry(addons)
-
     def __str__(self):
         return superclass.__str__(self) + "\n" +  str(self.addons)
 
-- 
1.7.11.7



More information about the anaconda-patches mailing list