pykickstart package

Subpackages

Submodules

pykickstart.base module

Base classes for creating commands and syntax version object.

This module exports several important base classes:

BaseData - The base abstract class for all data objects. Data objects

are contained within a BaseHandler object.

BaseHandler - The base abstract class from which versioned kickstart

handler are derived. Subclasses of BaseHandler hold BaseData and KickstartCommand objects.

DeprecatedCommand - An abstract subclass of KickstartCommand that should

be further subclassed by users of this module. When a subclass is used, a warning message will be printed.

RemovedCommand - an abstract subclass of KickstartCommand that should

be subclassed to update the description with the version it was removed in. Any use of the command will raise an error.

KickstartCommand - The base abstract class for all kickstart commands.

Command objects are contained within a BaseHandler object.

class pykickstart.base.BaseData(*args, **kwargs)[source]

Bases: KickstartObject

The base class for all data objects. This is an abstract class.

deleteRemovedAttrs()[source]

Remove all attributes from self that are given in the removedAttrs list. This method should be called from __init__ in a subclass, but only after the superclass’s __init__ method has been called.

removedAttrs = []
removedKeywords = []
class pykickstart.base.BaseHandler(mapping=None, dataMapping=None, commandUpdates=None, dataUpdates=None, *args, **kwargs)[source]

Bases: KickstartHandler

A base kickstart handler.

Each version of kickstart syntax is provided by a subclass of this class. These subclasses are what users will interact with for parsing, extracting data, and writing out kickstart files. This is an abstract class.

hasCommand(cmd)[source]

Return true if there is a handler for the string cmd.

maskAllExcept(lst)[source]

Set all entries in the commands dict to None, except the ones in the lst. All other commands will not be processed.

class pykickstart.base.DeprecatedCommand(writePriority=None, *args, **kwargs)[source]

Bases: KickstartCommand

Specify that a command is deprecated and no longer has any function. Any command that is deprecated should be subclassed from this class, only specifying an __init__ method that calls the superclass’s __init__. This is an abstract class.

property dataClass

Override the attribute of the deprecated command.

dataList()[source]

Override the method of the deprecated command.

parse(args)[source]

Print a warning message if the command is seen in the input file.

class pykickstart.base.KickstartCommand(writePriority=0, *args, **kwargs)[source]

Bases: KickstartObject

The base class for all kickstart commands. This is an abstract class.

conflictingCommands = []
property dataClass

For commands that can occur multiple times in a single kickstart file, return the class that should be used to store the data from each invocation. An instance of this class will be appended to dataList. For all other commands, return None.

dataList()[source]

For commands that can occur multiple times in a single kickstart file (like network, part, etc.), return the list that we should append more data objects to.

deleteRemovedAttrs()[source]

Remove all attributes from self that are given in the removedAttrs list. This method should be called from __init__ in a subclass, but only after the superclass’s __init__ method has been called.

parse(args)[source]

Parse the list of args and set data on the KickstartCommand object. This method must be provided by all subclasses.

removedAttrs = []
removedKeywords = []
set_to_obj(namespace, obj)[source]

Sets the contents of the namespace object (an instance of argparse.Namespace returned by parse_arguments) as attributes on the provided object obj. It’s useful to call this from KickstartCommand subclasses that handle lists of objects (like partitions, network devices, etc.) and need to populate a Data object.

set_to_self(namespace)[source]

Set the contents of the namespace object (an instance of argparse.Namespace returned by parse_arguments) as attributes on the KickstartCommand object. It’s useful to call this from KickstartCommand subclasses after parsing the arguments.

class pykickstart.base.KickstartHandler(*args, **kwargs)[source]

Bases: KickstartObject

An empty kickstart handler.

This handler doesn’t handle anything by default.

version – The version this syntax handler supports. This is set by

a class attribute of a KickstartHandler subclass and is used to set up the command dict. It is for read-only use.

dispatcher(args, lineno)[source]

Call the appropriate KickstartCommand handler for the current line in the kickstart file. A handler for the current command should be registered, though a handler of None is not an error. Returns the data object returned by KickstartCommand.parse.

args – A list of arguments to the current command lineno – The line number in the file, for error reporting

registerCommand(cmdName, cmdClass)[source]
registerData(dataName, dataClass)[source]
resetCommand(cmdName)[source]

Given the name of a command that’s already been instantiated, create a new instance of it that will take the place of the existing instance. This is equivalent to quickly blanking out all the attributes that were previously set.

This method raises a KeyError if cmdName is invalid.

version = None
class pykickstart.base.RemovedCommand(writePriority=None, *args, **kwargs)[source]

Bases: KickstartCommand

Specify that a command has been removed and no longer has any function. Any command that is removed should be subclassed from this class, and should set its description to add the version that the command was removed in. This is an abstract class.

