<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</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rtjtd | jjs| jj	s| jjs| jjrd|_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rxLjjj D ]|d qZW n,tjdrxjjj D ]|d qW rt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  qW jj s0d
jjkrjjr\|r\jjjjjjd
|j| jjrtjjjd
 tjjj   sdS jjsjjrdj_xt D ]}i }jjrd|d< njjrd|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rtjjjd|j  t|j  qW 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rt	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 )zReturn 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



