Example #1
0
    def __init__(self, *args, **kwargs):
        """Create a new KickstartHandler instance.

           Instance attributes:

           commands -- A mapping from a string command to a KickstartCommand
                       subclass object that handles it.  Multiple strings can
                       map to the same object, but only one instance of the
                       command object should ever exist.  Most users should
                       never have to deal with this directly, as it is
                       manipulated internally and called through dispatcher.
           currentLine -- The current unprocessed line from the input file
                          that caused this handler to be run.
        """
        KickstartObject.__init__(self, *args, **kwargs)

        # These will be set by the dispatcher.
        self.commands = {}
        self.currentLine = ""

        # A dict keyed by an integer priority number, with each value being a
        # list of KickstartCommand subclasses.  This dict is maintained by
        # registerCommand and used in __str__.  No one else should be touching
        # it.
        self._writeOrder = {}
Example #2
0
    def __init__(self, *args, **kwargs):
        """Create a new Packages instance.  Instance attributes:

           addBase       -- Should the Base group be installed even if it is
                            not specified?
           nocore        -- Should the Core group be skipped?  This results in
                            a %packages section that basically only installs the
                            packages you list, and may not be a usable system.
           default       -- Should the default package set be selected?
           environment   -- What base environment should be selected?  Only one
                            may be chosen at a time.
           excludedList  -- A list of all the packages marked for exclusion in
                            the %packages section, without the leading minus
                            symbol.
           excludeDocs   -- Should documentation in each package be excluded?
           groupList     -- A list of Group objects representing all the groups
                            specified in the %packages section.  Names will be
                            stripped of the leading @ symbol.
           excludedGroupList -- A list of Group objects representing all the
                                groups specified for removal in the %packages
                                section.  Names will be stripped of the leading
                                -@ symbols.
           handleMissing -- If unknown packages are specified in the %packages
                            section, should it be ignored or not?  Values can
                            be KS_MISSING_* from pykickstart.constants.
           handleBroken  -- If packages with conflicts are specified in the
                            %packages section, should it be ignored or not?
                            Values can be KS_BROKEN_* from pykickstart.constants.
           packageList   -- A list of all the packages specified in the
                            %packages section.
           instLangs     -- A list of languages to install.
           multiLib      -- Whether to use yum's "all" multilib policy.
           excludeWeakdeps -- Whether to exclude weak dependencies.
           timeout       -- Number of seconds to wait for a connection before
                            yum's or dnf's timing out or None.
           retries       -- Number of times yum's or dnf's attempt to retrieve
                            a file should retry before returning an error.
           seen          -- If %packages was ever used in the kickstart file,
                            this attribute will be set to True.

        """
        KickstartObject.__init__(self, *args, **kwargs)

        self.addBase = True
        self.nocore = False
        self.default = False
        self.environment = None
        self.excludedList = []
        self.excludedGroupList = []
        self.excludeDocs = False
        self.groupList = []
        self.handleMissing = constants.KS_MISSING_PROMPT
        self.handleBroken = constants.KS_BROKEN_REPORT
        self.packageList = []
        self.instLangs = None
        self.multiLib = False
        self.excludeWeakdeps = False
        self.timeout = None
        self.retries = None
        self.seen = False
Example #3
0
    def __init__(self, script, *args , **kwargs):
        """Create a new Script instance.  Instance attributes:

           :keyword errorOnFail: If execution of the script fails, should anaconda
                                 stop, display an error, and then reboot without
                                 running any other scripts?

           :keyword inChroot: Does the script execute in anaconda's chroot
                              environment or not?

           :keyword interp: The program that should be used to interpret this
                            script.

           :keyword lineno: The line number this script starts on.

           :keyword logfile: Where all messages from the script should be logged.

           :keyword script: A string containing all the lines of the script.

           :keyword type: The type of the script, which can be KS_SCRIPT_* from
                          :mod:`pykickstart.constants`.
        """
        KickstartObject.__init__(self, *args, **kwargs)
        self.script = "".join(script)

        self.interp = kwargs.get("interp", "/bin/sh")
        self.inChroot = kwargs.get("inChroot", False)
        self.lineno = kwargs.get("lineno", None)
        self.logfile = kwargs.get("logfile", None)
        self.errorOnFail = kwargs.get("errorOnFail", False)
        self.type = kwargs.get("type", constants.KS_SCRIPT_PRE)
