Mini Shell
3
Z��e�S � 0 @ s2 d dl Z d dlZd dlZd dlmZ d dlZd dlZd dlZd dlZd dl Z d dl
mZ d dlm
Z
d dlmZ d dlmZmZ d dlmZmZmZ d dlmZ d d lmZmZ d d
lmZ d dlm Z d dl!m"Z" d d
l#m$Z$ d dl%m&Z&m'Z' d dl(m)Z)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/ d dl0m1Z1m2Z2 d dl3m4Z4 d dl3m5Z6 d dl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z? d dl@mAZA d dlBmCZC d dlDmEZEmFZFmGZG eEeH�ZIeF� ZJeIjKd�ZLeIjKd�ZMedd� �ZNG dd� de6�ZOG dd� deO�ZPG d d!� d!e*ed"�ZQG d#d$� d$eQ�ZRejSZSG d%d&� d&ejT�ZTG d'd(� d(ejU�ZUG d)d*� d*e)�ZVG d+d,� d,e?�ZWeReReReReReReReReSeReReReReReReReReReReReTeReReReReReReReReReReReReReReReReReReReReReReReReReRd-�/ZXd(eUiZYeAe�ZZG d.d/� d/eZ�Z[G d0d1� d1e4�Z\G d2d3� d3e4�Z]d4d5� Z^dCd7d8�Z_d9d:� Z`d;d<� Zad=d>� Zbd?d@� ZcdAdB� ZddS )D� N)�ABCMeta)�contextmanager)�util)�conf)�VERSION�commands)�AddonSection� AddonData�
AddonRegistry)�IPMI_ABORTED)�ScriptError�errorHandler)�flags)�_)�BOSS)�KickstartReport)�F22_PwPolicy�F22_PwPolicyData)�BaseHandler�KickstartCommand)�KS_SCRIPT_POST�
KS_SCRIPT_PRE�KS_SCRIPT_TRACEBACK�KS_SCRIPT_PREINSTALL)�KickstartError�KickstartParseWarning)�KickstartParser)�Script)�NullSection�PackageSection�PostScriptSection�PreScriptSection�PreInstallScriptSection�OnErrorScriptSection�TracebackScriptSection�Section)�returnClassForVersion)�anaconda_logging)�get_module_logger�get_stdout_logger�get_anaconda_root_logger�scriptZparsingc c sN y
d V W n> t k
rH } z"t| � tjt� tjd� W Y d d } ~ X nX d S )N� )r �printr �ipmi_reportr �sys�exit)�e� r2 �!/usr/lib64/python3.6/kickstart.py�check_kickstart_errorD s
r4 c @ s e Zd ZdZdd� ZdS )�AnacondaKSScriptz� Execute a kickstart script
This will write the script to a file named /tmp/ks-script- before
execution.
Output is logged by the program logger, the path specified by --log
or to /tmp/ks-script-\*.log
c
C s^ | j r|}nd}tjdd|d �\}}tj|| jjd�� tj|� tj|d� | j r�| j rld|| j f }n| j }tj
j|�}tj
j|�s�tj
|� ndtj
j|� }tj|d d
d��(}tj| jdtj
j|� g||d
�}W dQ R X |dk�rZtjd|| j� | j�rZd} t|d��}dj|j� �} W dQ R X dt_tjt| j| �� tjt � t!j"d� dS )zk Run the kickstart script
@param chroot directory path to chroot into before execution
�/� z
ks-script-z/tmpzutf-8i� z%s/%sz/tmp/%s.log�wi� )Zpermz/tmp/%s)�stdout�rootNr z5Error code %s running the kickstart script at line %s�rT)#ZinChroot�tempfileZmkstemp�os�writer+ �encode�close�chmodZlogfile�path�dirname�exists�makedirs�basenamer Zopen_with_permZexecWithRedirectZinterp�
script_log�error�linenoZerrorOnFail�open�join� readlinesr Zkspromptr
�cbr r. r r/ r0 )
�self�chrootZ
scriptRoot�fdrB Zmessages�d�fpZrc�errr2 r2 r3 �runX s:
zAnacondaKSScript.runN)�__name__�
__module__�__qualname__�__doc__rT r2 r2 r2 r3 r5 P s r5 c s$ e Zd Z� fdd�Zdd� Z� ZS )�AnacondaInternalScriptc s t � j||� d| _d S )NT)�super�__init__Z_hidden)rN �args�kwargs)� __class__r2 r3 r[ � s zAnacondaInternalScript.__init__c C s dS )Nr7 r2 )rN r2 r2 r3 �__str__� s zAnacondaInternalScript.__str__)rU rV rW r[ r_ �
__classcell__r2 r2 )r^ r3 rY � s rY c @ s e Zd ZdZdd� Zdd� ZdS )�RemovedCommanda Kickstart command that was moved on DBus.
This class should simplify the transition to DBus.
Kickstart command that was moved on DBus should inherit this
class. Methods parse, setup and execute should be modified to
access the DBus modules or moved on DBus.
c C s dS )z�Generate this part of a kickstart file from the module.
This method shouldn't be overridden, because we use DBus modules
to generate these parts of a kickstart file.
Make sure that each DBus module is used only once.
r7 r2 )rN r2 r2 r3 r_ � s zRemovedCommand.__str__c C s t jd| j� dS )z�Do not parse anything.
We can keep this method for the checks if it is possible, but
it shouldn't parse anything.
z)Command %s will be parsed in DBus module.N)�logZwarning�
currentCmd)rN r\ r2 r2 r3 �parse� s zRemovedCommand.parseN)rU rV rW rX r_ rd r2 r2 r2 r3 ra � s
ra )� metaclassc @ s e Zd ZdZdd� ZdS )�UselessCommandz�Kickstart command that was moved on DBus and doesn't do anything.
Use this class to override the pykickstart command in our command map,
when we don't want the command to do anything. It is not allowed to
subclass this class.
c K s t d��d S )Nz7It is not allowed to subclass the UselessCommand class.)� TypeError)�clsr] r2 r2 r3 �__init_subclass__� s z UselessCommand.__init_subclass__N)rU rV rW rX ri r2 r2 r2 r3 rf � s rf c @ s e Zd Zdd� ZdS )�Loggingc C sv t jjt jkr0t j| j }|t j_t jt� |� t jjd krrt | j
�dkrr| j
}| jrfd| j
| jf }t jj|� d S )Nr z%s:%s)
r'