a º&c…*ã@sÌddlmZddlmZddlmZmZmZddlZddlZddl Zddl Zddl Z ddl Z ddl Z ddlZddlZejjGdd„dejjƒƒZdd„Ze d ¡Ze d ¡Ze d ¡Ze d ¡Zd d„ZdS)é)Úabsolute_import)Úunicode_literals)Ú_ÚloggerÚP_Nc@sReZdZdgZedƒjejjd�Z e dd„ƒZ dd„Z dd „Z d d „Zd d „ZdS)ÚConfigManagerCommandzconfig-managerz4manage {prog} configuration options and repositories)ÚprogcCs¬|jdddtdƒd�|jdddtd ƒd �|jd gd d tdƒd�|jdddtdƒd �|jdddtdƒd �| ¡}|jddddtdƒd�|jddddtdƒd�dS)NÚcrepoÚ*Úrepozrepo to modify)ÚnargsÚmetavarÚhelpú--saveFÚ store_truez/save the current options (useful with --setopt))ÚdefaultÚactionrú --add-repoÚappendZURLz8add (and enable) the repo from the specified file or url)rrr rú--dumpz,print current configuration values to stdoutú--dump-variableszprint variable values to stdoutú --set-enabledÚ set_enabledz"enable repos (automatically saves))rÚdestrrú--set-disabledÚ set_disabledz#disable repos (automatically saves))Ú add_argumentrÚadd_mutually_exclusive_group)ÚparserZ enable_group©rú>/usr/lib/python3.9/site-packages/dnf-plugins/config_manager.pyÚ set_argparser)s:þþþþþþþz"ConfigManagerCommand.set_argparsercCsÌ|jj}d|_|jjgksd|jjsd|jjsd|jjsd|jjsd|jj sd|jj   t dƒ  d gd¢¡¡¡|jjgkr~t t dƒ¡|jjsž|jj sž|jjsž|jjr¤d|_dd„|jjDƒ}dd„|Dƒ|j_dS) NTz.one of the following arguments is required: {}ú )rrrrrz--enablerz --disablez{Warning: --enablerepo/--disablerepo arguments have no meaningwith config manager. Use --set-enabled/--set-disabled instead.cSsg|]}|dkr| d¡‘qS)ú,)Úsplit)Ú.0Úxrrr Ú _óz2ConfigManagerCommand.configure..cSs"g|]}|D]}|dkr |‘q qS)Úr)r%ZsublistÚitemrrr r'asÿ)ÚcliÚdemandsZavailable_reposÚoptsÚadd_repoÚsaveÚdumpÚdump_variablesrrZ optparserÚerrorrÚformatÚjoinZrepos_edrZwarningZ root_userr )Úselfr,Z temp_listrrr Ú configureBs4 ÿþýüû ÿ ÿÿzConfigManagerCommand.configurecCs|jjr| ¡n| ¡dS)zExecute the util action here.N)r-r.Ú modify_repo)r5rrr Úrunds zConfigManagerCommand.runc srg‰tƒ‰‡‡‡‡fdd„}ˆjjrfˆjjD]‰|ˆdƒq,tˆjdƒrŽˆjj ¡D]‰|ˆdƒqTn(tˆjdƒrŽˆjj ¡D]‰|ˆdƒq~ˆr¬tj t dƒd  ˆ¡¡‚ˆj j }i}tˆjdƒrÔˆjj rÔˆjj }ˆjj�rˆj j j ¡D]\‰}td ˆ|fƒqìˆjj�rd ˆjjv�rvˆjj�rJ|�rJˆj j  ˆj j jd |j|¡ˆjj�rvtˆj j d ¡ƒtˆj j  ¡ƒˆ�s€d Sˆjj�s”ˆjj�rœdˆj_tˆƒD]È}i}ˆjj�rÀd |d <nˆjj�rÒd|d <tˆjdƒ�rˆjj ¡D]$\}}t |j|¡�rì| |¡�qìˆjj�r<|�r<ˆj j  |j|j|j|¡ˆjj�r¤tˆj j d|j¡ƒt| ¡ƒ�q¤d S)z< process --set-enabled, --set-disabled and --setopt options cs0ˆjj |¡}|sˆ ˆ¡n|r,ˆ |¡dS)N)ÚbaseZreposZ get_matchingÚaddÚextend)ÚkeyZadd_matching_reposZmatching©Zmatching_reposÚnameZnot_matching_repos_idr5rr Ú match_reposqs  z5ConfigManagerCommand.modify_repo..match_reposTÚ repo_setoptsFzNo matching repo to modify: %s.z, Ú main_setoptsz%s = %sÚmainNÚ1ZenabledÚ0zrepo: )Úsetr-r Úhasattrr@ÚkeysÚdnfÚ exceptionsÚErrorrr4r9ÚconfrAr1Z substitutionsÚitemsÚprintr/Zwrite_raw_configfileZconfig_file_pathr0ÚoutputZ fmtSectionrrÚsortedÚfnmatchÚidÚupdateZrepofile) r5r?ZsbcZmodifyÚvalr Z repo_modifyÚrepoidZsetoptsrr=r r7ksd      ÿ ÿ      z ConfigManagerCommand.modify_repoc CsT|jjj}d}|jjD�]}tjj |¡jdkr@dt j   |¡}t   tdƒ|¡| d¡rðt j  |¡}t j  ||¡}z6|jj|dd�}t |j|¡t  |d¡| ¡WnBtyì}z*|d 7}t  |¡WYd }~qWYd }~n d }~00qt|ƒ}d  tjj|¡}t j  |d |¡}d |||f} t|| ƒsqq|�rPtj  t!dd|ƒ¡‚d S)z process --add-repo option rr)zfile://zAdding repo from: %sz.repoúw+)Úmodeé¤éNz$created by {} config-manager from {}z%s.repoz"[%s] name=%s baseurl=%s enabled=1 zConfiguration of repo failedzConfiguration of repos failed)"r9rKZ get_reposdirr-r.rHÚpycompÚurlparseÚschemeÚosÚpathÚabspathrÚinforÚendswithÚbasenamer4ZurlopenÚshutilÚcopy2r>ÚchmodÚcloseÚIOErrorr2Úsanitize_url_to_fsr3ÚutilÚ MAIN_PROGÚ save_to_filerIrJr) r5Z myrepodirZ errors_countÚurlZdestnameÚfÚerTZreponameÚcontentrrr r.­s<      $ÿ  ÿzConfigManagerCommand.add_repoN)Ú__name__Ú __module__Ú __qualname__Úaliasesrr3rHrhriZsummaryÚ staticmethodr!r6r8r7r.rrrr r"sÿ "Brc CsŠzHt|dƒ�*}tj ||¡t |d¡Wdƒn1s<0YWn<ttfy„}z t  t dƒ||¡WYd}~dSd}~00dS)NrUrWz&Could not save repo to repofile %s: %sFT) ÚopenrHrYZ write_to_filer\rdrfÚOSErrorrr2r)ÚfilenamernÚfdrmrrr rjÓs . ÿrjz^\w+:/*(\w+:|www\.)?z[?/:&#|~\*\[\]\(\)\'\\]+z^[,.]*z[,.]*$c Cs(zbt |¡r`tjjr&| d¡ d¡}n:t|tƒrB| d¡ d¡}n | d¡}t|t ƒr`| d¡}Wnt t t t fy|Yn0t d|¡}t d|¡}t d|¡}t d|¡}t|ƒdk�r|dd… d¡}dt|dƒ}t ¡}| ||d… d¡¡|d|…d| ¡}d }t |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é¹éÿÿÿÿzE[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.:-])Ú RE_SCHEMEÚmatchrHrYZPY3ÚencodeÚdecodeÚ isinstanceÚstrZunicodeÚUnicodeDecodeErrorÚUnicodeEncodeErrorÚ UnicodeErrorÚ TypeErrorÚsubÚRE_SLASHÚRE_BEGINÚRE_FINALÚlenr$ÚhashlibZsha256rRZ hexdigestÚre)rkÚpartsÚ lastindexZcsumZ allowed_regexrrr rgäs.        rg)Z __future__rrZdnfpluginscorerrrrHZdnf.cliZ dnf.pycompZdnf.utilrPrŠr\r‹rbZpluginZregister_commandr+ZCommandrrjÚcompiler{r†r‡rˆrgrrrr Ús(  1