3 gt`*@sddlmZddlmZddlmZmZmZddlZddlZddl Zddl Zddl Z ddl Z ddl Z ddlZddlZejjGdddejjZddZejd Zejd Zejd Zejd Zd dZdS))absolute_import)unicode_literals)_loggerP_Nc@sReZdZdgZedjejjdZ e ddZ ddZ dd Z d d Zd d ZdS)ConfigManagerCommandzconfig-managerz4manage {prog} configuration options and repositories)progcCs|jdddtdd|jdddtd d |jd gd d tdd|jdddtdd |jdddtdd |j}|jddddtdd|jddddtdddS)Ncrepo*repozrepo to modify)nargsmetavarhelpz--saveF store_truez/save the current options (useful with --setopt))defaultactionrz --add-repoappendZURLz8add (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))rdestrrz--set-disabled set_disabledz#disable repos (automatically saves)) add_argumentrZadd_mutually_exclusive_group)parserZ enable_groupr$/usr/lib/python3.6/config_manager.py set_argparser)s,      z"ConfigManagerCommand.set_argparserc Cs|jj}d|_|jjgkp@|jjp@|jjp@|jjp@|jjp@|jj sp|jj j t dj djdddddd d d g|jjgkrtjt d |jjs|jj s|jjs|jjrd|_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|jdqS),)split).0xrrr _sz2ConfigManagerCommand.configure..cSs"g|]}|D]}|dkr |q qS)r)rZsublistitemrrrr as)clidemandsZavailable_reposoptsadd_reposavedumpdump_variablesrrZ optparsererrorrformatjoinZrepos_edrZwarningZ root_userr )selfr$Z temp_listrrr configureBs*  zConfigManagerCommand.configurecCs|jjr|jn|jdS)zExecute the util action here.N)r%r& modify_repo)r-rrrrunds zConfigManagerCommand.runc sgtfdd}jjrnxjjD]|dq.WtjdrxLjjjD]|dqZWn,tjdrxjjjD]|dqWrtjjt ddj j j }i}tjdrjj rjj }jjrx*j j jjD]\}td |fqWjj s0d jjkrjjr\|r\j j jj j jd |j|jjrtj jjd tj j jsd Sjjsjjrdj_xtD]}i}jjrd |d <njjrd|d <tjdr*x4jjjD]$\}}tj|j|r|j|qWjjrT|rTj j j|j|j|j|jjrtj jjd|jt|jqWd S)z< process --set-enabled, --set-disabled and --setopt options cs0jjj|}|sjn|r,j|dS)N)baseZreposZ get_matchingaddextend)keyZadd_matching_reposZmatching)matching_reposnamenot_matching_repos_idr-rr match_reposqs  z5ConfigManagerCommand.modify_repo..match_reposT repo_setoptsFzNo matching repo to modify: %s.z, main_setoptsz%s = %smainN1Zenabled0zrepo: )setr%r hasattrr9keysdnf exceptionsErrorrr,r1confr:r)Z substitutionsitemsprintr'Zwrite_raw_configfileZconfig_file_pathr(outputZ fmtSectionrrsortedfnmatchidupdateZrepofile) r-r8ZsbcZmodifyvalr Z repo_modifyrepoidZsetoptsr)r5r6r7r-rr/ks`          z ConfigManagerCommand.modify_repoc CsN|jjj}d}x|jjD]}tjjj|jdkrDdt j j |}t j td||jdrt j j|}t j j||}y6|jj|dd}tj|j|t j|d|jWn6tk r}z|d 7}t j|wWYd d }~XnXqt|}d jtjj|}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+)modeiNz$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&rApycompZurlparseschemeospathabspathrinforendswithbasenamer,ZurlopenshutilZcopy2r6chmodcloseIOErrorr*sanitize_url_to_fsr+util MAIN_PROG save_to_filerBrCr) r-Z myrepodirZ errors_counturlZdestnameferMZreponamecontentrrrr&s8         zConfigManagerCommand.add_repoN)__name__ __module__ __qualname__aliasesrr+rAr]r^Zsummary staticmethodrr.r0r/r&rrrrr"s  "BrcCspy4t|d }tjj||tj|dWdQRXWn6ttfk rj}ztj t d||dSd}~XnXdS)Nzw+iz&Could not save repo to repofile %s: %sFT) openrArPZ write_to_filerRrYr[OSErrorrr*r)filenamercfdrbrrrr_s  r_z^\w+:/*(\w+:|www\.)?z[?/:&#|~\*\[\]\(\)\'\\]+z^[,.]*z[,.]*$cCs*ybtj|r`tjjr&|jdjd}n:t|trB|jdjd}n |jd}t|t r`|jd}Wnt t t t fk r~YnXtjd|}tjd|}tjd|}tjd|}t|dkr|ddjd}dt|d }tj}|j||djd|d|d|j}d }tj|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. Zidnazutf-8r!rNrOzE[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.:-]) RE_SCHEMEmatchrArPZPY3encodedecode isinstancestrZunicodeUnicodeDecodeErrorUnicodeEncodeError UnicodeError TypeErrorsubRE_SLASHRE_BEGINRE_FINALlenrhashlibZsha256rKZ hexdigestre)r`parts lastindexZcsumZ allowed_regexrrrr\s.        r\)Z __future__rrZdnfpluginscorerrrrAZdnf.cliZ dnf.pycompZdnf.utilrIrrRrrXZpluginZregister_commandr#ZCommandrr_compilerpr{r|r}r\rrrrs(   1