Mini Shell

Direktori : /lib/python3.6/site-packages/pykickstart/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/pykickstart/__pycache__/base.cpython-36.pyc

3

�
Ld`�@s�dZddlmZddlZddlZddlmZmZmZddl	m
Z
ddlmZddl
mZGdd	�d	e
�ZGd
d�de�ZGdd
�d
e
�ZGdd�de�ZGdd�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@sveZdZdZgZgZddd�Zdd�Zdd�Zd	d
�Z	dd�Z
ed
d��Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�KickstartCommandzFThe base class for all kickstart commands.  This is an abstract class.rcs~|jtkrtd��tj|f|���||_d|_d|_d|_d|_	d|_
x0�fdd�|jD�D]}tj
d|td	d
�q^WdS)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.�NrFc3s|]}|�kr|VqdS)N�)�.0�kw)�kwargsr�/usr/lib/python3.6/base.py�	<genexpr>csz,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)rrr:s
zKickstartCommand.__init__cOsFd|_x:t|j��D]*\}}||jkr(qt||�rt|||�qWdS)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)rr r�key�valrrr�__call__fs

zKickstartCommand.__call__cCs
tj|�S)z~Return a string formatted for output to a kickstart file.  This
           method must be provided by all subclasses.
        )r�__str__)rrrrr*vszKickstartCommand.__str__cCstd��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)rr rrr�parse}szKickstartCommand.parsecCsdS)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)rrrr�dataList�szKickstartCommand.dataListcCsdS)aFor 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)rrrr�	dataClass�szKickstartCommand.dataClasscs,x&�fdd��jD�D]}t�|�qWdS)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.
        csg|]}t�|�r|�qSr)r%)r�k)rrr�
<listcomp>�sz7KickstartCommand.deleteRemovedAttrs.<locals>.<listcomp>N)r$�delattr)r�attrr)rr�deleteRemovedAttrs�sz#KickstartCommand.deleteRemovedAttrscCs|j||�dS)aSet 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�	namespacerrr�set_to_self�szKickstartCommand.set_to_selfcCstjdtdd�|j|�dS)Nz^_setToSelf has been renamed to set_to_self.  The old name will be removed in a future release.r)r)rr�PendingDeprecationWarningr5)rr4rrr�
_setToSelf�szKickstartCommand._setToSelfcCs2x,t|�j�D]\}}|dk	rt|||�qWdS)amSets 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&)rr4�objr'r(rrrr3�szKickstartCommand.set_to_objcCs tjdtdd�|j||�dS)Nz\_setToObj has been renamed to set_to_obj.  The old name will be removed in a future release.r)r)rrr6r3)rr4r9rrr�	_setToObj�szKickstartCommand._setToObjN)r)�__name__�
__module__�__qualname__�__doc__rr$rr)r*r+r,�propertyr-r2r5r7r3r:rrrrr	5s
,		r	c@s>eZdZdZd
dd�Zdd�Zedd��Zd	d
�Zdd�Z	dS)�DeprecatedCommandaSpecify 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.
    NcOs*|jtkrtd��tj||f|�|�dS)Nz'DeprecatedCommand is an abstract class.)rr@rr	r)rrr rrrrr�s
zDeprecatedCommand.__init__cCsdS)z.Override the method of the deprecated command.Nr)rrrrr,�szDeprecatedCommand.dataListcCsdS)z1Override the attribute of the deprecated command.Nr)rrrrr-�szDeprecatedCommand.dataClasscCsdS)z8Placeholder since DeprecatedCommands don't work anymore.r
r)rrrrr*�szDeprecatedCommand.__str__cCs&|j|jd�}tjtd�|t�dS)zAPrint a warning message if the command is seen in the input file.)r�cmda
Ignoring deprecated command on line %(lineno)s:  The %(cmd)s command has been deprecated and no longer has any effect.  It may be removed from future releases, which will result in a fatal error from kickstart.  Please modify your kickstart file to remove this command.N)rrrrrr)rr �mappingrrrr+�szDeprecatedCommand.parse)N)
r;r<r=r>rr,r?r-r*r+rrrrr@�s
r@c@sTeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�ZdS)�KickstartHandlera=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.
    NcOs(tj|f|�|�i|_d|_i|_dS)a�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.
        r
N)rr�commandsr�_writeOrder)rr rrrrr�szKickstartHandler.__init__cCsnd}t|jj��}|j�xN|D]F}x@|j|D]2}|j�}t|tj�rZtjrZ|j	d�}||7}q0Wq W|S)z9Return a string formatted for output to a kickstart file.r
zutf-8)
r"rE�keys�sortr*�
isinstance�six�	text_type�PY3�encode)r�retval�lstZprior9Zobj_strrrrr*s

zKickstartHandler.__str__cCs�t|�}d}x`||krl|jj||jjkr4|d7}q|jj||jjkrT|||<dS|jj||jjkrPqW||kr�|j|�n|j||�dS)Nr�)�lenrr;�append�insert)rrNr9Zlength�irrr�
_insertSorteds

zKickstartHandler._insertSortedcCs�|jjjd�dkr6|jjjdd�d}tjsPt|�}n|jjj�}tjsPt|�}t||j�|�|j	dk	r�|j	|j
kr�|j|j
|j	|�n|g|j
|j	<dS)NrrO���)rr;�find�splitrIrKZunicode�lowerr&rrErT)r�cmdObj�namerrr�_setCommand&s

