Viewing File: /usr/lib/python3.6/site-packages/dnf-plugins/__pycache__/config_manager.cpython-36.pyc

3

�gt`�*�@s�ddlmZddlmZddlmZmZmZddlZddlZddl	Zddl
ZddlZddlZddl
Z
ddlZddlZejjGdd�dejj��Zdd�Zejd	�Zejd
�Zejd�Zejd�Zd
d�ZdS)�)�absolute_import)�unicode_literals)�_�logger�P_Nc@sReZdZdgZed�jejjd�Z	e
dd��Zdd�Zdd	�Z
d
d�Zdd
�ZdS)�ConfigManagerCommandzconfig-managerz4manage {prog} configuration options and repositories)�progcCs�|jdddtd�d�|jdddtd	�d
�|jdgdd
td�d�|jdddtd�d
�|jdddtd�d
�|j�}|jddddtd�d�|jddddtd�d�dS)N�crepo�*�repozrepo to modify)�nargs�metavar�helpz--saveF�
store_truez/save the current options (useful with --setopt))�default�actionrz
--add-repo�appendZURLz8add (and enable) the repo from the specified file or url)rrr
rz--dumpz,print current configuration values to stdoutz--dump-variableszprint variable values to stdoutz
--set-enabled�set_enabledz"enable repos (automatically saves))r�destrrz--set-disabled�set_disabledz#disable repos (automatically saves))�add_argumentrZadd_mutually_exclusive_group)�parserZenable_group�r�$/usr/lib/python3.6/config_manager.py�
set_argparser)s,z"ConfigManagerCommand.set_argparsercCs�|jj}d|_|jjgkp@|jjp@|jjp@|jjp@|jjp@|jj	sp|jj
jtd�j
djdddddd	d
dg���|jjgkr�tjtd��|jjs�|jj	s�|jjs�|jjr�d|_d
d�|jjD�}dd�|D�|j_dS)NTz.one of the following arguments is required: {}� z--savez
--add-repoz--dumpz--dump-variablesz
--set-enabledz--enablez--set-disabledz	--disablez{Warning: --enablerepo/--disablerepo arguments have no meaningwith config manager. Use --set-enabled/--set-disabled instead.cSsg|]}|dkr|jd��qS)�,)�split)�.0�xrrr�
<listcomp>_sz2ConfigManagerCommand.configure.<locals>.<listcomp>cSs"g|]}|D]}|dkr|�qqS)�r)rZsublist�itemrrrr as)�cli�demandsZavailable_repos�opts�add_repo�save�dump�dump_variablesrrZ	optparser�errorr�format�joinZrepos_edrZwarningZ	root_userr	)�selfr$Z	temp_listrrr�	configureBs*zConfigManagerCommand.configurecCs|jjr|j�n|j�dS)zExecute the util action here.N)r%r&�modify_repo)r-rrr�runds
zConfigManagerCommand.runc	s�g�t������fdd�}�jjrnx�jjD]�|�d�q.Wt�jd�r�xL�jjj�D]�|�d�qZWn,t�jd�r�x�jjj�D]�|�d�q�W�r�tjjt	d�dj
�����jj}i}t�jd�r�jj
r�jj
}�jj�rx*�jjjj�D]\�}td	�|f�q�W�jj�s0d
�jjk�r��jj�r\|�r\�jjj�jjjd
|j|��jj�r�t�jjjd
��t�jjj����s�dS�jj�s��jj�r�d�j_x�t��D]�}i}�jj�r�d|d
<n�jj�r�d|d
<t�jd��r*x4�jjj�D]$\}}tj|j|��r|j|��qW�jj�rT|�rT�jjj|j|j|j|��jj�r�t�jjjd|j��t|j���q�WdS)z< process --set-enabled, --set-disabled and --setopt options cs0�jjj|�}|s�j��n|r,�j|�dS)N)�baseZreposZget_matching�add�extend)�keyZadd_matching_reposZmatching)�matching_repos�name�not_matching_repos_idr-rr�match_reposqs
z5ConfigManagerCommand.modify_repo.<locals>.match_reposT�repo_setoptsFzNo matching repo to modify: %s.z, �main_setoptsz%s = %s�mainN�1Zenabled�0zrepo: )�setr%r	�hasattrr9�keys�dnf�
exceptions�Errorrr,r1�confr:r)Z
substitutions�items�printr'Zwrite_raw_configfileZconfig_file_pathr(�outputZ
fmtSectionrr�sorted�fnmatch�id�updateZrepofile)	r-r8ZsbcZmodify�valrZrepo_modify�repoidZsetoptsr)r5r6r7r-rr/ks`