Example #4
0
    def __init__(self, *args, **kwargs):
        """Create a new KickstartHandler instance.

           Instance attributes:

           commands -- A mapping from a string command to a KickstartCommand
                       subclass object that handles it.  Multiple strings can
                       map to the same object, but only one instance of the
                       command object should ever exist.  Most users should
                       never have to deal with this directly, as it is
                       manipulated internally and called through dispatcher.
           currentLine -- The current unprocessed line from the input file
                          that caused this handler to be run.
        """
        KickstartObject.__init__(self, *args, **kwargs)

        # These will be set by the dispatcher.
        self.commands = {}
        self.currentLine = ""

        # A dict keyed by an integer priority number, with each value being a
        # list of KickstartCommand subclasses.  This dict is maintained by
        # registerCommand and used in __str__.  No one else should be touching
        # it.
        self._writeOrder = {}
Example #5
0
    def __init__(self, *args, **kwargs):
        """Create a new Packages instance.  Instance attributes:

           addBase       -- Should the Base group be installed even if it is
                            not specified?
           nocore        -- Should the Core group be skipped?  This results in
                            a %packages section that basically only installs the
                            packages you list, and may not be a usable system.
           default       -- Should the default package set be selected?
           environment   -- What base environment should be selected?  Only one
                            may be chosen at a time.
           excludedList  -- A list of all the packages marked for exclusion in
                            the %packages section, without the leading minus
                            symbol.
           excludeDocs   -- Should documentation in each package be excluded?
           groupList     -- A list of Group objects representing all the groups
                            specified in the %packages section.  Names will be
                            stripped of the leading @ symbol.
           excludedGroupList -- A list of Group objects representing all the
                                groups specified for removal in the %packages
                                section.  Names will be stripped of the leading
                                -@ symbols.
           handleMissing -- If unknown packages are specified in the %packages
                            section, should it be ignored or not?  Values can
                            be KS_MISSING_* from pykickstart.constants.
           packageList   -- A list of all the packages specified in the
                            %packages section.
           instLangs     -- A list of languages to install.
           multiLib      -- Whether to use yum's "all" multilib policy.
           excludeWeakdeps -- Whether to exclude weak dependencies.
           timeout       -- Number of seconds to wait for a connection before
                            yum's or dnf's timing out or None.
           retries       -- Number of times yum's or dnf's attempt to retrieve
                            a file should retry before returning an error.
           seen          -- If %packages was ever used in the kickstart file,
                            this attribute will be set to True.

        """
        KickstartObject.__init__(self, *args, **kwargs)

        self.addBase = True
        self.nocore = False
        self.default = False
        self.environment = None
        self.excludedList = []
        self.excludedGroupList = []
        self.excludeDocs = False
        self.groupList = []
        self.handleMissing = constants.KS_MISSING_PROMPT
        self.packageList = []
        self.instLangs = None
        self.multiLib = False
        self.excludeWeakdeps = False
        self.timeout = None
        self.retries = None
        self.seen = False
Example #6
0
    def __init__(self, name="", include=constants.GROUP_DEFAULT):
        """Create a new Group instance.  Instance attributes:

           name    -- The group's identifier
           include -- The level of how much of the group should be included.
                      Values can be GROUP_* from pykickstart.constants.
        """
        KickstartObject.__init__(self)
        self.name = name
        self.include = include
Example #7
0
    def __init__(self, *args, **kwargs):
        """Create a new BaseData instance.

           lineno -- Line number in the ks-file where this object was defined
        """

        # We don't want people using this class by itself.
        if self.__class__ is BaseData:
            raise TypeError("BaseData is an abstract class.")

        KickstartObject.__init__(self, *args, **kwargs)
        self.lineno = 0
