Mini Shell

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

3

�
Ld���@srdZddlmZddlmZddlZddlZddlZddlZddl	Z	yddl
mZWn ek
rtddl
mZYnXddlmZmZddlmZmZmZddlmZdd	lmZdd
lmZddlmZmZmZmZm Z m!Z!m"Z"ddl#m$Z$d
Z%dZ&dd�Z'dd�Z(dd�Z)dd�Z*dd�Z+Gdd�de�Z,Gdd�de�Z-Gdd�de�Z.Gdd �d e�Z/Gd!d"�d"e0�Z1dS)#a+
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.
�)�print_function)�IteratorN)�
OrderedSet)�	constants�version)�KickstartError�KickstartParseError�KickstartParseWarning)�KickstartObject)�load_to_str)�KSOptionParser)�PackageSection�PreScriptSection�PreInstallScriptSection�PostScriptSection�TracebackScriptSection�OnErrorScriptSection�NullSection)�_�endZcommandscCs.d}d}d}tjr |jtj��}�xyt|�}Wntk
rFPYnX|dkrRP|d7}d}|j�}|jd�s�tjr�|jtj��}||7}q$y|j	d�d}Wn t
td�||d��YnXyt|�}Wn<t
k
�r
}zt
td�t|�|d��WYdd}~XnX|dk	r$||jtj��7}q$W|S)	Nr��z	%ksappend� zIllegal url for %%ksappend: %s)�linenoz"Unable to open %%ksappend file: %s)�sixZPY3�encode�sys�getdefaultencoding�next�
StopIteration�strip�
startswith�splitrrrr�str)�lineIter�lr�retvalZksurlZll�contents�e�r)�/usr/lib/python3.6/parser.py�_preprocessStateMachine<s>
*r+cCst|jd�dg�}t|�S)a
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.
    Tr)�iter�
splitlinesr+)�s�ir)r)r*�preprocessFromStringToStringksr0cCsZyt|�}Wn:tk
rF}zttd�t|�dd��WYdd}~XnXtt|jd���S)a
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.
    z'Unable to open input kickstart file: %sr)rNT)rrrr#r+r,r-)�fr'r(r)r)r*�preprocessKickstartToStringts
*r2cCsDt|�}|r@ddl}|jddd�\}}tj||�tj|�|SdS)aPreprocess 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.
    rNz-ks.cfgrz/tmp)r0�tempfile�mkstemp�os�write�close)r.r3�outF�outNamer)r)r*�preprocessFromString�s
r:cCsDt|�}|r@ddl}|jddd�\}}tj||�tj|�|SdS)aPreprocess 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.
    rNz-ks.cfgrz/tmp)r2r3r4r5r6r7)r1r.r3r8r9r)r)r*�preprocessKickstart�s