z ConfigManagerCommand.modify_repoc
CsN|jjj}d}�x|jjD�]}tjjj|�jdkrDdt	j
j|�}tj
td�|�|jd�r�t	j
j|�}t	j
j||�}y6|jj|dd�}tj|j|�t	j|d�|j�Wn6tk
r�}z|d	7}tj|�wWYd
d
}~XnXqt|�}djtjj|�}t	j
j|d|�}d
|||f}	t||	�sqqW|�rJtjj t!dd|���d
S)z process --add-repo option rr!zfile://zAdding repo from: %sz.repozw+)�modei��Nz$created by {} config-manager from {}z%s.repoz"[%s]
name=%s
baseurl=%s
enabled=1
zConfiguration of repo failedzConfiguration of repos failed)"r1rDZget_reposdirr%r&rA�pycompZurlparse�scheme�os�path�abspathr�infor�endswith�basenamer,Zurlopen�shutilZcopy2r6�chmod�close�IOErrorr*�sanitize_url_to_fsr+�util�	MAIN_PROG�save_to_filerBrCr)
r-Z	myrepodirZerrors_count�urlZdestname�f�erMZreponame�contentrrrr&�s8




zConfigManagerCommand.add_repoN)�__name__�
__module__�__qualname__�aliasesrr+rAr]r^Zsummary�staticmethodrr.r0r/r&rrrrr"s"BrcCspy4t|d�� }tjj||�tj|d�WdQRXWn6ttfk
rj}ztj	t
d�||�dSd}~XnXdS)Nzw+i�z&Could not save repo to repofile %s: %sFT)�openrArPZ
write_to_filerRrYr[�OSErrorrr*r)�filenamerc�fdrbrrrr_�s
r_z^\w+:/*(\w+:|www\.)?z[?/:&#|~\*\[\]\(\)\'\\]+z^[,.]*z[,.]*$cCs*ybtj|�r`tjjr&|jd�jd�}n:t|t�rB|jd�jd�}n
|jd�}t|t	�r`|jd�}Wnt
ttt
fk
r~YnXtjd|�}tjd|�}tjd|�}tjd|�}t|�dk�r|dd�jd�}dt|d
�}tj�}|j||d�jd��|d|�d|j�}d	}tj|d|�S)z�Return a filename suitable for the filesystem and for repo id

    Strips dangerous and common characters to create a filename we
    can use to store the cache in.
    Zidnazutf-8r!r�N�rOzE[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.:-]���)�	RE_SCHEME�matchrArPZPY3�encode�decode�
isinstance�strZunicode�UnicodeDecodeError�UnicodeEncodeError�UnicodeError�	TypeError�sub�RE_SLASH�RE_BEGIN�RE_FINAL�lenr�hashlibZsha256rKZ	hexdigest�re)r`�parts�	lastindexZcsumZ
allowed_regexrrrr\�s.



r\)Z
__future__rrZdnfpluginscorerrrrAZdnf.cliZ
dnf.pycompZdnf.utilrIrrRr�rXZpluginZregister_commandr#ZCommandrr_�compilerpr{r|r}r\rrrr�<module>s(1




Back to Directory File Manager
<