Example #8
0
    def __init__(self, *args, **kwargs):
        """Create a new BaseData instance.

           lineno -- Line number in the ks-file where this object was defined
        """

        # We don't want people using this class by itself.
        if self.__class__ is BaseData:
            raise TypeError("BaseData is an abstract class.")

        KickstartObject.__init__(self, *args, **kwargs)
        self.lineno = 0
Example #9
0
    def __init__(
        self,
        writePriority=0,
        *args,
        **kwargs
    ):  # type: (KickstartCommand, Union[None, int], *Any, **Any) -> None
        """Create a new KickstartCommand instance.  This method must be
           provided by all subclasses, but subclasses must call
           KickstartCommand.__init__ first.  Instance attributes:

           currentCmd    -- The name of the command in the input file that
                            caused this handler to be run.
           currentLine   -- The current unprocessed line from the input file
                            that caused this handler to be run.
           handler       -- A reference to the BaseHandler subclass this
                            command is contained withing.  This is needed to
                            allow referencing of Data objects.
           lineno        -- The current line number in the input file.
           seen          -- If this command was ever used in the kickstart file,
                            this attribute will be set to True.  This allows
                            for differentiating commands that were omitted
                            from those that default to unset.
           writePriority -- An integer specifying when this command should be
                            printed when iterating over all commands' __str__
                            methods.  The higher the number, the later this
                            command will be written.  All commands with the
                            same priority will be written alphabetically.
        """

        # We don't want people using this class by itself.
        if self.__class__ is KickstartCommand:
            raise TypeError("KickstartCommand is an abstract class.")

        KickstartObject.__init__(self, *args, **kwargs)

        self.writePriority = writePriority

        # These will be set by the dispatcher.
        self.currentCmd = ""
        self.currentLine = ""
        self.handler = None  # type: Union[None, BaseHandler]
        self.lineno = 0
        self.seen = False

        # If a subclass provides a removedKeywords list, remove all the
        # members from the kwargs list before we start processing it.  This
        # ensures that subclasses don't continue to recognize arguments that
        # were removed.
        for arg in (kw for kw in self.removedKeywords if kw in kwargs):
            kwargs.pop(arg)
Example #10
0
    def __init__(self, *args,
                 **kwargs):  # type: (Packages, *Any, **Any) -> None
        """Create a new Packages instance.  Instance attributes:

           addBase       -- Should the Base group be installed even if it is
                            not specified?
           nocore        -- Should the Core group be skipped?  This results in
                            a %packages section that basically only installs the
                            packages you list, and may not be a usable system.
           default       -- Should the default package set be selected?
           environment   -- What base environment should be selected?  Only one
                            may be chosen at a time.
           excludedList  -- A list of all the packages marked for exclusion in
                            the %packages section, without the leading minus
                            symbol.
           excludeDocs   -- Should documentation in each package be excluded?
           groupList     -- A list of Group objects representing all the groups
                            specified in the %packages section.  Names will be
                            stripped of the leading @ symbol.
           excludedGroupList -- A list of Group objects representing all the
                                groups specified for removal in the %packages
                                section.  Names will be stripped of the leading
                                -@ symbols.
           handleMissing -- If unknown packages are specified in the %packages
                            section, should it be ignored or not?  Values can
                            be KS_MISSING_* from pykickstart.constants.
           packageList   -- A list of all the packages specified in the
                            %packages section.
           instLangs     -- A list of languages to install.
           multiLib      -- Whether to use yum's "all" multilib policy.
           seen          -- If %packages was ever used in the kickstart file,
                            this attribute will be set to True.

        """
        KickstartObject.__init__(self, *args, **kwargs)

        self.addBase = True  # type: bool
        self.nocore = False  # type: bool
        self.default = False  # type: bool
        self.environment = None  # type: Union[None, str]
        self.excludedList = []  # type: List[str]
        self.excludedGroupList = []  # type: List[Group]
        self.excludeDocs = False  # type: bool
        self.groupList = []  # type: List[Group]
        self.handleMissing = constants.KS_MISSING_PROMPT  # type: int
        self.packageList = []  # type: List[str]
        self.instLangs = None  # type: Union[None, List[str]]
        self.multiLib = False  # type: bool
        self.seen = False  # type: bool