r;c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�PutBackIteratorcCst|�|_d|_dS)N)r,�	_iterable�_buf)�self�iterabler)r)r*�__init__�s
zPutBackIterator.__init__cCs|S)Nr))r?r)r)r*�__iter__�szPutBackIterator.__iter__cCs
||_dS)N)r>)r?r.r)r)r*�put�szPutBackIterator.putcCs$|jr|j}d|_|St|j�SdS)N)r>rr=)r?r&r)r)r*r�s
zPutBackIterator.nextcCs|j�S)N)r)r?r)r)r*�__next__�szPutBackIterator.__next__N)�__name__�
__module__�__qualname__rArBrCrrDr)r)r)r*r<�s
r<c@s"eZdZejZdd�Zdd�ZdS)�ScriptcOsxtj|f|�|�dj|�|_|jdd�|_|jdd�|_|jdd�|_|jdd�|_|jd	d�|_	|jd
t
j�|_dS)a|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`.
        r�interpz/bin/sh�inChrootFrN�logfile�errorOnFail�type)
r
rA�join�script�getrIrJrrKrLr�
KS_SCRIPT_PRErM)r?rO�args�kwargsr)r)r*rA�szScript.__init__cCs6d}|jtjkr|d7}nV|jtjkr0|d7}n@|jtjkrF|d7}n*|jtjkr\|d7}n|jtjkrp|d7}|jdkr�|jr�|d|j7}|jtjkr�|jr�|d	7}|j	d
k	r�|d|j	7}|j
r�|d7}|jjd
��r|j
tjkr�|d|jS|d|jSn*|j
tjk�r$|d|jS|d|jSd
S)z9Return a string formatted for output to a kickstart file.rz
%prez
%postz
%tracebackz
%pre-installz	
%onerrorz/bin/shz --interpreter=%sz --nochrootNz
 --logfile=%sz --erroronfail�
z	
%s%%end
z
%sz

%s
%%end
z
%s
)rMrrQZKS_SCRIPT_POSTZKS_SCRIPT_TRACEBACKZKS_SCRIPT_PREINSTALLZKS_SCRIPT_ONERRORrIrJrKrLrO�endswith�_verr�F8)r?r&r)r)r*�__str__�s4




zScript.__str__N)rErFrGr�DEVELrVrArXr)r)r)r*rH�s rHc@s^eZdZdZdejfdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
ejZdS)�Groupz=A class representing a single group in the %packages section.rcCstj|�||_||_dS)z�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.
        N)r
rA�name�include)r?r[r\r)r)r*rA
s
zGroup.__init__cCs:|jtjkrd|jS|jtjkr,d|jSd|jSdS)z9Return a string formatted for output to a kickstart file.z@%s --nodefaultsz@%s --optionalz@%sN)r\r�GROUP_REQUIREDr[�	GROUP_ALL)r?r)r)r*rXs


z
Group.__str__cCs|j|jkS)N)r[)r?�otherr)r)r*�__lt__!szGroup.__lt__cCs|j|jkS)N)r[)r?r_r)r)r*�__le__$szGroup.__le__cCs|j|jkS)N)r[)r?r_r)r)r*�__eq__'szGroup.__eq__cCs|j|jkS)N)r[)r?r_r)r)r*�__ne__*szGroup.__ne__cCs|j|jkS)N)r[)r?r_r)r)r*�__gt__-szGroup.__gt__cCs|j|jkS)N)r[)r?r_r)r)r*�__ge__0szGroup.__ge__N)rErFrG�__doc__r�
GROUP_DEFAULTrArXr`rarbrcrdrer
�__hash__r)r)r)r*rZs	rZc@s2eZdZejZdd�Zdd�Zdd�Zdd�Z	d	S)
�PackagescOsxtj|f|�|�d|_d|_d|_d|_g|_g|_d|_g|_	t
j|_g|_
d|_d|_d|_d|_d|_d|_dS)aO	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.

        TFN)r
rA�addBase�nocore�default�environment�excludedList�excludedGroupList�excludeDocs�	groupListrZKS_MISSING_PROMPT�
handleMissing�packageList�	instLangs�multiLib�excludeWeakdeps�timeout�retries�seen)r?rRrSr)r)r*rA9s"&zPackages.__init__cCs�d}|js�|jr|d|j7}|j}|j�x|D]}|d|j�7}q2W|j}|j�x|D]}|d|7}q^W|j}|j�x|D]}|d|j�7}q�W|j}|j�x|D]}|d|7}q�W|dkr�|jr�dSd}|jr�|d7}|j	r�|d7}|j
�s
|d7}|j�r|d	7}|jt
jk�r0|d
7}|jdk	�rJ|d|j7}|j�rZ|d
7}|j�rj|d7}|jdk	�r�|d|j7}|jdk	�r�|d|j7}|jtjk�r�|d|dS|d|dSdS)z9Return a string formatted for output to a kickstart file.rz@^%s
z%s
z-%s
z

%packagesz
 --defaultz --excludedocsz	 --nobasez	 --nocorez --ignoremissingNz --instLangs=%sz --multilibz --excludeWeakdepsz
 --timeout=%dz
 --retries=%drTz
%end
)rlrmrq�sortrXrsrornryrprjrkrrrZKS_MISSING_IGNORErtrurvrwrxrVrrW)r?ZpkgsZgrps�grp�p�pkgr&r)r)r*rXrs\



zPackages.__str__cCs�tddtjd�}|jddddtjd�|jddddtjd�|j|j�d�\}}|jrh|jrhtt	d	���d
j
|�}|dd�|jD�kr�dS|jr�|jjt
|tjd
��n4|jr�|jjt
|tjd
��n|jjt
|tjd
��dS)Nr)�prog�descriptionrz--nodefaults�
store_trueF)�actionrl�helprz
--optional)rRz5Group cannot specify both --nodefaults and --optionalrcSsg|]
}|j�qSr))r[)�.0�gr)r)r*�
<listcomp>�sz*Packages._processGroup.<locals>.<listcomp>)r[r\)rrrY�add_argumentZparse_known_argsr"Z
nodefaultsZoptionalrrrNrq�appendrZrr]r^rg)r?�line�op�nsZextrar{r)r)r*�
_processGroup�s 


