Permalink
Switch branches/tags
workflow-change-base ttt-tag-will-be-removed taroon-pre-package-changes taroon-merge-point taroon-emd-base taroon-base start sent-alpnet s390-beforeheadmerge rhel5-base rhel4-base r6.1.beta1 r4-3-17 r0-49 r0-9-2 r0-9-1 r0-9-0 r0-8-14 r0-8-11 r0-8-10 r0-8-7 r0-8-6 r0-8-2 r0-7-11 r0-7-9 r0-7-5 r0-7-4 r0-7-3 r0-7-2 r0-7-1 pre-tab-convert pre-newcomps merged-to-taroon merge.with.pot kudzu-r0-98-10 kudzu-r0-97 kudzu-r0-69 kudzu-r0-66 kudzu-r0-46 kudzu-r0-44 i18n-update-from-sources-07-20-2001 help hampton-post-HEAD-merge fc5-base fc4-base fc3-base f17-pre-noloader-merge f8-base f7-base desc config-migrate-base before.390.merge before.removing.utc before.po.msgmerge before.libdir.changes before.kudzu.loader.patch before.jj.patch2 before.bootloader.merge before-taroon-updates before-taroon-merge before-taroon-merge-2 before-rpm-4.1 before-parted-1-6-changes before-nfs-mount-upgrade before-loader-switch before-hampton-merge before-ccb-qu2-cleanup before-cambridge-monitor-query-change before-6-1-merge b4.msf.really.broke.x ancaonda-fairfax-beta-3 anaconda.8.0.90 anaconda-sparc-alpha-base anaconda-s390-tag7 anaconda-s390-tag5 anaconda-s390-tag4 anaconda-s390-tag3 anaconda-s390-tag2 anaconda-s390-tag anaconda-s390-new-tag6 anaconda-s390-GA2 anaconda-parted-base anaconda-hampton-rescueloader-base anaconda-hampton-beta1-5 anaconda-hampton-beta1-4 anaconda-hampton-beta1-3 anaconda-hampton-beta1-2 anaconda-hampton-beta-1 anaconda-hampton-base anaconda-gtk-2-0-base anaconda-fairfax-rc2 anaconda-fairfax-rc1 anaconda-fairfax-beta-3 anaconda-fairfax-beta-2 anaconda-fairfax-beta-1 anaconda-fairfax-beta-1-2 anaconda-dispatch-base anaconda-before-rpm-head-changes anaconda-before-japanese-merge anaconda-before-2.6
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
225 lines (174 sloc) 8.39 KB
# Methods and API for anaconda/firstboot 3rd party addons
#
# Copyright (C) 2012 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details. You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#
__all__ = ["AddonSection", "AddonRegistry", "AddonData", "collect_addon_paths"]
import os
import functools
from pykickstart.sections import Section
from pyanaconda.progress import progress_message
from pyanaconda.core.i18n import N_
from pyanaconda.anaconda_loggers import get_module_logger
log = get_module_logger(__name__)
PLACEHOLDER_NAME = "ADDON_placeholder"
def collect_addon_paths(toplevel_addon_paths, ui_subdir="gui"):
"""This method looks into the directories present
in toplevel_addon_paths and registers each subdirectory
as a new addon identified by that subdirectory name.
It then registers spokes, categories and data (ks)
paths for the application to use. By default is looks
for spokes and categories in <addon>/gui/ subdirectory
but that can be changed using the ui_subdir argument."""
module_paths = {
"spokes": [],
"ks": [],
"categories": []
}
for path in toplevel_addon_paths:
try:
directories = os.listdir(path)
except OSError:
directories = []
for addon_id in directories:
addon_ks_path = os.path.join(path, addon_id, "ks")
if os.path.isdir(addon_ks_path):
module_paths["ks"].append(("%s.ks.%%s" % addon_id, addon_ks_path))
addon_spoke_path = os.path.join(path, addon_id, ui_subdir, "spokes")
if os.path.isdir(addon_spoke_path):
module_paths["spokes"].append(("%s.%s.spokes.%%s" % (addon_id, ui_subdir), addon_spoke_path))
addon_category_path = os.path.join(path, addon_id, "categories")
if os.path.isdir(addon_category_path):
module_paths["categories"].append(("%s.categories.%%s" % addon_id, 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 functools.reduce(lambda acc, id_addon: acc + str(id_addon[1]),
self.__dict__.items(), "")
def execute(self, storage, ksdata, instClass, users, payload):
"""This method calls execute on all the registered addons."""
for v in self.__dict__.values():
if hasattr(v, "execute"):
progress_message(N_("Executing %s addon") % v.name)
if v.execute.__code__.co_argcount == 6:
v.execute(storage, ksdata, instClass, users, payload)
else:
v.execute(storage, ksdata, instClass, users)
log.warning("Addon %s is using deprecated method signature", v.name)
log.warning("Use execute(storage, ksdata, instClass, users, payload) instead")
def setup(self, storage, ksdata, instClass, payload):
"""This method calls setup on all the registered addons."""
# filter out placeholders (should be imported now)
d = {}
for k, v in self.__dict__.items():
if not v.name == PLACEHOLDER_NAME:
d[k] = v
else:
log.warning("Removing placeholder for addon %s. Addon wasn't imported!", k)
self.__dict__ = d
for v in self.__dict__.values():
if hasattr(v, "setup"):
if v.setup.__code__.co_argcount == 5:
v.setup(storage, ksdata, instClass, payload)
else:
v.setup(storage, ksdata, instClass)
log.warning("Addon %s is using deprecated method signature", v.name)
log.warning("Use setup(storage, ksdata, instClass, payload) instead")
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 = ""
self.header_args = ""
def __str__(self):
return "%%addon %s %s\n%s%%end\n" % (self.name, self.header_args, self.content)
def setup(self, storage, ksdata, instClass, payload):
"""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."""
log.warning("Addon %s doesn't have setup method!", self.name)
def execute(self, storage, ksdata, instClass, users, payload):
"""Make the changes to the underlying system.
This method is called only once in the post-install
setup phase.
"""
log.warning("Addon %s doesn't have execute method!", self.name)
def handle_header(self, lineno, args):
"""Process additional arguments to the %addon line.
This function receives any arguments on the %addon line after the
addon ID. For example, for the line:
%addon com_example_foo --argument='example'
This function would be called with args=["--argument='example'"].
By default AddonData.handle_header just preserves the passed
arguments by storing them and adding them to the __str__ output.
"""
if args:
self.header_args += " ".join(args)
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."""
super().handleHeader(lineno, args)
self.addon_id = args[1]
# If the addon is not registered, create dummy placeholder for it.
# If not replaced, the placeholder will be removed in the setup method.
if self.addon_id and not hasattr(self.handler.addons, self.addon_id):
setattr(self.handler.addons, self.addon_id, AddonData(PLACEHOLDER_NAME))
# Parse additional arguments to %addon with the AddonData handler
addon = getattr(self.handler.addons, self.addon_id)
addon.handle_header(lineno, args[2:])
def finalize(self):
"""Let addon know no additional data will come."""
super().finalize()
addon = getattr(self.handler.addons, self.addon_id)
addon.finalize()