Example #11
0
    def __init__(self, *args, **kwargs):    # type: (Packages, *Any, **Any) -> None
        """Create a new Packages instance.  Instance attributes:

           addBase       -- Should the Base group be installed even if it is
                            not specified?
           nocore        -- Should the Core group be skipped?  This results in
                            a %packages section that basically only installs the
                            packages you list, and may not be a usable system.
           default       -- Should the default package set be selected?
           environment   -- What base environment should be selected?  Only one
                            may be chosen at a time.
           excludedList  -- A list of all the packages marked for exclusion in
                            the %packages section, without the leading minus
                            symbol.
           excludeDocs   -- Should documentation in each package be excluded?
           groupList     -- A list of Group objects representing all the groups
                            specified in the %packages section.  Names will be
                            stripped of the leading @ symbol.
           excludedGroupList -- A list of Group objects representing all the
                                groups specified for removal in the %packages
                                section.  Names will be stripped of the leading
                                -@ symbols.
           handleMissing -- If unknown packages are specified in the %packages
                            section, should it be ignored or not?  Values can
                            be KS_MISSING_* from pykickstart.constants.
           packageList   -- A list of all the packages specified in the
                            %packages section.
           instLangs     -- A list of languages to install.
           multiLib      -- Whether to use yum's "all" multilib policy.
           seen          -- If %packages was ever used in the kickstart file,
                            this attribute will be set to True.

        """
        KickstartObject.__init__(self, *args, **kwargs)

        self.addBase = True # type: bool
        self.nocore = False # type: bool
        self.default = False    # type: bool
        self.environment = None # type: Union[None, str]
        self.excludedList = []  # type: List[str]
        self.excludedGroupList = [] # type: List[Group]
        self.excludeDocs = False    # type: bool
        self.groupList = [] # type: List[Group]
        self.handleMissing = constants.KS_MISSING_PROMPT    # type: int
        self.packageList = []   # type: List[str]
        self.instLangs = None   # type: Union[None, List[str]]
        self.multiLib = False   # type: bool
        self.seen = False   # type: bool
Example #12
0
    def __init__(self, *args, **kwargs):
        """Create a new BaseData instance.

           lineno -- Line number in the ks-file where this object was defined
        """

        # We don't want people using this class by itself.
        if self.__class__ is BaseData:
            raise TypeError("BaseData is an abstract class.")

        KickstartObject.__init__(self, *args, **kwargs)
        self.lineno = 0

        # If a subclass provides a removedKeywords list, warn if the user
        # continues to use some of the removed keywords
        for arg in (kw for kw in self.removedKeywords if kw in kwargs):
            warnings.warn("The '%s' keyword has been removed." % arg, KickstartParseWarning, stacklevel=2)
Example #13
0
    def __init__(self, *args, **kwargs):
        """Create a new BaseData instance.

           lineno -- Line number in the ks-file where this object was defined
        """

        # We don't want people using this class by itself.
        if self.__class__ is BaseData:
            raise TypeError("BaseData is an abstract class.")

        KickstartObject.__init__(self, *args, **kwargs)
        self.lineno = 0

        # If a subclass provides a removedKeywords list, warn if the user
        # continues to use some of the removed keywords
        for arg in (kw for kw in self.removedKeywords if kw in kwargs):
            warnings.warn("The '%s' keyword has been removed." % arg, KickstartParseWarning, stacklevel=2)