property dataClass

Override the attribute of the removed command.

dataList()[source]

Override the method of the removed command.

parse(args)[source]

Raise an error if the command is found in the input file

pykickstart.constants module

pykickstart.errors module

Error and warning handling classes and functions.

This module exports several exception classes:

KickstartError - A generic exception class.

KickstartParseError - An exception for errors occurring during parsing.

KickstartValueError - No longer raised by pykickstart, but kept around for

backwards compatibility.

KickstartVersionError - An exception for errors relating to unsupported

syntax versions.

And some warning classes:

KickstartWarning - A generic warning class.

KickstartParseWarning - A class for warnings occurring during parsing.

KickstartDeprecationWarning - A class for warnings occurring during parsing

related to deprecated commands and options.

exception pykickstart.errors.KickstartDeprecationWarning[source]

Bases: KickstartParseWarning, DeprecationWarning

A class for warnings occurring during parsing related to using deprecated commands and options.

exception pykickstart.errors.KickstartError(msg='', lineno=None, formatting=True)[source]

Bases: Exception

A generic exception class for unspecific error conditions.

exception pykickstart.errors.KickstartParseError(msg='', lineno=None, formatting=True)[source]

Bases: KickstartError

An exception class for errors when processing the input file, such as unknown options, commands, or sections.

exception pykickstart.errors.KickstartParseWarning[source]

Bases: KickstartWarning, UserWarning

A class for warnings occurring during parsing an input file, such as defining duplicate entries and setting removed keywords.

exception pykickstart.errors.KickstartValueError(msg='', lineno=None, formatting=True)[source]

Bases: KickstartError

This exception class is no longer raised by pykickstart but is kept for backwards compatibility.

exception pykickstart.errors.KickstartVersionError(msg='', lineno=None, formatting=True)[source]

Bases: KickstartError

An exception class for errors related to using an incorrect version of kickstart syntax.

exception pykickstart.errors.KickstartWarning[source]

Bases: Warning

A generic warning class for unspecific conditions.

pykickstart.errors.formatErrorMsg(lineno, msg='')[source]

This function is deprecated. KickstartError formats the error message now, so this function returns a tuple that can be formatted by KickstartError.

You should call: KickstartError(message, lineno=lineno)

But the deprecated way is still supported: KickstartError(formatErrorMsg(message, lineno=lineno))

pykickstart.i18n module

pykickstart.ko module

Base classes for internal pykickstart use.

The module exports the following important classes:

KickstartObject - The base class for all classes in pykickstart

class pykickstart.ko.KickstartObject(*args, **kwargs)[source]

Bases: object

The base class for all other classes in pykickstart.

pykickstart.load module

pykickstart.load.is_url(location)
pykickstart.load.load_to_file(location, destination)[source]

Load a destination URL or file into a file name. Type of input is inferred automatically.

Arguments: location – URL or file name to load destination – destination file name to write to

Returns: file name with contents Raises: KickstartError on error reading or writing

pykickstart.load.load_to_str(location)[source]

Load a destination URL or file into a string. Type of input is inferred automatically.

Arguments: location – URL or file name to load

Returns: string with contents Raises: KickstartError on error reading

pykickstart.options module

Specialized option handling.

This module exports three classes:

ExtendAction - A subclass of Action that appends a list of values to an

already existing list. In this way, it’s like the existing “append” action except for lists instead of single values.

ExtendConstAction - A subclass of Action that appends a list of constants

to an already existing list. In this way, it’s like the existing “append_const” action except for lists instead of single values.

KSOptionParser - A specialized subclass of ArgumentParser to be used

in BaseHandler subclasses.

And it exports two functions:

commaSplit - A function to be used as the type= argument to any arguments

that take a single string that may be split on commas, resulting in a list of strings.

ksboolean - A function to be used as the type= argument to any arguments

that can take a boolean.

class pykickstart.options.ExtendAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: Action

class pykickstart.options.ExtendConstAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: Action

class pykickstart.options.KSHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]

Bases: RawTextHelpFormatter

Used in generating documentation

class pykickstart.options.KSOptionParser(*args, **kwargs)[source]

Bases: ArgumentParser

A specialized subclass of argparse.ArgumentParser to handle extra option attribute checking, work error reporting into the KickstartParseError framework, and to turn off the default help.

add_argument(dest, ..., name=value, ...)[source]
add_argument(option_string, option_string, ..., name=value, ...) None
error(message: string)[source]

Prints a usage message incorporating the message to stderr and exits.

If you override this in a subclass, it should not return – it should either exit or raise an exception.

