3 ft`O@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+ej,dZ-Gdd d e.Z/Gd d d e/Z0Gd d d e/Z1dS))absolute_import)unicode_literals)misc)ucd_) basestringurlparseNdnfcs~eZdZdZdddZddZfddZd d Zd d Zd dZ ddZ e fddZ e fddZddZeddZZS) BaseConfigzlBase class for storing configuration definitions. Subclass when creating your own definitions. NcCs||jd<||_dS)N_config)__dict___section)selfconfigsectionparserr/usr/lib/python3.6/config.py__init__<s zBaseConfig.__init__cCszd|jkrtdj|j|t|j|}|dkr4dSy|j}Wn tk rb}zdSd}~XnXt|t rvt |S|S)Nr z!'{}' object has no attribute '{}') r AttributeErrorformat __class__getattrr getValue Exception isinstancestrr)rnameoptionvalueZexrrr __getattr__@s   zBaseConfig.__getattr__cs:t|j|d}|dkr(tt|j||S|j||tdS)N)rr superr __setattr__ _set_value PRIO_RUNTIME)rrrr)rrrr"NszBaseConfig.__setattr__c Cstg}|jd|j|jrjxN|jjD]@}y|jj}Wntk rPd}YnX|jd|j|fq&Wdj|S)Nz[%s]z%s: %s ) appendr r optBindssecondgetValueString RuntimeErrorfirstjoin)routoptBindrrrr__str__Us zBaseConfig.__str__cCst|j|d}|dk S)N)rr )rrmethodrrr _has_optionaszBaseConfig._has_optioncCs$t|j|d}|dkrdS|jS)N)rr r)rrr1rrr _get_valueeszBaseConfig._get_valuecCs$t|j|d}|dkrdS|jS)N)rr Z getPriority)rrr1rrr _get_prioritykszBaseConfig._get_prioritycCst|j|d}|dkr&td|d|}|dkr\y|j||Wntk rXYnXnyrt|tsrt|tr|j|tjj |nDt|tjj st|tjj rt|t r|j|t |n |j||WnHtk r}z*tjjtd|t|ft|dWYdd}~XnXdS)zSSet option's value if priority is equal or higher than current priority.NzOption "z" does not existszError parsing '%s': %s) raw_error)rr rsetrlisttuplelibdnfconf VectorStringZ OptionBoolZOptionChildBoolintboolr+r exceptions ConfigErrorrr)rrrpriorityr1rerrrr#qs*   zBaseConfig._set_valuecCs|j|rx|j|D]}|j||}| s4|dkr8d}t|j|ry|jjj|j||Wqtk r}z,t j t dt |t |t |t |WYdd}~XqXq|dkrt||rt|||qt jt dt |t |t |qWdS)z+Set option values from an INI file section.Noner%z,Invalid configuration value: %s=%s in %s; %sNarchz+Unknown configuration option: %s = %s in %s) hasSectionZoptionsZgetSubstitutedValuehasattrr r(at newStringr+loggererrorrrrsetattrdebug)rrrfilenamer@rrrArrr _populates     0zBaseConfig._populatec Cshd|jg}|jrZxF|jjD]8}y|jd|j|jjfWqtk rTYqXqWdj|dS)z]Return a string representing the values of all the configuration options. z[%s]z%s = %sr&) r r r(r'r,r)r*r+r-)routputr/rrrdumps  zBaseConfig.dumpcCstjj}|j||j|sHx(|jD]}tjjj|||kr(|}q(Wx6|jD]*\}}t|t rndj |}|j |||qRW|j |ddS)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) r9r: ConfigParserreadrDZgetData substituteitemsrr7r-ZsetValuewrite)rLZ section_id substitutionsZmodifyrZsectrrrrrwrite_raw_configfiles     zBaseConfig.write_raw_configfile)NNN)__name__ __module__ __qualname____doc__rr r"r0r2r3r4r$r# PRIO_DEFAULTrMrO staticmethodrW __classcell__rr)rrr 5s     r cseZdZdZd%fdd ZddZedd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZeddZejddZeddZejddZeddZejd dZdefd!d"Zed#d$ZZS)&MainConfz?Configuration option definitions for dnf.conf's [main] section.mainNcstjj}tt|j||||jdtjj gt |jdtjj gt tjj j |_ tj|_|jjjt tjjtjjrtjj}d}nVytj}}WnDttfk r}z$tdjt|}tjj|WYdd}~XnX|jj jt ||jj!jt |g|_"dS)NZ pluginpathZpluginconfpathz/var/logzCould not set cachedir: {})#r9r: ConfigMainr!r_rr#r constZ PLUGINPATHr\ZPLUGINCONFPATHrVZ SubstitutionshawkeyZ detect_archrCr Zsystem_cachedirr6ZSYSTEM_CACHEDIRutilZ am_i_rootrZ getCacheDirIOErrorOSErrorrrrr>Errorcachedirlogdir tempfiles)rrrrrhrirAmsg)rrrrs$   zMainConf.__init__cCsx|jD]}tj|qWdS)N)rjosunlink)r file_namerrr__del__s zMainConf.__del__cCsLd}x$|jdD]}tjj|r|}PqW|sH|jdd}tjj||S)zReturns the value of reposdirNZreposdirr)r3rlpathexistsr rdZ ensure_dir)rZ myrepodirZrdirrrr get_reposdirs  zMainConf.get_reposdirc Cs|j|}|j|}t|trtj|}|ddkrF|j||j|ntjj }t j dd\}}|j j |zdy|jd||Wn>tk r}z"tjjtdj|t|WYdd}~XnX|j|||Wdtj|XdS) z In case the option value is a remote URL, download it to the temporary location and use this temporary file instead. rfiler%zdnf-downloaded-config-)prefixNz9Configuration file URL "{}" could not be downloaded: {})rsr%)r4r3rrrr#rpr9ZrepoZ DownloadertempfileZmkstemprjr'Z downloadURLr+r r>r?rrrrlclose) roptnamepriovallocationZ downloaderZtemp_fdZ temp_pathrArrr_check_remote_files"        zMainConf._check_remote_filecsjddkrSj|}|tkr,Sj|}t|tstfdd|Drj|tjj fdd|D|Sn4t j j t j j |jdrj|j||SdS)z Return root used as prefix for option (installroot or "/"). When specified from commandline it returns value from conf.installroot installroot/c3s*|]"}tjjtjj|jdVqdS)r}N)rlrprqr-lstrip).0p)r|rr *sz6MainConf._search_inside_installroot..csg|]}j|qSr)_prepend_installroot_path)rr)rrr -sz7MainConf._search_inside_installroot..)r3r4PRIO_COMMANDLINErranyr#r9r:r;rlrprqr-r~r)rrwrxryr)r|rr_search_inside_installroots$    z#MainConf._search_inside_installrootcCs,|j|}|j|j|}|j|||dS)N)r4rr3r#)rrwrxnew_pathrrrprepend_installroot6s zMainConf.prepend_installrootcCs,tjj|jd|jd}tjjj||j S)Nr|r}) rlrpr-r3r~r9r:rQrSrV)rrpZ root_pathrrrr<sz"MainConf._prepend_installroot_pathc Cs`ddddddddd d d d dd dddddddddddddg}x|D]}t||d}|dk ob|gkrB|j|r$d}|jry|jjj|j}Wntk rYnX|rtjj }||j |kr|j |}xR|D]6}|r|j ||j ||g|q|j |gtjj qWn|j ||tjj qBt ||r>t|||qBtjtdt|t|qBWt|d ddkr|j ddtjj t |dr\x|jjD]\}}x|D]} t |j|r"y|jjj|jt | WnJtk r} z,tjjtd || t| ft| d!WYdd} ~ XnXn.t ||rr?r) roptsZ config_argsrrZ appendValueZ add_priorityitemvaluesryrArkrrr_configure_from_options@s\         . z MainConf._configure_from_optionscCsPd}|dk rL|gkrL|j|r2|j||tjjntjtdt|t|dS)Nrz%Unknown configuration option: %s = %s) r2r#r r:rrHrrr)rZpkgsrrrr exclude_pkgss   zMainConf.exclude_pkgscCs(|jd}|r$|jd| |jddS)z Adjust conf options interactionsrstrictN)r3r#r4)rZskip_broken_valrrr_adjust_conf_optionss zMainConf._adjust_conf_optionscCs |jjdS)N releasever)rVget)rrrrrszMainConf.releasevercCs,|dkr|jjdddSt||jd<dS)Nr)rVpopr)rryrrrrscCs |jjdS)NrC)rVr)rrrrrCsz MainConf.archcCsb|dkr|jjdddS|tjjjkrFtd}tjj|j d|||jd<tjj ||_ dS)NrCzIncorrect or unknown "{}": {}) rVrr rpm _BASEARCH_MAPkeysrr>rgrr)rryrkrrrrCs cCs |jjdS)Nr)rVr)rrrrrszMainConf.basearchcCsT|dkr|jjdddS|tjjjkrFtd}tjj|j d|||jd<dS)NrzIncorrect or unknown "{}": {}) rVrr rrrrr>rgr)rryrkrrrrscCs|dkr|jd}tjj}y|j|Wndtk rd}ztjjt d||fWYdd}~Xn,t k r}zt j |WYdd}~XnX|j ||j|||jd||dS)NrzParsing file "%s" failed: %s)r3r9r:rQrRr+r r>r?rrerHrrMr r#)rrLr@rrArrrrRs  (z MainConf.readcCs|jdtjjkS)Nr)r3r rbZ VERBOSE_LEVEL)rrrrverboseszMainConf.verbose)r`N)rXrYrZr[rropropertyrrr{rrrrrrrsetterrCrr\rRrr^rr)rrr_s& ?     r_cs*eZdZdZdfdd ZddZZS)RepoConfz4Option definitions for repository INI file sections.NcsP|r |jntjj}tt|jtjj|||||_|rL|jj j t |dS)N) r r9r:rar!rrZ ConfigRepoZ_mainConfigRefHolderrr6r\)rparentrrZ mainConfig)rrrrs zRepoConf.__init__c Cst|dddkr0xd D]}|j|dtjjqWt|di}x|jD]\}}tj|j|s^qFx|jD]\}}x|D]}t|j |ry|j j j |j t|WnLt k r} z0tjjtd|j||t| ft| dWYdd} ~ XnXqvtd} tj| |j|qvWqhWqFWdS) zConfigure repos from the opts. rNF repo_gpgcheck repo_setoptsz7Error parsing --setopt with key '%s.%s', value '%s': %s)r5z-Repo %s did not have a %s attr. before setopt)rr)rr#r r:rrTfnmatchr rEr r(rFrGr+r>r?rrrHr) rrrwrZrepoidZsetoptsrrryrArkrrrrs$    2z RepoConf._configure_from_options)NN)rXrYrZr[rrr^rr)rrrs r)2Z __future__rrZdnf.yumrZdnf.i18nrrZ dnf.pycomprrrZdnf.conf.substitutionsr Z dnf.constZdnf.exceptionsZdnf.utilrcZloggingrlZ libdnf.confr9Z libdnf.reporur:ZOptionZPriority_EMPTYZ PRIO_EMPTYZPriority_DEFAULTr\ZPriority_MAINCONFIGZPRIO_MAINCONFIGZPriority_AUTOMATICCONFIGZPRIO_AUTOMATICCONFIGZPriority_REPOCONFIGZPRIO_REPOCONFIGZPriority_PLUGINDEFAULTZPRIO_PLUGINDEFAULTZPriority_PLUGINCONFIGZPRIO_PLUGINCONFIGZPriority_COMMANDLINErZPriority_RUNTIMEr$Z getLoggerrHobjectr r_rrrrrs@