Example #14
0
    def __init__(self, writePriority=0, *args, **kwargs):
        """Create a new KickstartCommand instance.  This method must be
           provided by all subclasses, but subclasses must call
           KickstartCommand.__init__ first.  Instance attributes:

           currentCmd    -- The name of the command in the input file that
                            caused this handler to be run.
           currentLine   -- The current unprocessed line from the input file
                            that caused this handler to be run.
           handler       -- A reference to the BaseHandler subclass this
                            command is contained withing.  This is needed to
                            allow referencing of Data objects.
           lineno        -- The current line number in the input file.
           seen          -- If this command was ever used in the kickstart file,
                            this attribute will be set to True.  This allows
                            for differentiating commands that were omitted
                            from those that default to unset.
           writePriority -- An integer specifying when this command should be
                            printed when iterating over all commands' __str__
                            methods.  The higher the number, the later this
                            command will be written.  All commands with the
                            same priority will be written alphabetically.
        """

        # We don't want people using this class by itself.
        if self.__class__ is KickstartCommand:
            raise TypeError("KickstartCommand is an abstract class.")

        KickstartObject.__init__(self, *args, **kwargs)

        self.writePriority = writePriority

        # These will be set by the dispatcher.
        self.currentCmd = ""
        self.currentLine = ""
        self.handler = None
        self.lineno = 0
        self.seen = False

        # If a subclass provides a removedKeywords list, remove all the
        # members from the kwargs list before we start processing it.  This
        # ensures that subclasses don't continue to recognize arguments that
        # were removed.
        for arg in (kw for kw in self.removedKeywords if kw in kwargs):
            kwargs.pop(arg)
Example #15
0
    def __init__(self, writePriority=0, *args, **kwargs):
        """Create a new KickstartCommand instance.  This method must be
           provided by all subclasses, but subclasses must call
           KickstartCommand.__init__ first.  Instance attributes:

           currentCmd    -- The name of the command in the input file that
                            caused this handler to be run.
           currentLine   -- The current unprocessed line from the input file
                            that caused this handler to be run.
           handler       -- A reference to the BaseHandler subclass this
                            command is contained withing.  This is needed to
                            allow referencing of Data objects.
           lineno        -- The current line number in the input file.
           seen          -- If this command was ever used in the kickstart file,
                            this attribute will be set to True.  This allows
                            for differentiating commands that were omitted
                            from those that default to unset.
           writePriority -- An integer specifying when this command should be
                            printed when iterating over all commands' __str__
                            methods.  The higher the number, the later this
                            command will be written.  All commands with the
                            same priority will be written alphabetically.
        """

        # We don't want people using this class by itself.
        if self.__class__ is KickstartCommand:
            raise TypeError("KickstartCommand is an abstract class.")

        KickstartObject.__init__(self, *args, **kwargs)

        self.writePriority = writePriority

        # These will be set by the dispatcher.
        self.currentCmd = ""
        self.currentLine = ""
        self.handler = None
        self.lineno = 0
        self.seen = False

        # If a subclass provides a removedKeywords list, warn if the user
        # continues to use some of the removed keywords
        for arg in (kw for kw in self.removedKeywords if kw in kwargs):
            warnings.warn("The '%s' keyword has been removed." % arg,
                          KickstartParseWarning,
                          stacklevel=2)
