
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
šgt`…*  ã               @   sÌ   d dl mZ d dl mZ d dlmZmZmZ d dlZd dlZd dl	Zd dl
Zd dlZd dlZd dlZd dlZd dlZejjG dd„ dejjƒƒZdd„ Zejd	ƒZejd
ƒZejdƒZejdƒZdd„ ZdS )é    )Úabsolute_import)Úunicode_literals)Ú_ÚloggerÚP_Nc               @   sR   e Zd ZdgZedƒjejjd�Z	e
dd„ ƒZdd„ Zdd	„ Zd
d„ Zdd„ ZdS )ÚConfigManagerCommandzconfig-managerz4manage {prog} configuration options and repositories)Úprogc             C   s¬   | j dddtdƒd� | j dddtd	ƒd
� | j dg ddtdƒd� | j dddtdƒd
� | j dddtdƒd
� | jƒ }|j ddddtdƒd� |j ddddtdƒd� d S )NÚcrepoÚ*Úrepozrepo to modify)ÚnargsÚmetavarÚhelpz--saveFÚ
store_truez/save the current options (useful with --setopt))ÚdefaultÚactionr   z
--add-repoÚappendZURLz8add (and enable) the repo from the specified file or url)r   r   r   r   z--dumpz,print current configuration values to stdoutz--dump-variableszprint variable values to stdoutz--set-enabledÚset_enabledz"enable repos (automatically saves))r   Údestr   r   z--set-disabledÚset_disabledz#disable repos (automatically saves))Úadd_argumentr   Zadd_mutually_exclusive_group)ÚparserZenable_group© r   ú$/usr/lib/python3.6/config_manager.pyÚset_argparser)   s,    z"ConfigManagerCommand.set_argparserc             C   sØ   | j j}d|_| jjg kp@| jjp@| jjp@| jjp@| jjp@| jj	sp| j j
jtdƒjdjdddddd	d
dgƒƒƒ | jjg krŠtjtdƒƒ | jjsª| jj	sª| jjsª| jjr°d|_dd„ | jjD ƒ}dd„ |D ƒ| j_d S )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.c             S   s   g | ]}|d kr|j d ƒ‘qS )ú,)Úsplit)Ú.0Úxr   r   r   ú
<listcomp>_   s    z2ConfigManagerCommand.configure.<locals>.<listcomp>c             S   s"   g | ]}|D ]}|d kr|‘qqS )Ú r   )r   ZsublistÚitemr   r   r   r    a   s    )ÚcliÚdemandsZavailable_reposÚoptsÚadd_repoÚsaveÚdumpÚdump_variablesr   r   Z	optparserÚerrorr   ÚformatÚjoinZrepos_edr   ZwarningZ	root_userr	   )Úselfr$   Z	temp_listr   r   r   Ú	configureB   s*    zConfigManagerCommand.configurec             C   s   | j jr| jƒ  n| jƒ  dS )zExecute the util action here.N)r%   r&   Úmodify_repo)r-   r   r   r   Úrund   s    
zConfigManagerCommand.runc       	         sŒ  g ‰ t ƒ ‰‡ ‡‡‡fdd„}ˆjjrnxˆjjD ]‰|ˆdƒ q.W tˆjdƒršxLˆjjjƒ D ]‰|ˆdƒ qZW n,tˆjdƒršxˆjjjƒ D ]‰|ˆdƒ qˆW ˆr¸tjjt	dƒdj
ˆƒ ƒ‚ˆjj}i }tˆjdƒràˆjjràˆjj}ˆjj�rx*ˆjjjjƒ D ]\‰}td	ˆ|f ƒ qúW ˆjj �s0d
ˆjjk�rˆˆjj�r\|�r\ˆjjjˆjjjd
|j|ƒ ˆjj�rˆtˆjjjd
ƒƒ tˆjjjƒ ƒ ˆ �s’dS ˆjj�s¦ˆjj�r®dˆj_xØtˆ ƒD ]Ì}i }ˆjj�rÔd|d< nˆjj�ræd|d< tˆjdƒ�r*x4ˆjjjƒ D ]$\}}tj|j|ƒ�r|j|ƒ �qW ˆjj�rT|�rTˆjjj|j|j|j|ƒ ˆjj�r¸tˆjjjd|j ƒƒ t|jƒ ƒ �q¸W dS )z< process --set-enabled, --set-disabled and --setopt options c                s0   ˆj jj| ƒ}|sˆjˆƒ n|r,ˆ j|ƒ d S )N)ÚbaseZreposZget_matchingÚaddÚextend)ÚkeyZadd_matching_reposZmatching)Úmatching_reposÚnameÚnot_matching_repos_idr-   r   r   Úmatch_reposq   s
    z5ConfigManagerCommand.modify_repo.<locals>.match_reposTÚrepo_setoptsFzNo matching repo to modify: %s.z, Úmain_setoptsz%s = %sÚmainNÚ1ZenabledÚ0zrepo: )Úsetr%   r	   Úhasattrr9   ÚkeysÚdnfÚ
exceptionsÚErrorr   r,   r1   Úconfr:   r)   ZsubstitutionsÚitemsÚprintr'   Zwrite_raw_configfileZconfig_file_pathr(   ÚoutputZ
fmtSectionr   r   ÚsortedÚfnmatchÚidÚupdateZrepofile)	r-   r8   ZsbcZmodifyÚvalr   Zrepo_modifyÚrepoidZsetoptsr   )r5   r6   r7   r-   r   r/   k   s`    






