Mini Shell
3
�
Ld` � @ s� d Z ddlmZ ddlZddlZddlmZmZmZ ddl m
Z
ddlmZ ddl
mZ G dd � d e
�ZG d
d� de�ZG dd
� d
e
�ZG dd� de�ZG dd� de
�ZdS )a{
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.
KickstartCommand - The base abstract class for all kickstart commands.
Command objects are contained within a BaseHandler
object.
� )�_N)�KickstartParseError�KickstartParseWarning�KickstartDeprecationWarning)�KickstartObject)�versionToString)�Packagesc @ sv e Zd ZdZg Zg Zddd�Zdd� Zdd� Zd d
� Z dd� Z
ed
d� �Zdd� Z
dd� Zdd� Zdd� Zdd� ZdS )�KickstartCommandzFThe base class for all kickstart commands. This is an abstract class.r c s~ | j tkrtd��tj| f|�� � || _d| _d| _d| _d| _ d| _
x0� fdd�| jD �D ]}tj
d| td d
� q^W dS )a� 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.
z&KickstartCommand is an abstract class.� Nr Fc 3 s | ]}|� kr|V qd S )N� )�.0�kw)�kwargsr �/usr/lib/python3.6/base.py� <genexpr>c s z,KickstartCommand.__init__.<locals>.<genexpr>z"The '%s' keyword has been removed.� )�
stacklevel)� __class__r � TypeErrorr �__init__�
writePriority�
currentCmd�currentLine�handler�lineno�seen�removedKeywords�warnings�warnr )�selfr �argsr �argr )r r r : s
zKickstartCommand.__init__c O sF d| _ x:t|j� �D ]*\}}|| jkr(qt| |�rt| ||� qW dS )z�Set multiple attributes on a subclass of KickstartCommand at once
via keyword arguments. Valid attributes are anything specified in
a subclass, but unknown attributes will be ignored.
TN)r �list�items�removedAttrs�hasattr�setattr)r r r �key�valr r r �__call__f s
zKickstartCommand.__call__c C s
t j| �S )z~Return a string formatted for output to a kickstart file. This
method must be provided by all subclasses.
)r �__str__)r r r r r* v s zKickstartCommand.__str__c C s t d��dS )z�Parse the list of args and set data on the KickstartCommand object.
This method must be provided by all subclasses.
z,parse() not implemented for KickstartCommandN)r )r r r r r �parse} s zKickstartCommand.parsec C s dS )z�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.
Nr )r r r r �dataList� s zKickstartCommand.dataListc C s dS )a 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.
Nr )r r r r � dataClass� s zKickstartCommand.dataClassc s, x&� fdd�� j D �D ]}t� |� qW dS )z�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.
c s g | ]}t � |�r|�qS r )r% )r �k)r r r �
<listcomp>� s z7KickstartCommand.deleteRemovedAttrs.<locals>.<listcomp>N)r$ �delattr)r �attrr )r r �deleteRemovedAttrs� s z#KickstartCommand.deleteRemovedAttrsc C s | j || � dS )a 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.
N)�
set_to_obj)r � namespacer r r �set_to_self� s zKickstartCommand.set_to_selfc C s t jdtdd� | j|� d S )Nz^_setToSelf has been renamed to set_to_self. The old name will be removed in a future release.r )r )r r �PendingDeprecationWarningr5 )r r4 r r r �
_setToSelf� s zKickstartCommand._setToSelfc C s2 x,t |�j� D ]\}}|dk rt|||� qW dS )am 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.
N)�varsr# r&