exit(status=0, message=None)[source]
parse_args(*args, **kwargs)[source]
parse_known_args(*args, **kwargs)[source]
remove_argument(arg, **kwargs)[source]
pykickstart.options.commaSplit(value)[source]
pykickstart.options.ksboolean(value)[source]
pykickstart.options.mountpoint(value)[source]

pykickstart.parser module

Main kickstart file processing module.

This module exports several important classes:

Script - Representation of a single %pre, %pre-install, %post, or %traceback script.

Packages - Representation of the %packages section.

KickstartParser - The kickstart file parser state machine.

class pykickstart.parser.Group(name='', include=1)[source]

Bases: KickstartObject

A class representing a single group in the %packages section.

class pykickstart.parser.KickstartParser(handler, followIncludes=True, errorsAreFatal=True, missingIncludeIsFatal=True, unknownSectionIsFatal=True)[source]

Bases: object

The kickstart file parser class as represented by a basic state machine. To create a specialized parser, make a subclass and override any of the methods you care about. Methods that don’t need to do anything may just pass. However, _stateMachine should never be overridden.

getSection(s)[source]

Return a reference to the requested section (s must start with ‘%’s), or raise KeyError if not found.

handleCommand(lineno, args)[source]

Given the list of command and arguments, call the Version’s dispatcher method to handle the command. Returns the command or data object returned by the dispatcher. This method may be overridden in a subclass if necessary.

readKickstart(f, reset=True)[source]

Process a kickstart file, given by the filename f.

readKickstartFromString(s, reset=True)[source]

Process a kickstart file, provided as the string str.

registerSection(obj)[source]

Given an instance of a Section subclass, register the new section with the parser. Calling this method means the parser will recognize your new section and dispatch into the given object to handle it.

setupSections()[source]

Install the sections all kickstart files support. You may override this method in a subclass, but should avoid doing so unless you know what you’re doing.

class pykickstart.parser.Packages(*args, **kwargs)[source]

Bases: KickstartObject

add(pkgList)[source]

Given a list of lines from the input file, strip off any leading symbols and add the result to the appropriate list.

class pykickstart.parser.PutBackIterator(iterable)[source]

Bases: Iterator

next()[source]
put(s)[source]
class pykickstart.parser.Script(script, *args, **kwargs)[source]

Bases: KickstartObject

pykickstart.parser.preprocessFromString(s)[source]

Preprocess the kickstart file, provided as the string s. This method is currently only useful for handling %ksappend lines, which need to be fetched before the real kickstart parser can be run. Returns the location of the complete kickstart file.

pykickstart.parser.preprocessFromStringToString(s)[source]

Preprocess the kickstart file, provided as the string s. This method is currently only useful for handling %ksappend lines, which need to be fetched before the real kickstart parser can be run. Returns the complete kickstart file as a string.

pykickstart.parser.preprocessKickstart(f)[source]

Preprocess the kickstart file, given by the filename f. This method is currently only useful for handling %ksappend lines, which need to be fetched before the real kickstart parser can be run. Returns the location of the complete kickstart file.

pykickstart.parser.preprocessKickstartToString(f)[source]

Preprocess the kickstart file, given by the filename f. This method is currently only useful for handling %ksappend lines, which need to be fetched before the real kickstart parser can be run. Returns the complete kickstart file as a string.

pykickstart.sections module

This module exports the classes that define a section of a kickstart file. A section is a chunk of the file starting with a %tag and ending with a %end. Examples of sections include %packages, %pre, and %post.

You may use this module to define your own custom sections which will be treated just the same as a predefined one by the kickstart parser. All that is necessary is to create a new subclass of Section and call parser.registerSection with an instance of your new class.

class pykickstart.sections.NullSection(*args, **kwargs)[source]

Bases: Section

This defines a section that pykickstart will recognize but do nothing with. If the parser runs across a %section that has no object registered, it will raise an error. Sometimes, you may want to simply ignore those sections instead. This class is useful for that purpose.

allLines = True
finalize()[source]

This method is called when the %end tag for a section is seen. It is not required to be provided.

handleHeader(lineno, args)[source]

This method is called when the opening tag for a section is seen. Not all sections will need this method, though all provided with kickstart include one.

Arguments:

args – A list of all strings passed as arguments to the section

opening tag.

handleLine(line)[source]

This method is called for every line of a section. Take whatever action is appropriate. While this method is not required to be provided, not providing it does not make a whole lot of sense.

Arguments:

line – The complete line, with any trailing newline.

class pykickstart.sections.OnErrorScriptSection(*args, **kwargs)[source]

Bases: ScriptSection

sectionOpen = '%onerror'
class pykickstart.sections.PackageSection(handler, **kwargs)[source]

Bases: Section

handleHeader(lineno, args)[source]