zPackages._processGroupc	sTt|j�}t|j�}t�}t�}g}x�|D]�}|j�}|dd�dkrV|dd�|_q*|ddkrv|j|dd��q*|ddkr�|dd�dkr�|j|dd�kr�d|_q�|ddkr�|jt|dd�d	��q�|j|dd��q*|j|�q*Wd
d�|D���fdd�|j	D�|_	|j
j|�|||B}|||B}t|�|_t|�|_dS)
z�Given a list of lines from the input file, strip off any leading
           symbols and add the result to the appropriate list.
        r�z@^N�@r�-�)r[cSsg|]
}|j�qSr))r[)r�r�r)r)r*r��sz Packages.add.<locals>.<listcomp>csg|]}|j�kr|�qSr))r[)r�r�)�excludedGroupNamesr)r*r��s)
rrnrsr rmr�r�rZ�addrqro�extend�list)	r?ZpkgListZexistingExcludedSetZexistingPackageSetZnewExcludedSetZ
newPackageSetror}�strippedr))r�r*r��s2


"
zPackages.addN)
rErFrGrrYrVrArXr�r�r)r)r)r*ri5s
9;ric@s�eZdZdZd$dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd%dd�Zd&dd �Zd!d"�Zd#S)'�KickstartParsera5The 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.
    TcCsh||_d|_||_||_i|_||_||_t|_d|_	d|_
|jj|_|jt_
|jt_
i|_|j�dS)a.Create a new KickstartParser instance.  Instance attributes:

           errorsAreFatal        -- Should errors cause processing to halt, or
                                    just print a message to the screen?  This
                                    is most useful for writing syntax checkers
                                    that may want to continue after an error is
                                    encountered.
           followIncludes        -- If %include is seen, should the included
                                    file be checked as well or skipped?
           handler               -- An instance of a BaseHandler subclass.  If
                                    None, the input file will still be parsed
                                    but no data will be saved and no commands
                                    will be executed.
           missingIncludeIsFatal -- Should missing include files be fatal, even
                                    if errorsAreFatal is False?
           unknownSectionIsFatal -- Should an unknown %section be fatal?  Not all
                                    sections are handled by pykickstart.  Some are
                                    user-defined, so there should be a way to have
                                    pykickstart ignore them.
        rrN)�errorsAreFatal�errorsCount�followIncludes�handler�
currentdir�missingIncludeIsFatal�unknownSectionIsFatal�STATE_COMMANDS�_state�
_includeDepth�_linerrHrVri�	_sections�
setupSections)r?r�r�r�r�r�r)r)r*rAs
zKickstartParser.__init__cCst|_d|_dS)zKReset the internal variables of the state machine for a new kickstart file.rN)r�r�r�)r?r)r)r*�_reset,szKickstartParser._resetcCs
|j|S)zyReturn a reference to the requested section (s must start with '%'s),
           or raise KeyError if not found.
        )r�)r?r.r)r)r*�
getSection1szKickstartParser.getSectioncCs&|jr"|j|j_|jj||�}|SdS)a	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.
        N)r�r�ZcurrentLineZ
dispatcher)r?rrRr&r)r)r*�
handleCommand7s
zKickstartParser.handleCommandcCs<|jstd|��|jjd�s,td|j��||j|j<dS)z�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.
        z#no sectionOpen given for section %s�%z'section %s tag does not start with a %%N)�sectionOpen�	TypeErrorr!r�)r?�objr)r)r*�registerSectionBs
zKickstartParser.registerSectioncCs|j�t|_dS)z�Called at the close of a kickstart section to take any required
           actions.  Internally, this is used to add scripts once we have the
           whole body read.
        N)�finalizer�r�)r?r�r)r)r*�	_finalizePszKickstartParser._finalizecCs8|jtkrdS|dd�dkr4|jdd�j�|j_dS)z/Kickstart recognizes a couple special comments.N�
z
#platform=)r�r�r�r r��platform)r?r�r)r)r*�_handleSpecialCommentsXs
z&KickstartParser._handleSpecialCommentscCs�|j|j}�x�yJt|�}|dkrX|jdkrX|jtjkrNttd�|j|d��|j	|�Wnt
k
rpPYnX|d7}|j|�r�|jr�q|j
�jd��r�|j�d}|j|�r�|d
kr�|j|�qtj|�}|r�|ddkr�|j	|�Pn�|�r<|ddk�r<t|�dk�s |d�r*t|d��|j|d�qnp|�rT|dd	k�rTqnX|�r�|j|d��r�|jtjk�r�ttd�|j|d��|j|�|d8}|j	|�Pq|j|�qW|S)Nrrz#Section %s does not end with %%end.)rrr��%end�%includez	%ksappend)r�r�)r�r�rr�rrWrrr�r�r�_isBlankOrCommentZallLines�lstripr!r"�_validStateZ
handleLine�shlex�len�_handleIncluderC)r?r$rr�r�ZpossibleSectionStartrRr)r)r*�_readSectionasN





