a ©2ÑhÏYã@s<ddlmZddlmZddlmZddlmZmZddlm Z m Z ddl Z ddl Z ddlZ ddlZ ddlZ ddlZ ddlZddlZddlZddlZddlZddlZejjjZejjjZejjjZejjj Z!ejjj"Z#ejjj$Z%ejjj&Z'ejjj(Z)ejjj*Z+e ,d¡Z-Gdd „d e.ƒZ/Gd d „d e/ƒZ0Gd d „d e/ƒZ1dS)é)Úabsolute_import)Úunicode_literals)Úmisc)ÚucdÚ_)Ú basestringÚurlparseNÚdnfcsŠeZdZdZddd„Zdd„Z‡fdd„Zd d „Zd d „Zd d„Z dd„Z e fdd„Z e fdd„Zdd„Ze fdd„Zedd„ƒZ‡ZS)Ú BaseConfigzlBase class for storing configuration definitions. Subclass when creating your own definitions. NcCs||jd<||_dS)NÚ_config)Ú__dict__Ú_section)ÚselfÚconfigÚsectionÚparser©rú3/usr/lib/python3.9/site-packages/dnf/conf/config.pyÚ__init__<s zBaseConfig.__init__c Cs€d|jvrtd |j|¡ƒ‚t|j|ƒ}|dur4dSz|ƒ ¡}Wn&tyh}zWYd}~dSd}~00t|t ƒr|t |ƒS|S)Nr z!'{}' object has no attribute '{}') r ÚAttributeErrorÚformatÚ __class__Úgetattrr ÚgetValueÚ ExceptionÚ isinstanceÚstrr)rÚnameÚoptionÚvalueÚexrrrÚ __getattr__@s   zBaseConfig.__getattr__cs:t|j|dƒ}|dur(tt|ƒ ||¡S| ||t¡dS©N)rr Úsuperr Ú __setattr__Ú _set_valueÚ PRIO_RUNTIME)rrrr©rrrr$NszBaseConfig.__setattr__c Csng}| d|j¡|jrd|j ¡D]>}z|j ¡}WntyLd}Yn0| d|j|f¡q$d |¡S)Nú[%s]Úz%s: %sÚ ) Úappendr r ÚoptBindsÚsecondÚgetValueStringÚ RuntimeErrorÚfirstÚjoin)rÚoutÚoptBindrrrrÚ__str__Us  zBaseConfig.__str__cCst|j|dƒ}|duSr")rr ©rrÚmethodrrrÚ _has_optionaszBaseConfig._has_optioncCs$t|j|dƒ}|durdS|ƒ ¡Sr")rr rr5rrrÚ _get_valueeszBaseConfig._get_valuecCs$t|j|dƒ}|durdS|ƒ ¡Sr")rr Z getPriorityr5rrrÚ _get_prioritykszBaseConfig._get_priorityc Cst|j|dƒ}|dur&td|dƒ‚|ƒ}|durZz| ||¡WntyVYn0n¾zrt|tƒspt|tƒr†| |tj  |¡¡nDt|tjj ƒs¢t|tjj ƒr¾t|t ƒr¾| |t |ƒ¡n | ||¡WnJty}z0tjjtdƒ|t|ƒft|ƒd‚WYd}~n d}~00dS)zSSet option's value if priority is equal or higher than current priority.NzOption "z" does not existszError parsing '%s': %s©Z raw_error)rr rÚsetrÚlistÚtupleÚlibdnfÚconfÚ VectorStringZ OptionBoolZOptionChildBoolÚintÚboolr/r Ú exceptionsÚ ConfigErrorrr)rrrÚpriorityr6rÚerrrr%qs2  ÿþ  ÿþzBaseConfig._set_valuec Csð| |¡rì| |¡D]Ö}| ||¡}|r0|dkr4d}t|j|ƒrªz|j ¡ |¡ ||¡Wqêty¦}z2t   t dƒt |ƒt |ƒt |ƒt |ƒ¡WYd}~qêd}~00q|dkrÊt||ƒrÊt|||ƒqt  t dƒt |ƒt |ƒt |ƒ¡qdS)z+Set option values from an INI file section.ÚNoner)z,Invalid configuration value: %s=%s in %s; %sNÚarchz+Unknown configuration option: %s = %s in %s)Ú hasSectionÚoptionsZgetSubstitutedValueÚhasattrr r,ÚatÚ newStringr/ÚloggerÚerrorrrrÚsetattrÚdebug)rrrÚfilenamerErrrFrrrÚ _populateŒs$     ÿþzBaseConfig._populatec Csbd|jg}|jrT|j ¡D]6}z| d|j|j ¡f¡WqtyPYq0qd |¡dS)z]Return a string representing the values of all the configuration options. r(z%s = %sr*) r r r,r+r0r-r.r/r1)rÚoutputr3rrrÚdump¡s  zBaseConfig.dumpc Csn|j ¡}z| |¡ ||¡WnHtyh}z0tj tdƒ  ||t |ƒ¡t |ƒ¡‚WYd}~n d}~00dS)aÔFor standard options, sets the value of the option if the priority is equal to or higher than the current priority. For "append" options, appends the values parsed from value_string to the current list of values. If the first parsed element of the list of values is empty and the priority is equal to or higher than the current priority, the current list is replaced with the new values. If the priority is higher than the current priority, the current priority is increased to the priority. Raises dnf.exceptions.ConfigError if the option with the given name does not exist or value_string contains an invalid value or not allowed value. zCannot set "{}" to "{}": {}N) r r,rLrMr/r rCrDrrr)rrZ value_stringrEZ opt_bindsrFrrrÚset_or_append_opt_value²s ÿz"BaseConfig.set_or_append_opt_valuecCsˆtj ¡}| |¡| |¡sD| ¡D]}tjj ||¡|kr&|}q&| ¡D]*\}}t|t ƒrhd  |¡}|  |||¡qL|  |d¡dS)zö filename - name of config file (.conf or .repo) section_id - id of modified section (e.g. main, fedora, updates) substitutions - instance of base.conf.substitutions modify - dict of modified options ú FN) r>r?Ú ConfigParserÚreadrIZgetDataÚ substituteÚitemsrr<r1ZsetValueÚwrite)rRZ section_idÚ substitutionsZmodifyrZsectrrrrrÚwrite_raw_configfileÄs      zBaseConfig.write_raw_configfile)NNN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr!r$r4r7r8r9r&r%Ú PRIO_DEFAULTrSrUrVÚ staticmethodr^Ú __classcell__rrr'rr 5s      r cs eZdZdZd+‡fdd„ Zdd„Zedd „ƒZd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zedd„ƒZejdd„ƒZedd„ƒZejdd„ƒZedd„ƒZejd d„ƒZed!d"„ƒZejd#d"„ƒZed$d%„ƒZejd&d%„ƒZdefd'd(„Zed)d*„ƒZ‡ZS),ÚMainConfz?Configuration option definitions for dnf.conf's [main] section.ÚmainNc stj ¡}tt|ƒ |||¡| dtjj gt ¡| dtjj gt ¡tjj   ¡|_ t ¡|_|j ¡ t tjj¡tj ¡rŒtjj}d}nXzt ¡}}WnFttfyâ}z*tdƒ t|ƒ¡}tj |¡‚WYd}~n d}~00|j  ¡ t |¡|j !¡ t |¡g|_"dS)NZ pluginpathZpluginconfpathz/var/logzCould not set cachedir: {})#r>r?Ú ConfigMainr#rfrr%r ÚconstZ PLUGINPATHrcZPLUGINCONFPATHr]Z SubstitutionsÚhawkeyZ detect_archrHr Zsystem_cachedirr;ZSYSTEM_CACHEDIRÚutilZ am_i_rootrZ getCacheDirÚIOErrorÚOSErrorrrrrCÚErrorÚcachedirÚlogdirÚ tempfiles)rrrrrorprFÚmsgr'rrrâs$   "zMainConf.__init__cCs|jD]}t |¡qdSr")rqÚosÚunlink)rÚ file_namerrrÚ__del__ýs zMainConf.__del__cCsJd}| d¡D]}tj |¡r|}q(q|sF| d¡d}tj |¡|S)zReturns the value of reposdirNZreposdirr)r8rsÚpathÚexistsr rkZ ensure_dir)rZ myrepodirZrdirrrrÚ get_reposdirs  zMainConf.get_reposdirc Csî| |¡}| |¡}t|tƒrêt |¡}|ddvrF| ||j|¡n¤tj  ¡}t j dd\}}|j   |¡zpz| d||¡Wn@tyÀ}z(tj tdƒ |t|ƒ¡¡‚WYd}~nd}~00| |||¡Wt |¡n t |¡0dS)zŽ In case the option value is a remote URL, download it to the temporary location and use this temporary file instead. r)Úfiler)zdnf-downloaded-config-)ÚprefixNz9Configuration file URL "{}" could not be downloaded: {})r9r8rrrr%rwr>ZrepoZ DownloaderÚtempfileZmkstemprqr+Z downloadURLr/r rCrDrrrrsÚclose) rÚoptnameÚprioÚvalÚlocationZ downloaderZtemp_fdZ temp_pathrFrrrÚ_check_remote_files&       ÿÿzMainConf._check_remote_filecs¸ˆ d¡‰ˆdkrˆSˆ |¡}|tkr,ˆSˆ |¡}t|tƒs€t‡fdd„|Dƒƒr´ˆ |tj  ‡fdd„|Dƒ¡|¡ˆSn4t j   t j   ˆ| d¡¡¡r´ˆ |ˆ |¡|¡ˆSdS)zœ Return root used as prefix for option (installroot or "/"). When specified from commandline it returns value from conf.installroot Ú installrootú/c 3s*|]"}tj tj ˆ| d¡¡¡VqdS)r„N)rsrwrxr1Úlstrip©Ú.0Úp)rƒrrÚ <óz6MainConf._search_inside_installroot..csg|]}ˆ |¡‘qSr)Ú_prepend_installroot_pathr†©rrrÚ ?rŠz7MainConf._search_inside_installroot..)r8r9ÚPRIO_COMMANDLINErrÚanyr%r>r?r@rsrwrxr1r…r‹)rr~rr€r)rƒrrÚ_search_inside_installroot,s&    ýz#MainConf._search_inside_installrootcCs,| |¡}| | |¡¡}| |||¡dSr")r9r‹r8r%)rr~rÚnew_pathrrrÚprepend_installrootHs zMainConf.prepend_installrootcCs,tj | d¡| d¡¡}tjj ||j ¡S)Nrƒr„) rsrwr1r8r…r>r?rXrZr])rrwZ root_pathrrrr‹Nsz"MainConf._prepend_installroot_pathc Csgd¢}|D] }t||dƒ}|dur |gkr | |¡räd}|jrnz|j ¡ |¡ ¡}WntylYn0|rÐtjj }||  |¡kr’|  |¡}|D]6}|rº|  ||  |¡|g|¡q–|  |gtjj ¡q–n|  ||tjj ¡q t ||ƒrþt|||ƒq t tdƒt|ƒt|ƒ¡q t|ddƒdur>|  ddtjj ¡t |dƒr|j ¡D]¾\}}|D]®} t |j|ƒrÞz|j ¡ |¡ t | ¡WnLtyÚ} z2tjjtdƒ|| t| ƒft| ƒd ‚WYd} ~ n d} ~ 00n.t ||ƒrøt||| ƒntd ƒ} t | |¡q`qTdS) z%Configure parts of CLI from the opts )ÚpluginsÚversionÚconfig_file_pathÚ debuglevelZ errorlevelrƒZbestZ assumeyesZassumenoZclean_requirements_on_removeÚgpgcheckZshowdupesfromreposr“Z ip_resolveZ rpmverbosityZdisable_excludesZcolorZ downloadonlyZ persistenceZexcludeÚ excludepkgsÚ skip_brokenZtsflagsrHÚbasearchZ ignorearchZ cacheonlyZcommentNFú%Unknown configuration option: %s = %sr—Zlocalpkg_gpgcheckÚ main_setoptsz4Error parsing --setopt with key '%s', value '%s': %sr:z1Main config did not have a %s attr. before setopt)rr7r r,rLZ getAddValuer/r r?rŽr9r%r8rKrPrNÚwarningrrrœr[rMrCrDr) rÚoptsZ config_argsrrZ appendValueZ add_priorityÚitemÚvaluesr€rFrrrrrÚ_configure_from_optionsRsX        ÿ  ÿþ z MainConf._configure_from_optionscCsPd}|durL|gkrL| |¡r2| ||tjj¡nt tdƒt|ƒt|ƒ¡dS)Nr˜r›) r7r%r r?rŽrNrrr)rZpkgsrrrrÚ exclude_pkgs‘s   ÿzMainConf.exclude_pkgscCs(| d¡}|r$| d| | d¡¡dS)z Adjust conf options interactionsr™ÚstrictN)r8r%r9)rZskip_broken_valrrrÚ_adjust_conf_optionsœs zMainConf._adjust_conf_optionscCs |j d¡S)NÚ releasever©r]ÚgetrŒrrrr¥£szMainConf.releasevercCs,|dur|j dd¡dSt|ƒ|jd<dS)a Sets the releasever variable and sets releasever_major and releasever_minor accordingly. releasever_major is set to the part of $releasever before the first ".". releasever_minor is set to the part after the first ".". Nr¥©r]Úpopr©rr€rrrr¥¨s cCs |j d¡S)NÚreleasever_majorr¦rŒrrrr«¶szMainConf.releasever_majorcCs,|dur|j dd¡dSt|ƒ|jd<dS)z¶ Override the releasever_major variable, which is usually derived from the releasever variable. This setter does not update the value of $releasever. Nr«r¨rªrrrr«»scCs |j d¡S)NÚreleasever_minorr¦rŒrrrr¬ÈszMainConf.releasever_minorcCs,|dur|j dd¡dSt|ƒ|jd<dS)z¶ Override the releasever_minor variable, which is usually derived from the releasever variable. This setter does not update the value of $releasever. Nr¬r¨rªrrrr¬ÍscCs |j d¡S)NrHr¦rŒrrrrHÚsz MainConf.archcCsb|dur|j dd¡dS|tjj ¡vrFtdƒ}tj |  d|¡¡‚||jd<tj  |¡|_ dS)NrHúIncorrect or unknown "{}": {}) r]r©r ÚrpmÚ _BASEARCH_MAPÚkeysrrCrnrrš©rr€rrrrrrHßs cCs |j d¡S)Nršr¦rŒrrrršìszMainConf.basearchcCsT|dur|j dd¡dS|tjj ¡vrFtdƒ}tj |  d|¡¡‚||jd<dS)Nršr­) r]r©r r®r¯r rrCrnrr±rrrršñsc Cs¸|dur| d¡}tj ¡}z| |¡Wnhtyf}z$tj t dƒ||f¡‚WYd}~n6d}~0t y’}zt   |¡WYd}~n d}~00|  ||j||¡| d||¡dS)Nr•zParsing file "%s" failed: %s)r8r>r?rXrYr/r rCrDrrlrNrrSr r%)rrRrErrFrrrrYýs  , z MainConf.readcCs| d¡tjjkS)Nr–)r8r riZ VERBOSE_LEVELrŒrrrÚverbose szMainConf.verbose)rgN)r_r`rarbrrvÚpropertyryr‚rr’r‹r¡r¢r¤r¥Úsetterr«r¬rHršrcrYr²rerrr'rrfßsF ?           rfcs*eZdZdZd‡fdd„ Zdd„Z‡ZS)ÚRepoConfz4Option definitions for repository INI file sections.NcsP|r |jntj ¡}tt|ƒ tj |¡||¡||_|rL|j  ¡  t |¡dSr") r r>r?rhr#rµrZ ConfigRepoZ_mainConfigRefHolderrr;rc)rÚparentrrZ mainConfigr'rrrs zRepoConf.__init__c Cs t|ddƒdur,dD]}| |dtjj¡qt|diƒ}| ¡D]Æ\}}t |j|¡sXq@| ¡D]¤\}}|D]–}t|j |ƒrêz|j   ¡  |¡  t|¡WnNt yæ} z6tjjtdƒ|j||t| ƒft| ƒd‚WYd} ~ n d} ~ 00qltdƒ} t | |j|¡qlq`q@dS) zConfigure repos from the opts. r—NF)r—Z repo_gpgcheckÚ repo_setoptsz7Error parsing --setopt with key '%s.%s', value '%s': %sr:z-Repo %s did not have a %s attr. before setopt)rr%r r?rŽr[Úfnmatchr rKr r,rLrMr/rCrDrrrNr) rržr~r·ZrepoidZsetoptsrr r€rFrrrrrr¡s*  ÿþz RepoConf._configure_from_options)NN)r_r`rarbrr¡rerrr'rrµs rµ)2Z __future__rrZdnf.yumrZdnf.i18nrrZ dnf.pycomprrr¸Zdnf.conf.substitutionsr Z dnf.constZdnf.exceptionsZdnf.utilrjZloggingrsZ libdnf.confr>Z libdnf.repor|r?ZOptionZPriority_EMPTYZ PRIO_EMPTYZPriority_DEFAULTrcZPriority_MAINCONFIGZPRIO_MAINCONFIGZPriority_AUTOMATICCONFIGZPRIO_AUTOMATICCONFIGZPriority_REPOCONFIGZPRIO_REPOCONFIGZPriority_PLUGINDEFAULTZPRIO_PLUGINDEFAULTZPriority_PLUGINCONFIGZPRIO_PLUGINCONFIGZPriority_COMMANDLINErŽZPriority_RUNTIMEr&Z getLoggerrNÚobjectr rfrµrrrrÚs@             +5