z ConfigManagerCommand.modify_repoc       
      C   sN  | j jj}d}�x| jjD �]}tjjj|ƒjdkrDdt	j
j|ƒ }tjtdƒ|ƒ |jdƒrèt	j
j|ƒ}t	j
j||ƒ}y6| j j|dd�}tj|j|ƒ t	j|dƒ |jƒ  W n6 tk
rä } z|d	7 }tj|ƒ wW Y d
d
}~X nX qt|ƒ}djtjj|ƒ}t	j
j|d| ƒ}d|||f }	t||	ƒsqqW |�rJtjj t!dd|ƒƒ‚d
S )z process --add-repo option r   r!   zfile://zAdding repo from: %sz.repozw+)Úmodei¤  é   Nz$created by {} config-manager from {}z%s.repoz"[%s]
name=%s
baseurl=%s
enabled=1
zConfiguration of repo failedzConfiguration of repos failed)"r1   rD   Zget_reposdirr%   r&   rA   ÚpycompZurlparseÚschemeÚosÚpathÚabspathr   Úinfor   ÚendswithÚbasenamer,   ZurlopenÚshutilZcopy2r6   ÚchmodÚcloseÚIOErrorr*   Úsanitize_url_to_fsr+   ÚutilÚ	MAIN_PROGÚsave_to_filerB   rC   r   )
r-   Z	myrepodirZerrors_countÚurlZdestnameÚfÚerM   ZreponameÚcontentr   r   r   r&   ­   s8    




zConfigManagerCommand.add_repoN)Ú__name__Ú
__module__Ú__qualname__Úaliasesr   r+   rA   r]   r^   ZsummaryÚstaticmethodr   r.   r0   r/   r&   r   r   r   r   r   "   s   "Br   c             C   sp   y4t | dƒ� }tjj||ƒ tj| dƒ W d Q R X W n6 ttfk
rj } ztj	t
dƒ| |ƒ dS d }~X nX dS )Nzw+i¤  z&Could not save repo to repofile %s: %sFT)ÚopenrA   rP   Zwrite_to_filerR   rY   r[   ÚOSErrorr   r*   r   )Úfilenamerc   Úfdrb   r   r   r   r_   Ó   s    
r_   z^\w+:/*(\w+:|www\.)?z[?/:&#|~\*\[\]\(\)\'\\]+z^[,.]*z[,.]*$c             C   s*  ybt j| ƒr`tjjr&| jdƒjdƒ} n:t| tƒrB| jdƒjdƒ} n
| jdƒ} t| t	ƒr`| jdƒ} W n t
tttfk
r~   Y nX t jd| ƒ} tjd| ƒ} tjd| ƒ} tjd| ƒ} t| ƒdk�r| dd… jdƒ}dt|d
 ƒ }tjƒ }|j| |d… jdƒƒ | d|… d |jƒ  } d	}tj|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.
    Zidnazutf-8r!   r   éú   Né¹   rO   zE[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.:-]éÿÿÿÿ)Ú	RE_SCHEMEÚmatchrA   rP   ZPY3ÚencodeÚdecodeÚ
isinstanceÚstrZunicodeÚUnicodeDecodeErrorÚUnicodeEncodeErrorÚUnicodeErrorÚ	TypeErrorÚsubÚRE_SLASHÚRE_BEGINÚRE_FINALÚlenr   ÚhashlibZsha256rK   Z	hexdigestÚre)r`   ÚpartsÚ	lastindexZcsumZallowed_regexr   r   r   r\   ä   s.    



r\   )Z
__future__r   r   Zdnfpluginscorer   r   r   rA   Zdnf.cliZ
dnf.pycompZdnf.utilrI   r   rR   r€   rX   ZpluginZregister_commandr#   ZCommandr   r_   Úcompilerp   r{   r|   r}   r\   r   r   r   r   Ú<module>   s(    1