zKickstartHandler._setCommandcCsfd}x.t|jj��D]\}}|jj|jkr|}PqW|dkrL|�}|j|�||j|<||j|_dS)N)r"rDr#rr;r[r)r�cmdName�cmdClassrYZ_keyr(rrr�registerCommand<s

z KickstartHandler.registerCommandcCst|||�dS)N)r&)r�dataNamer-rrr�registerDataSszKickstartHandler.registerDatacCs@||jkrt�|j|j�}|j|�||j|<||j|_dS)aPGiven 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.
        N)rD�KeyErrorrr[r)rr\rYrrr�resetCommandWs


zKickstartHandler.resetCommandcCs�|d}||jkr(ttd�||d��n�|j|dk	r�||j|_|j|j|_||j|_d|j|_|j|j|dd��}|j|j�}t	|t
�r�|dk	r�|j|�|SdS)a�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
        rzUnknown command: %s)rNTrO)rDrrrrrrr+r,rH�BaseDatarQ)rr rrAr9rNrrr�
dispatcherhs	

zKickstartHandler.dispatcher)
r;r<r=r>�versionrr*rTr[r^r`rbrdrrrrrC�srCc@s<eZdZdZd
dd�Zdd�Zddd�Zd	d
�Zdd�ZdS)�BaseHandleraA 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.
    NcOsR|jtkrtd��tj|f|�|�g|_t�|_d|_g|_	|j
||||�dS)aGCreate 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:

           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.
        z!BaseHandler is an abstract class.r
N)rrfrrCr�scriptsr�packages�platform�_null_section_strings�_registerCommands)rrB�dataMapping�commandUpdates�dataUpdatesr rrrrr�s$
zBaseHandler.__init__cCs�d}|jr|d|j7}|dt|j�7}|tj|�7}x<|jD]2}|j�}t|tj�rjtj	rj|j
d�}||7}q@W|jr�|d7}x|jD]}||7}q�W||jj�7}|S)z9Return a string formatted for output to a kickstart file.r
z
#platform=%s
z#version=%s
zutf-8�
)
rirrerCr*rgrHrIrJrKrLrjrh)rrMZscriptZ
script_str�srrrr*�s 
zBaseHandler.__str__c
Cs�|iks|dkr(ddlm}||j}n|}|iks<|dkrTddlm}||j}n|}t|t�rtt|�}|j|�t|t�r�t|�}|j|�x$t|j��D]\}	}
|j	|	|
�q�Wx$t|j��D]\}}|j
||�q�WdS)Nr)�
commandMap)�dataMap)Zpykickstart.handlers.controlrqrerrrH�dict�updater"r#r^r`)
rrBrlrmrnrqZcMaprrZdMapr\r]r_r-rrrrk�s$



zBaseHandler._registerCommandscCs8i|_x,t|jj��D]\}}||krd|j|<qWdS)z�Set all entries in the commands dict to None, except the ones in
           the lst.  All other commands will not be processed.
        N)rEr"rDr#)rrNr'Z_valrrr�
maskAllExceptszBaseHandler.maskAllExceptcCs
t||�S)z5Return true if there is a handler for the string cmd.)r%)rrArrr�
hasCommandszBaseHandler.hasCommand)NNNN)NNNN)	r;r<r=r>rr*rkrurvrrrrrf�s
6

rfc@s8eZdZdZgZgZdd�Zdd�Zdd�Zdd	�Z	d
S)rcz@The base class for all data objects.  This is an abstract class.cs`|jtkrtd��tj|f|���d|_x0�fdd�|jD�D]}tjd|t	dd�q@WdS)	zwCreate a new BaseData instance.

           lineno -- Line number in the ks-file where this object was defined
        zBaseData is an abstract class.rc3s|]}|�kr|VqdS)Nr)rr
)rrrr+sz$BaseData.__init__.<locals>.<genexpr>z"The '%s' keyword has been removed.r)rN)
rrcrrrrrrrr)rr rr!r)rrrs
zBaseData.__init__cCsdS)z9Return a string formatted for output to a kickstart file.r
r)rrrrr*.szBaseData.__str__cOs@x:t|j��D]*\}}||jkr"qt||�rt|||�qWdS)z�Set multiple attributes on a subclass of BaseData at once via
           keyword arguments.  Valid attributes are anything specified in a
           subclass, but unknown attributes will be ignored.
        N)r"r#r$r%r&)rr rr'r(rrrr)2s


zBaseData.__call__cs,x&�fdd��jD�D]}t�|�qWdS)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.
        csg|]}t�|�r|�qSr)r%)rr.)rrrr/Esz/BaseData.deleteRemovedAttrs.<locals>.<listcomp>N)r$r0)rr1r)rrr2@szBaseData.deleteRemovedAttrsN)
r;r<r=r>rr$rr*r)r2rrrrrcsrc)r>Zpykickstart.i18nrrIrZpykickstart.errorsrrrZpykickstart.korZpykickstart.versionrZpykickstart.parserrr	r@rCrfrcrrrr�<module>(s#0