a iYvã @s¾ddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlZddl m Z m Z ddlZddlmZddlmZddlZz$ddlmZmZmZmZdd„ZWnFeyþd d „Zzdd lmZWneyød d„ZYn0Yn0d Zee dƒe dƒgƒZee dƒe dƒdgƒZer^ddl m!Z!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'n(ddl!m!Z!m"Z"m#Z#ddl(m%Z%m&Z&m'Z'ej)j*Gdd„dej+j,ƒƒZ-ej)j*Gdd„de-ƒƒZ.dS)é)Úprint_functionN)Ú_Úlogger)ÚPY3)Úucd)ÚnameÚversionÚcodenameÚos_release_attrcCstƒtƒtƒfS©N)rrr ©r r ú4/usr/lib/python3.9/site-packages/dnf-plugins/copr.pyÚlinux_distribution.srcCsdS)NÚr )rr r r r 1sr )rc Cs„tdƒh}i}|D]<}z$| ¡ d¡\}}| d¡||<WqtyLYq0q|d|ddfWdƒS1sv0YdS)Nz/etc/os-releaseú=ú"ÚNAMEZ VERSION_ID)ÚopenÚrstripÚsplitÚstripÚ ValueError)Zos_release_fileZos_release_dataÚlineZos_release_keyZos_release_valuer r r r7s  ÚcoprZyesÚyÚnoÚnr)Ú ConfigParserÚ NoOptionErrorÚNoSectionError)ÚurlopenÚ HTTPErrorÚURLErrorc@s eZdZdZdZdZdZdZdZedeZ dZ e d ƒZ d Z e d ƒZed d „ƒZdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zed$d%„ƒZd&d'„Zd(d)„Zd*d+„Z d,d-„Z!d.d/„Z"d0d1„Z#ed2d3„ƒZ$ed4d5„ƒZ%ed6d7„ƒZ&dS)8Ú CoprCommandz Copr plugin for DNF Nzcopr.fedorainfracloud.orgZfedoraÚhttpsi»ú://)rz Interact with Copr repositories.Ta” enable name/project [chroot] disable name/project remove name/project list --installed/enabled/disabled list --available-by-user=NAME search project Examples: copr enable rhscl/perl516 epel-6-x86_64 copr enable ignatenkobrain/ocltoys copr disable rhscl/perl516 copr remove rhscl/perl516 copr list --enabled copr list --available-by-user=ignatenkobrain copr search tests cCs|jddgd¢d| ¡}|jddtdƒd|jd dtd ƒd|jd dtd ƒd|jd dtdƒd|jdtdƒd|jddddS)NÚ subcommandé)ÚhelpÚenableÚdisableÚremoveÚlistÚsearch©ÚnargsÚchoicesz --installedÚ store_truez.List all installed Copr repositories (default))Úactionr(z --enabledzList enabled Copr repositoriesz --disabledzList disabled Copr repositoriesz--available-by-userrz-List available Copr repositories by user NAME)Úmetavarr(z--hubz(Specify an instance of Copr to work with)r(ÚargÚ*)r/)Ú add_argumentÚadd_mutually_exclusive_groupr)ÚparserZ list_optionr r r Ú set_argparserps$ÿÿÿÿÿzCoprCommand.set_argparsercCsˆ|jjjjdkrdSd}tƒ}g}|jjjd}tj  |t d¡}tj  |¡r¨|  |¡|  |¡| dd¡rž| dd¡rž| dd¡}| dd¡}||g|_n ddg|_t tj  |t d¡¡D],}| d¡rÀtj  |t d|¡} |  | ¡qÀg} t|jjƒr|jjd d ¡} t| ƒd krR|jjrRt td ƒtd ƒ¡tj td ƒ¡‚nJ|jjs|t| ƒd kr||j|_|j|_n t| ƒd kr”| d}n|jj}|rB|rBd|_|  t |dd¡| !||dd¡} | rB| !||d|j"¡} | !||d|j#¡} | |_| d| |_t$| ƒ|j#krB|jd| 7_|jd| 7_|js„d|vrl||_|j"d||_n| dd¡d|_||_dS)Nrrz.confÚmainÚ distributionÚ releaseverFz.dú/éúError: z^specify Copr hub either with `--hub` or using `copr_hub/copr_username/copr_projectname` formatzmultiple hubs specifiedT)ÚreverseÚhostnameÚprotocolÚportr%ú:r')%ÚcliZcommandÚoptsrÚbaseÚconfZpluginconfpathÚosÚpathÚjoinÚ PLUGIN_CONFÚisfileÚappendÚreadZ has_optionÚgetÚ chroot_configÚlistdirÚendswithÚlenr4rÚhubrÚcriticalrÚdnfÚCliErrorÚdefault_hostnameÚ copr_hostnameÚ default_urlÚcopr_urlÚsortedÚ_read_config_itemÚdefault_protocolÚ default_portÚint)ÚselfZcopr_hubZcopr_plugin_configZ config_filesZ config_pathZdefault_config_filer;r<ÚfilenameZ config_fileÚprojectrArBrCr r r Ú configure„sv     ÿ      ÿÿ    ÿ ÿ zCoprCommand.configurec Cs.z| ||¡WSttfy(|YS0dSr )rPrr)rbZconfigrUÚsectionÚdefaultr r r r^ÐszCoprCommand._read_config_itemcCstj d | ¡¡¡dS)Nú{0} )ÚsysÚstderrÚwriteÚformatr)rbÚtextr r r Ú_user_warning_before_promptÖsz'CoprCommand._user_warning_before_promptc Csà|jjd}|dkr&|jj |¡dS|dkrl|jjrH| |jj¡dS| |jj j d|jj |jj ¡dSz|jj d}WnJttfyÆt tdƒtdƒ¡|jj |¡tj tdƒ¡‚Yn0z\|jj d}t|jj ƒdkrötj tdƒ¡‚| d ¡|_t|jƒd kr"tj td ƒ¡‚Wn(tyL| ¡}| d ¡|_Yn0|d krf| |¡dS| d ¡}t|ƒdvr¦t tdƒtdƒ¡tj tdƒ¡‚nexactly two additional parameters to copr command are requiredr'ézToo many arguments.ú-r>zOBad format of optional chroot. The format is distribution-version-architecture.r-r=)ror>zEuse format `copr_username/copr_projectname` to reference copr projectzbad copr project formatz{0}/_copr:{1}:{2}:{3}.repor)a Enabling a Copr repository. Please note that this repository is not part of the main distribution, and quality may vary. The Fedora Project does not exercise any power over the contents of this repository beyond the rules outlined in the Copr FAQ at , and packages are not held to any quality or security level. Please do not file bug reports about these packages in Fedora Bugzilla. In case of problems, contact the owner of this repository. z!Do you really want to enable {0}?z Repository successfully enabled.r*z!Repository successfully disabled.r+z Repository successfully removed.úUnknown subcommand {}.)(rFr&rEZ optparserÚ print_helpZavailable_by_userÚ_list_user_projectsÚ_list_installed_repositoriesrGrHZreposdirÚenabledZdisabledr4rÚ IndexErrorrrVrrWrXrTÚ exceptionsÚErrorrÚ chroot_partsÚ _guess_chrootÚ_searchrlÚ get_reposdirrZÚ_sanitize_usernameÚ _need_rootrKÚ _ask_userÚ_download_repoÚinfoÚ_runtime_deps_warningÚ _disable_repoÚ _remove_repo) rbr&Ú project_nameÚchrootrdÚ copr_usernameÚcopr_projectnameÚ repo_filenamerÚmsgr r r ÚrunÙsš  ÿÿÿÿ      ÿÿ    þ  ÿ        ÿzCoprCommand.runcCs‚|j d¡d}t d|j|¡}|j|jko8t d|¡}t d|¡}|jjr\|sd|sddSn|sddSt d|¡rtdSt d|¡r„dS|j } | r’|sš| sž|rždSd} t d |¡rØ| d d ¡\} } } }| d| d|}n‚t d|¡r,| d d ¡}|  d d¡d d d ¡d } | d|dd|d }n.| d d ¡}|j d|dd|d }d} | sh|d7}| rv|d7}t |ƒ| S)Nr=éÿÿÿÿú_copr:Z_copr_z_copr:|^_copr_zcopr:.*:.*:.*:mlz coprdep:.*Fúcopr:rDr>rpr'rorTz (disabled)z *) ÚrepofilerÚreÚmatchrZr\r[rFrUruÚrsplitrYÚprint)rbÚrepo_idÚrepoÚ enabled_onlyÚ disabled_onlyÚ file_nameZ match_newZ match_oldZ match_anyruÚold_reporrZZ copr_ownerZcopr_dirrŠZ copr_namer r r Ú_list_repo_file8sB      zCoprCommand._list_repo_filecCsBd}|jj ¡D]\}}| ||||¡rd}q|r>ttdƒƒdS)NFTz* These coprs have repo file with an old format that contains no information about Copr hub - the default one was assumed. Re-enable the project to fix this.)rGÚreposÚitemsršr“r)rbZ directoryr–r—r™r”r•r r r rtis z(CoprCommand._list_installed_repositoriesc CsÐd |¡}|j|}|jj|dd}zt | ¡¡}Wn(ty^tj   t dƒ |¡¡‚Yn0|  |¡t dƒ |¡}|  |¡|dD]@}d ||d¡}|d p¬t d ƒ} |jj t|ƒ| ¡}t|ƒqŠdS) Nz!/api_3/project/list?ownername={0}úw+©Úmodez+Can't parse repositories for username '{}'.zList of {} coprsrœz {0}/{1} : rÚ descriptionzNo description given©rlr\rGr ÚjsonÚloadsrOrrWrwrxrÚ_check_json_outputÚ_print_match_sectionÚoutputZ fmtKeyValFillrr“) rbZ user_nameÚapi_pathÚurlÚresÚ json_parseÚ section_textÚitemrŠÚdescr r r rsss&   ÿÿ    zCoprCommand._list_user_projectsc CsÎd |¡}|j|}|jj|dd}zt | ¡¡}Wn(ty^tj   t dƒ |¡¡‚Yn0|  |¡t dƒ |¡}|  |¡|dD]>}d |d¡}|d pªt d ƒ} |jj t|ƒ| ¡}t|ƒqŠdS) Nz/api_3/project/search?query={}rržzCan't parse search for '{}'.z Matched: {}rœz{0} : Z full_namer zNo description given.r¡) rbÚqueryr§r¨r©rªr«r¬rŠr­r r r r{ˆs"   ÿ    zCoprCommand._searchcCs|jj |¡}t|ƒdSr )rGr¦Z fmtSectionr“)rbrmÚ formattedr r r r¥œsz CoprCommand._print_match_sectioncCsh|jstj d¡d|_tj d | ¡¡¡|j ¡rd|jjj s`|jj j d |¡d |¡dsddSdS)NÚ Frhz {} [y/N]: z {} [Y/n]: )rŠZdefaultyes_msgT) Ú first_warningrirjrkrlrrGZ _promptWantedrHZassumenor¦Z userconfirm©rbrrŠr r r Ú_ask_user_no_raise s  ÿzCoprCommand._ask_user_no_raisecCs | ||¡stj tdƒ¡‚dS)NzSafe and good answer. Exiting.)r³rWrwrxrr²r r r r¬s zCoprCommand._ask_usercCs t ¡dkrtj tdƒ¡‚dS)Nrz/This command has to be run under the root user.)rIÚgeteuidrWrwrxr)Úclsr r r r~°s ÿzCoprCommand._need_rootcCs|j}|dus&|ddus&|ddur,tƒ}|jjjd}d|dvr€d|vrXd|}n&d td ƒvrnd|}nd  |d|¡}n–d |vr¸t d ¡}d|vr¦d |¡}nd |d|¡}n^d|vrðt d¡}d|vrÞd |¡}nd |d|¡}n&d |d  dd¡d|r|nd¡}|S)z2 Guess which chroot is equivalent to this machine NrFr'ZbasearchZFedoraZRawhidezfedora-rawhide-ZrawhideZredhat_support_product_versionzfedora-{0}-{1}ZMageiaz%{distro_arch}ZCauldronzmageia-cauldron-{}zmageia-{0}-{1}ZopenSUSEz%{_target_cpu}Z Tumbleweedzopensuse-tumbleweed-{}zopensuse-leap-{0}-{1}z epel-{}-{}Ú.Zx86_64) rQrrGrHÚ substitutionsr rlÚrpmZ expandMacror)rbZdistZdistarchr†r r r rz·s,         &zCoprCommand._guess_chrootc CsÊd |jdd…¡}|jd}d |||¡}z*t|j|ƒ}tj |¡rRt |¡Wnbt yn}zþ|j dkrœt dƒ |j||j t |ƒ¡}t j |¡‚t dƒ}|j d¡} | rñsz-CoprCommand._download_repo..z¿ If you want to enable a non-default repository, use the following command: 'dnf copr enable {0} ' But note that the installed repo file will likely need a manual modification.zProject {0} does not exist.zFailed to connect to {0}: {1}z\[copr:rr'éþÿÿÿz.reporÚ_coprrrDZgroup_ú@Úwb),rKryrlr r\rIrJÚexistsr+r!ÚcoderÚstrrWrwrxZheadersrPÚbase64Z b64decodeÚdecoder¢r£r"ÚreasonÚstrerrorÚreadlinerr‘rGrHr|r[ÚreplacerZrrkÚ readlinesÚchmodÚstatÚS_IRUSRÚS_IWUSRÚS_IRGRPÚS_IROTH)rbr…r‰Z short_chrootZarchr§ZresponseÚeZ error_msgZ error_dataZerror_data_decodedZ first_linerZold_repo_filenameÚfr r r r€Üsj        ÿ ÿ  ý " $ÿÿÿþ    .zCoprCommand._download_repocsÌ|jjdd|j ¡| | |¡|¡‰g}ˆj ¡D]}| d¡rHq8| |¡q8|s\dSt dƒ}t   d¡‰|  d  ‡‡fdd „|Dƒ¡¡}| |t d ƒ¡sÈ|D]$}|jj ˆj||jjjd d i¡q¢dS) a, In addition to the main copr repo (that has repo ID prefixed with `copr:`), the repofile might contain additional repositories that serve as runtime dependencies. This method informs the user about the additional repos and provides an option to disable them. T)r›rŽNaºMaintainer of the enabled Copr repository decided to make it dependent on other repositories. Such repositories are usually necessary for successful installation of RPMs from the main Copr repository (they provide runtime dependencies). Be aware that the note about quality and bug-reporting above applies here too, Fedora Project doesn't control the content. Please review the list: {0} These repositories have been enabled automatically.r'z c s*g|]"}djtˆƒ|ˆj |d¡d‘qS)z){num:2}. [{repoid}] baseurl={baseurl}Úbaseurl)ZnumÚrepoidrÓ)rlÚnextÚcfgZgetValue)rºrÔ©Zcounterr•r r Ú 8s ü ýz5CoprCommand._runtime_deps_warning..z!Do you want to keep them enabled?ruÚ0)rGÚresetZread_all_reposÚ_get_copr_repor}rÖÚsectionsÚ startswithrNrÚ itertoolsÚcountrlrKr³rHÚwrite_raw_configfilerr·)rbr‡rˆZ runtime_depsr”rZdepr r×r r‚s.   ÿ û þz!CoprCommand._runtime_deps_warningcCsÐd |j dd¡d| |¡|¡}||jjvrÄd | |¡|¡}}||jjvrÀd|jj|jvrÀ|jj|j d¡d}z0| dd ¡d dd¡d}||jkr¨WdSWqÄty¼YqÄ0ndS|jj|S) Nzcopr:{0}:{1}:{2}rDr'rz{0}-{1}r¾r=rŒro) rlrZr’r}rGr›rrrv)rbr‡rˆr”r˜rZr r r rÛFs$þ  ÿ   zCoprCommand._get_copr_repoc Csv| ||¡}|s,tj td |j||¡ƒ¡‚zt |j ¡Wn4t yp}ztj t |ƒ¡‚WYd}~n d}~00dS)Nz&Failed to remove copr repo {0}/{1}/{2}) rÛrWrwrxrrlrZrIr+rÚOSErrorrÃ)rbr‡rˆr•rÑr r r r„\s ÿÿzCoprCommand._remove_repocCs`| ||¡}|dur,tj td ||¡ƒ¡‚|j ¡D]$}|jj   |j ||jj j ddi¡q6dS)Nz!Failed to disable copr repo {}/{}rurÙ) rÛrWrwrxrrlrÖrÜrGrHràrr·)rbr‡rˆr•r”r r r rƒhs ÿÿÿzCoprCommand._disable_repocCs<zt | ¡¡}Wn$ty6tj tdƒ¡YdS0|S)z¤ Wrapper around response from server check data and print nice error in case of some error (and return None) otherwise return json object. úUnknown response from server.N)r¢r£rOrrWrErXr)rµrÒr¦r r r Ú _get_datats  zCoprCommand._get_datacCs"d|vrtj d |d¡¡‚dS)NÚerrorz{})rWrwrxrl)rµZjson_objr r r r¤‚szCoprCommand._check_json_outputcCs&|ddkrd |dd…¡S|SdS)Nrr¿zgroup_{}r'r¹)rµr‡r r r r}‡s zCoprCommand._sanitize_username)'Ú__name__Ú __module__Ú __qualname__Ú__doc__rQrYZ default_hubr_r`r[ÚaliasesrÚsummaryr±ÚusageÚ staticmethodr9rer^rnr‹ršrtrsr{r¥r³rÚ classmethodr~rzr€r‚rÛr„rƒrãr¤r}r r r r r#PsL  L_1   %82    r#c@sDeZdZdZdZedƒZdZdd„Zdd„Z e d d „ƒZ d d „Z d S)ÚPlaygroundCommandz Playground plugin for DNF )Z playgroundz$Interact with Playground repository.z [enable|disable|upgrade]c Cs0| ¡| tdƒtdƒ¡d |j¡}|jj|dd}| |¡}| ¡|ddkrft j   tdƒ¡‚|d D]¼}d  |d |d ¡}d  |jj j | dd¡¡}zp||dvr²Wqnd |j||¡}|jj|dd}| |¡}| ¡|rd|vr|ddkr| ||¡Wqnt jjy(Yqn0qndS)Nz!Enabling a Playground repository.zDo you want to continue?z{0}/api/playground/list/rržr¦Úokrâr›z{0}/{1}ÚusernameZcoprnamez{}/_playground_{}.repor=rpZchrootsz{0}/api/coprs/{1}/detail/{2}/)r~rrrlr\rGr rãÚcloserWrErXrHr|rÉr€rwrx) rbr†Zapi_urlrÒr¦r•r…r‰Zoutput2r r r Ú _cmd_enable—sBþÿ    ÿ ÿ  ÿzPlaygroundCommand._cmd_enablecCs2| ¡t d |jjj¡¡D]}| |¡qdS)Nz{}/_playground_*.repo)r~ÚglobrlrGrHr|r„)rbr‰r r r Ú _cmd_disable·szPlaygroundCommand._cmd_disablecCs|jddgd¢ddS)Nr&r')r)r*Úupgrader.)r6)r8r r r r9¼sÿzPlaygroundCommand.set_argparsercCs¦tj d¡‚|jjd}| ¡}|dkrB| |¡t t dƒ¡n`|dkrb|  ¡t t dƒ¡n@|dkrŒ|  ¡| |¡t t dƒ¡ntj t d ƒ  |¡¡‚dS) Nz%Playground is temporarily unsupportedrr)z-Playground repositories successfully enabled.r*z.Playground repositories successfully disabled.rõz-Playground repositories successfully updated.rq) rWrwrxrFr&rzròrrrrôrl)rbr&r†r r r r‹Ás      ÿzPlaygroundCommand.runN) rårærçrèrérrêrëròrôrìr9r‹r r r r rîs  rî)/Z __future__rrórÞr¢rIrÚshutilrÌrirÄZdnfpluginscorerrrWZ dnf.pycomprZdnf.i18nrr¸Zdistrorrr r rÚ ImportErrorÚplatformrLÚsetZYESZNOZ configparserrrrZurllib.requestr r!r"Zurllib2ZpluginZregister_commandrEZCommandr#rîr r r r ÚsP       B