Example #16
0
    def __init__(self, mapping=None, dataMapping=None, commandUpdates=None,
            dataUpdates=None, *args, **kwargs):
        """Create a new BaseHandler instance.  This method must be provided by
           all subclasses, but subclasses must call BaseHandler.__init__ first.

           mapping          -- A custom map from command strings to classes,
                               useful when creating your own handler with
                               special command objects.  It is otherwise unused
                               and rarely needed.  If you give this argument,
                               the mapping takes the place of the default one
                               and so must include all commands you want
                               recognized.
           dataMapping      -- This is the same as mapping, but for data
                               objects.  All the same comments apply.
           commandUpdates   -- This is similar to mapping, but does not take
                               the place of the defaults entirely.  Instead,
                               this mapping is applied after the defaults and
                               updates it with just the commands you want to
                               modify.
           dataUpdates      -- This is the same as commandUpdates, but for
                               data objects.


           Instance attributes:

           commands -- A mapping from a string command to a KickstartCommand
                       subclass object that handles it.  Multiple strings can
                       map to the same object, but only one instance of the
                       command object should ever exist.  Most users should
                       never have to deal with this directly, as it is
                       manipulated internally and called through dispatcher.
           currentLine -- The current unprocessed line from the input file
                          that caused this handler to be run.
           packages -- An instance of pykickstart.parser.Packages which
                       describes the packages section of the input file.
           platform -- A string describing the hardware platform, which is
                       needed only by system-config-kickstart.
           scripts  -- A list of pykickstart.parser.Script instances, which is
                       populated by KickstartParser.addScript and describes the
                       %pre/%pre-install/%post/%traceback script section of the
                       input file.
        """

        # We don't want people using this class by itself.
        if self.__class__ is BaseHandler:
            raise TypeError("BaseHandler is an abstract class.")

        KickstartObject.__init__(self, *args, **kwargs)

        # This isn't really a good place for these, but it's better than
        # everything else I can think of.
        self.scripts = []
        self.packages = Packages()
        self.platform = ""

        # These will be set by the dispatcher.
        self.commands = {}
        self.currentLine = ""

        # A dict keyed by an integer priority number, with each value being a
        # list of KickstartCommand subclasses.  This dict is maintained by
        # registerCommand and used in __str__.  No one else should be touching
        # it.
        self._writeOrder = {}

        self._registerCommands(mapping, dataMapping, commandUpdates, dataUpdates)
Example #17
0
 def __str__(self):
     """Return a string formatted for output to a kickstart file.  This
        method must be provided by all subclasses.
     """
     return KickstartObject.__str__(self)
Example #18
0
 def __str__(self):
     """Return a string formatted for output to a kickstart file.  This
        method must be provided by all subclasses.
     """
     return KickstartObject.__str__(self)
Example #19
0
    def __init__(self,
                 mapping=None,
                 dataMapping=None,
                 commandUpdates=None,
                 dataUpdates=None,
                 *args,
                 **kwargs):
        """Create a new BaseHandler instance.  This method must be provided by
           all subclasses, but subclasses must call BaseHandler.__init__ first.

           mapping          -- A custom map from command strings to classes,
                               useful when creating your own handler with
                               special command objects.  It is otherwise unused
                               and rarely needed.  If you give this argument,
                               the mapping takes the place of the default one
                               and so must include all commands you want
                               recognized.
           dataMapping      -- This is the same as mapping, but for data
                               objects.  All the same comments apply.
           commandUpdates   -- This is similar to mapping, but does not take
                               the place of the defaults entirely.  Instead,
                               this mapping is applied after the defaults and
                               updates it with just the commands you want to
                               modify.
           dataUpdates      -- This is the same as commandUpdates, but for
                               data objects.


           Instance attributes:

           commands -- A mapping from a string command to a KickstartCommand
                       subclass object that handles it.  Multiple strings can
                       map to the same object, but only one instance of the
                       command object should ever exist.  Most users should
                       never have to deal with this directly, as it is
                       manipulated internally and called through dispatcher.
           currentLine -- The current unprocessed line from the input file
                          that caused this handler to be run.
           packages -- An instance of pykickstart.parser.Packages which
                       describes the packages section of the input file.
           platform -- A string describing the hardware platform, which is
                       needed only by system-config-kickstart.
           scripts  -- A list of pykickstart.parser.Script instances, which is
                       populated by KickstartParser.addScript and describes the
                       %pre/%pre-install/%post/%traceback script section of the
                       input file.
        """

        # We don't want people using this class by itself.
        if self.__class__ is BaseHandler:
            raise TypeError("BaseHandler is an abstract class.")

        KickstartObject.__init__(self, *args, **kwargs)

        # This isn't really a good place for these, but it's better than
        # everything else I can think of.
        self.scripts = []
        self.packages = Packages()
        self.platform = ""

        # These will be set by the dispatcher.
        self.commands = {}
        self.currentLine = ""

        # A dict keyed by an integer priority number, with each value being a
        # list of KickstartCommand subclasses.  This dict is maintained by
        # registerCommand and used in __str__.  No one else should be touching
        # it.
        self._writeOrder = {}

        self._registerCommands(mapping, dataMapping, commandUpdates,
                               dataUpdates)