Current File : //kunden/usr/share/crypto-policies/python/__pycache__/build-crypto-policies.cpython-39.pyc
a

�
�gW�@sxddlZddlZddlZddlZddlZddlZdZdd�Zdd�Zdd�Z	dd	d
�Z
dd�Zd
d�Ze
dkrte�dS)�Nzreload-cmds.shcOst|dtji|��dS)N�file)�print�sys�stderr)�args�kwargs�r�:/usr/share/crypto-policies/python/build-crypto-policies.py�eprintsr
cCs�tjdd�}|jdddd�|jdddd�|jd	td
dd�|jd
ddd�|jdddd�|jddd�|jddd�|��S)zParse the command lineF)�allow_abbrevz--flat�
store_truez1put all the generated files in a single directory)�action�helpz--testz7compare the generated config file with the existing onez--policyZPOLICYz"generate the specified policy only)�type�metavarrz--reloadcmdszDalso save reload cmds into reload-cmds.sh script in output directoryz--strictzfail on warnings�	policydirz5a directory with base policy definition files (*.pol))r�	outputdirz.a target directory with generated config files)�argparse�ArgumentParser�add_argument�str�
parse_args)�parserrrr	rs.��
�����rcCsz|jr$tj�|j|�d|�d��}n`tj�|j|�}tj�|�srzt�|�Wn"typtd|���YdS0tj�||d�}|j	�r"z^t
|dd��}|��}Wd�n1s�0Y||kr�td|�d|�d	��WdSWd
St�y�Yn$t�y td|���YdS0t
d|�d|���t
|d
dd��}|�|�Wd�n1�sf0Yt
�d
S)N�-z.txtz#Cannot create directory for policy F�utf-8)�encodingzConfig for z for policy z differs from the existing oneTzError reading generated file zSaving config for �w��moder)Zflat�os�path�joinr�isdir�mkdir�OSErrorr
�test�open�read�FileNotFoundErrorr�write)�cmdline�policy_nameZconfig_name�configr �dirpath�fZ
old_configrrr	�save_config/s<
�&*r/c
Cs(d}|durg}ztj|g|�Rd|ji�}Wn6tyd}ztdt|��WYd}~dSd}~00dd�tt�D�}|D]�}tj|}|�}	|	�	|�
|	j��}
|dvs�|	�|
��rz(d�
|g|��}t|||	j|
�s�d	}Wn.t�ytd
|	j�td�d}Yn0q|td
|	j�d}q||S)NrrzError: �cSsg|]}d|vr|�qS��	Generatorr��.0�grrr	�
<listcomp>`�z build_policy.<locals>.<listcomp>>ZEMPTYz	GOST-ONLY�:�zError saving config for zKeeping original configuration�zError testing config for �)�cryptopoliciesZUnscopedCryptoPolicyr�
ValueErrorr
r�dir�policygenerators�__dict__Zgenerate_configZscopedZSCOPESZtest_configr!r/ZCONFIG_NAMEr$)r*r+�subpolicy_names�errZcp�e�
generatorsr5�cls�genr,�namerrr	�build_policySs:��

rHcCs�d}dd�tt�D�}tj�|jt�}zRt|ddd��0}|D]}tj|}|�	|j
�q<Wd�n1sl0YWnty�td�d}Yn0|S)	NrcSsg|]}d|vr|�qSr1rr3rrr	r6yr7z$save_reload_cmds.<locals>.<listcomp>rrrzError saving reload cmds�)
r>r?rr r!r�RELOAD_CMD_NAMEr&r@r)Z
RELOAD_CMDr$r
)r*rBrDr r.r5rErrr	�save_reload_cmdsvs
0
rKcCs�t�}d}|jrt�d�|jrPdd�|j���d�D�}|^}}t|||�}nzt�	|j
��^}|D]H}|j�d�sb|j
dd�rbtj�|j�\}}|d	krbt||�}|rbq�qbWd
�n1s�0Y|s�|jr�t|�}t�|�d
S)z!The actual command implementationr�errorcSsg|]}|r|�qSrr)r4�nrrr	r6�r7zmain.<locals>.<listcomp>r8�.F)�follow_symlinksz.polN)r�strict�warnings�filterwarningsZpolicy�upper�splitrHr�scandirrrG�
startswith�is_filer �splitextZ
reloadcmdsrKr�exit)r*rB�namesr+rA�sd�i�extrrr	�main�s(

$
r^�__main__)N)rrrrQr<r?rJr
rr/rHrKr^�__name__rrrr	�<module>s$
#