zKickstartParser._readSectioncCs|t|jj��kS)zFIs the given section tag one that has been registered with the parser?)r�r��keys)r?�str)r)r*r��szKickstartParser._validStatecCsXy
|�WnHtk
rR}z,|jd7_|jr4�nt|tjd�WYdd}~XnXdS)z�Call the provided function (which doesn't take any arguments) and
           do the appropriate error handling.  If errorsAreFatal is False, this
           function will just print the exception and keep going.
        r)�fileN)�	Exceptionr�r��printr�stderr)r?�fn�msgr)r)r*�_tryFunc�s
zKickstartParser._tryFunccCs |j�p|dkp|j�ddkS)Nrr�#)�isspacer�)r?r�r)r)r*r��sz!KickstartParser._isBlankOrCommentcCsZ|js
dS|jd7_y|j|dd�Wntk
rF|jrB�YnX|jd8_dS)NrF)�reset)r�r��
readKickstartrr�)r?r1r)r)r*r��szKickstartParser._handleIncludec
s�d��x�yt|��_�jdkr PWntk
r8PYnX�d7��j�j�r\�j�j�qtj�jdd���ddkr�t��dks��dr�t�d���j	�d�q�j
tk�r��ddkr�qn��ddd	k�rl�d}�j|��s6�j
�rttd
�|�d��n.tjtd��|d�t��jt�j|d
��|�_
�j�j
��j���fdd���j|���n�j���fdd��q�j
tk�r�Pq�jdkr|j�j��d8��j|���qWdS)NrrrT)Zcommentsz%include)rz	%ksappendr�zUnknown kickstart section: %szDPotentially unknown section seen at line %(lineno)s: %(sectionName)s)rZsectionName)r�cs�j���S)N)ZhandleHeaderr))rRrr�r)r*�<lambda>�sz/KickstartParser._stateMachine.<locals>.<lambda>cs�j���S)N)r�r))rRrr?r)r*r�s)rr�rr�r�r�r"r�rr�r�r�r�r�r�warnings�warnr	r�rr�r�r�r��	STATE_ENDr�rC)r?r$Z
newSectionr))rRrr�r?r*�
_stateMachine�sN



zKickstartParser._stateMachinecCs.|r|j�t|jd�dg�}|j|�dS)z5Process a kickstart file, provided as the string str.TrN)r�r<r-r�)r?r.r�r/r)r)r*�readKickstartFromString
sz'KickstartParser.readKickstartFromStringcCs�|r|j�tjj|�sd|jd|jkrdtjjtjj|j|jd|��rdtjj|j|jd|�}tjj|�}|jd�s�tjj	|�}||j|j<yt
|�}Wn:tk
r�}zttd�t
|�dd��WYdd}~XnX|j|dd�dS)	z2Process a kickstart file, given by the filename f.r�/z'Unable to open input kickstart file: %sr)rNF)r�)r�r5�path�existsr�r�rN�dirnamer!�abspathrrrr#r�)r?r1r�Zcdr.r(r)r)r*r�s"
*zKickstartParser.readKickstartcCs�i|_|jt|jtd��|jt|jtd��|jt|jtd��|jt|jtd��|jt|jtd��|jt	|j��|jt
|jdd��|jt
|jdd��dS)z�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.
        )ZdataObjz%addon)r�z	%anacondaN)r�r�rr�rHrrrrr
r)r?r)r)r*r�3szKickstartParser.setupSectionsN)TTTT)T)T)rErFrGrfrAr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r)r)r)r*r��s$
(	AD

r�)2rfZ
__future__r�collections.abcrr5rr�rr�Zordered_setr�ImportErrorZ
orderedsetZpykickstartrrZpykickstart.errorsrrr	Zpykickstart.kor
Zpykickstart.loadrZpykickstart.optionsrZpykickstart.sectionsr
rrrrrrZpykickstart.i18nrr�r�r+r0r2r:r;r<rHrZri�objectr�r)r)r)r*�<module> s>$/	
O*H