Process the arguments to the %packages header and set attributes on the Version’s Packages instance appropriate. This method may be overridden in a subclass if necessary.

handleLine(line)[source]

This method is called for every line of a section. Take whatever action is appropriate. While this method is not required to be provided, not providing it does not make a whole lot of sense.

Arguments:

line – The complete line, with any trailing newline.

sectionOpen = '%packages'
class pykickstart.sections.PostScriptSection(*args, **kwargs)[source]

Bases: ScriptSection

sectionOpen = '%post'
class pykickstart.sections.PreInstallScriptSection(*args, **kwargs)[source]

Bases: ScriptSection

sectionOpen = '%pre-install'
class pykickstart.sections.PreScriptSection(*args, **kwargs)[source]

Bases: ScriptSection

sectionOpen = '%pre'
class pykickstart.sections.ScriptSection(*args, **kwargs)[source]

Bases: Section

allLines = True
finalize()[source]

This method is called when the %end tag for a section is seen. It is not required to be provided.

handleHeader(lineno, args)[source]

Process the arguments to a %pre/%post/%traceback header for later setting on a Script instance once the end of the script is found. This method may be overridden in a subclass if necessary.

handleLine(line)[source]

This method is called for every line of a section. Take whatever action is appropriate. While this method is not required to be provided, not providing it does not make a whole lot of sense.

Arguments:

line – The complete line, with any trailing newline.

class pykickstart.sections.Section(handler, **kwargs)[source]

Bases: object

The base class for defining kickstart sections. You are free to subclass this as appropriate.

Class attributes:

allLines – Does this section require the parser to call handleLine

for every line in the section, even blanks and comments?

sectionOpen – The string that denotes the start of this section. You

must start your tag with a percent sign.

timesSeen – This attribute is for informational purposes only. It is

incremented every time handleHeader is called to keep track of the number of times a section of this type is seen.

allLines = False
finalize()[source]

This method is called when the %end tag for a section is seen. It is not required to be provided.

handleHeader(lineno, args)[source]

This method is called when the opening tag for a section is seen. Not all sections will need this method, though all provided with kickstart include one.

Arguments:

args – A list of all strings passed as arguments to the section

opening tag.

handleLine(line)[source]

This method is called for every line of a section. Take whatever action is appropriate. While this method is not required to be provided, not providing it does not make a whole lot of sense.

Arguments:

line – The complete line, with any trailing newline.

sectionOpen = ''
property seen

This property is given for consistency with KickstartCommand objects only. It simply returns whether timesSeen is non-zero.

timesSeen = 0
class pykickstart.sections.TracebackScriptSection(*args, **kwargs)[source]

Bases: OnErrorScriptSection

handleHeader(lineno, args)[source]

Process the arguments to a %pre/%post/%traceback header for later setting on a Script instance once the end of the script is found. This method may be overridden in a subclass if necessary.

sectionOpen = '%traceback'

pykickstart.version module

Methods for working with kickstart versions.

This module defines several symbolic constants that specify kickstart syntax versions. Each version corresponds roughly to one release of Red Hat Linux, Red Hat Enterprise Linux, or Fedora Core as these are where most syntax changes take place.

This module also exports several functions:

makeVersion - Given a version number, return an instance of the

matching handler class.

returnClassForVersion - Given a version number, return the matching

handler class. This does not return an instance of that class, however.

stringToVersion - Convert a string representation of a version number

into the symbolic constant.

versionToString - Perform the reverse mapping.

versionToLongString - Perform the reverse mapping but use long names.

versionFromFile - Read a kickstart file and determine the version of

syntax it uses. This requires the kickstart file to have a version= comment in it.

pykickstart.version.getVersionFromCommandClass(cls)[source]
pykickstart.version.isRHEL(version)[source]
pykickstart.version.makeVersion(version=40000)[source]

Return a new instance of the syntax handler for version. version can be either a string or the matching constant. This function is useful for standalone programs which just need to handle a specific version of kickstart syntax (as provided by a command line argument, for example) and need to instantiate the correct object.

pykickstart.version.returnClassForVersion(version=40000)[source]

Return the class of the syntax handler for version. version can be either a string or the matching constant. Raises KickstartVersionError if version does not match anything.

pykickstart.version.stringToVersion(s)[source]

Convert string into one of the provided version constants. Raises KickstartVersionError if string does not match anything.

pykickstart.version.versionFromFile(f)[source]

Given a file or URL, look for a line starting with #version= and return the version number. If no version is found, return DEVEL.

pykickstart.version.versionToLongString(version)[source]

Convert version into a long string representation.

pykickstart.version.versionToString(version, skipDevel=False)[source]

Convert version into a string representation of the version number. This is the reverse operation of stringToVersion. Raises KickstartVersionError if version does not match anything.

Module contents