__pycache__/__init__.cpython-36.opt-1.pyc000064400000002207147205131140014077 0ustar003 ft`@spdZddlmZddlmZddlmZmZmZddlmZm Z m Z ddlm Z m Z ddlm Z mZmZeZdS) aL The configuration classes and routines in yum are splattered over too many places, hard to change and debug. The new structure here will replace that. Its goal is to: * accept configuration options from all three sources (the main config file, repo config files, command line switches) * handle all the logic of storing those and producing related values. * returning configuration values. * optionally: asserting no value is overridden once it has been applied somewhere (e.g. do not let a new repo be initialized with different global cache path than an already existing one). )absolute_import)unicode_literals) PRIO_DEFAULTPRIO_MAINCONFIGPRIO_AUTOMATICCONFIG)PRIO_REPOCONFIGPRIO_PLUGINDEFAULTPRIO_PLUGINCONFIG)PRIO_COMMANDLINE PRIO_RUNTIME) BaseConfigMainConfRepoConfN)__doc__Z __future__rrZdnf.conf.configrrrrrr r r r r rZConfrr/usr/lib/python3.6/__init__.py#s  __pycache__/__init__.cpython-36.pyc000064400000002207147205131140013140 0ustar003 ft`@spdZddlmZddlmZddlmZmZmZddlmZm Z m Z ddlm Z m Z ddlm Z mZmZeZdS) aL The configuration classes and routines in yum are splattered over too many places, hard to change and debug. The new structure here will replace that. Its goal is to: * accept configuration options from all three sources (the main config file, repo config files, command line switches) * handle all the logic of storing those and producing related values. * returning configuration values. * optionally: asserting no value is overridden once it has been applied somewhere (e.g. do not let a new repo be initialized with different global cache path than an already existing one). )absolute_import)unicode_literals) PRIO_DEFAULTPRIO_MAINCONFIGPRIO_AUTOMATICCONFIG)PRIO_REPOCONFIGPRIO_PLUGINDEFAULTPRIO_PLUGINCONFIG)PRIO_COMMANDLINE PRIO_RUNTIME) BaseConfigMainConfRepoConfN)__doc__Z __future__rrZdnf.conf.configrrrrrr r r r r rZConfrr/usr/lib/python3.6/__init__.py#s  __pycache__/config.cpython-36.opt-1.pyc000064400000035047147205131140013615 0ustar003 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@              __pycache__/config.cpython-36.pyc000064400000035047147205131140012656 0ustar003 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@              __pycache__/read.cpython-36.opt-1.pyc000064400000006411147205131140013254 0ustar003 ft`@s~ddlmZddlmZddlmZmZddlZddlZ ddl Zddl Zddl Z ddl Z ddlZe jdZGdddeZdS))absolute_import)unicode_literals)_ucdNdnfc@s,eZdZddZddZddZddZd S) RepoReadercCs||_||_dS)N)confopts)selfrr r /usr/lib/python3.6/read.py__init__$szRepoReader.__init__c csx|j|jjD] }|VqWg}x8|jjD],}x&tjtjj|dD]}|j|qFWq,W|j dddxT|D]L}yx|j|D] }|VqWWqrt j j k rt jtd|YqrXqrWdS)Nz*.repocSstjj|ddS)N)rutilZ split_path)xr r r 5sz%RepoReader.__iter__..)keyz'Warning: failed loading '%s', skipping.) _get_reposrZconfig_file_pathreposdirglobospathjoinappendsortr exceptions ConfigErrorloggerwarningr)r rZ repo_configsrrrepofnr r r __iter__(s   zRepoReader.__iter__c Cs^tjjj||jj}tjj|}|dk rl||krJtdj |||||}ntdj ||||}tj j |tjj ||j}y|j |||tjjWnZtk r}z>||krtdj |||}ntdj ||}tj j |WYdd}~XnX|jdtjjkr8||kr tdj ||}ntdj |}tj|t|j|_|jj|jj||_|S) z)Build a repository using the parsed data.Nz&Bad id for repo: {} ({}), byte = {} {}z!Bad id for repo: {}, byte = {} {}z.Repository '{}' ({}): Error parsing config: {}z)Repository '{}': Error parsing config: {}namez@Repository '{}' ({}) is missing name in configuration, using id.z;Repository '{}' is missing name in configuration, using id.)libdnfr ConfigParserZ substitute substitutionsrrepoZrepo_id_invalidrformatrrZRepoZ _populateZPRIO_REPOCONFIG ValueErrorZ _get_priorityZ PRIO_DEFAULTrrrr#Z_substitutionsupdateZcfg) r parserZid_r!Zsubstituted_idZinvalidmsgr'er r r _build_repo?s8         zRepoReader._build_repoccs|jj}tjj}|j|y|j|Wndtk rd}ztjj t dj ||WYdd}~Xn,t k r}zt j|WYdd}~XnXx|jD]x}|dkrqy|j|t||}Wn:tjjtjj fk r}zt j|wWYdd}~XnX||_|j|j|VqWdS)z4Parse and yield all repositories from a config file.zParsing file "{}" failed: {}Nmain)rr&r$r%ZsetSubstitutionsread RuntimeErrorrrrrr(IOErrorrrZgetDatar.rZ RepoErrorZrepofileZ_configure_from_optionsr )r r!Zsubstsr+r-ZsectionZthisrepor r r rhs(  (  zRepoReader._get_reposN)__name__ __module__ __qualname__r r"r.rr r r r r#s)r)Z __future__rrZdnf.i18nrrZdnf.confrZ libdnf.confr$Zdnf.exceptionsZdnf.reporZloggingrZ getLoggerrobjectrr r r r s   __pycache__/read.cpython-36.pyc000064400000006411147205131140012315 0ustar003 ft`@s~ddlmZddlmZddlmZmZddlZddlZ ddl Zddl Zddl Z ddl Z ddlZe jdZGdddeZdS))absolute_import)unicode_literals)_ucdNdnfc@s,eZdZddZddZddZddZd S) RepoReadercCs||_||_dS)N)confopts)selfrr r /usr/lib/python3.6/read.py__init__$szRepoReader.__init__c csx|j|jjD] }|VqWg}x8|jjD],}x&tjtjj|dD]}|j|qFWq,W|j dddxT|D]L}yx|j|D] }|VqWWqrt j j k rt jtd|YqrXqrWdS)Nz*.repocSstjj|ddS)N)rutilZ split_path)xr r r 5sz%RepoReader.__iter__..)keyz'Warning: failed loading '%s', skipping.) _get_reposrZconfig_file_pathreposdirglobospathjoinappendsortr exceptions ConfigErrorloggerwarningr)r rZ repo_configsrrrepofnr r r __iter__(s   zRepoReader.__iter__c Cs^tjjj||jj}tjj|}|dk rl||krJtdj |||||}ntdj ||||}tj j |tjj ||j}y|j |||tjjWnZtk r}z>||krtdj |||}ntdj ||}tj j |WYdd}~XnX|jdtjjkr8||kr tdj ||}ntdj |}tj|t|j|_|jj|jj||_|S) z)Build a repository using the parsed data.Nz&Bad id for repo: {} ({}), byte = {} {}z!Bad id for repo: {}, byte = {} {}z.Repository '{}' ({}): Error parsing config: {}z)Repository '{}': Error parsing config: {}namez@Repository '{}' ({}) is missing name in configuration, using id.z;Repository '{}' is missing name in configuration, using id.)libdnfr ConfigParserZ substitute substitutionsrrepoZrepo_id_invalidrformatrrZRepoZ _populateZPRIO_REPOCONFIG ValueErrorZ _get_priorityZ PRIO_DEFAULTrrrr#Z_substitutionsupdateZcfg) r parserZid_r!Zsubstituted_idZinvalidmsgr'er r r _build_repo?s8         zRepoReader._build_repoccs|jj}tjj}|j|y|j|Wndtk rd}ztjj t dj ||WYdd}~Xn,t k r}zt j|WYdd}~XnXx|jD]x}|dkrqy|j|t||}Wn:tjjtjj fk r}zt j|wWYdd}~XnX||_|j|j|VqWdS)z4Parse and yield all repositories from a config file.zParsing file "{}" failed: {}Nmain)rr&r$r%ZsetSubstitutionsread RuntimeErrorrrrrr(IOErrorrrZgetDatar.rZ RepoErrorZrepofileZ_configure_from_optionsr )r r!Zsubstsr+r-ZsectionZthisrepor r r rhs(  (  zRepoReader._get_reposN)__name__ __module__ __qualname__r r"r.rr r r r r#s)r)Z __future__rrZdnf.i18nrrZdnf.confrZ libdnf.confr$Zdnf.exceptionsZdnf.reporZloggingrZ getLoggerrobjectrr r r r s   __pycache__/substitutions.cpython-36.opt-1.pyc000064400000003552147205131140015303 0ustar003 fj @sLddlZddlZddlZddlmZejdZejdZGddde Z dS)N)_z^DNF_VAR_[A-Za-z0-9_]+$Zdnfcs.eZdZfddZddZd ddZZS) Substitutionscstt|j|jdS)N)superr__init___update_from_env)self) __class__#/usr/lib/python3.6/substitutions.pyr"szSubstitutions.__init__cCs\ddtddD}xBtjjD]4\}}tj|rD|||dd<q ||kr |||<q WdS)NcSsg|] }d|qS)zDNF%dr ).0Znumr r r 'sz2Substitutions._update_from_env..r )rangeosenvironitemsENVIRONMENT_VARS_REmatch)rZ numericvarskeyvalr r r r&s  zSubstitutions._update_from_env/etc/yum/vars//etc/dnf/vars/c Csx|D]}g}y"tjj||jd}tj|}Wntk rJwYnXx|D]}tjj||}d}tjj|rys    __pycache__/substitutions.cpython-36.pyc000064400000003552147205131140014344 0ustar003 fj @sLddlZddlZddlZddlmZejdZejdZGddde Z dS)N)_z^DNF_VAR_[A-Za-z0-9_]+$Zdnfcs.eZdZfddZddZd ddZZS) Substitutionscstt|j|jdS)N)superr__init___update_from_env)self) __class__#/usr/lib/python3.6/substitutions.pyr"szSubstitutions.__init__cCs\ddtddD}xBtjjD]4\}}tj|rD|||dd<q ||kr |||<q WdS)NcSsg|] }d|qS)zDNF%dr ).0Znumr r r 'sz2Substitutions._update_from_env..r )rangeosenvironitemsENVIRONMENT_VARS_REmatch)rZ numericvarskeyvalr r r r&s  zSubstitutions._update_from_env/etc/yum/vars//etc/dnf/vars/c Csx|D]}g}y"tjj||jd}tj|}Wntk rJwYnXx|D]}tjj||}d}tjj|rys    __init__.py000064400000003671147205131140006662 0ustar00# conf.py # dnf configuration classes. # # Copyright (C) 2012-2016 Red Hat, Inc. # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of # the GNU General Public License v.2, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY expressed or implied, including the implied warranties of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. You should have received a copy of the # GNU General Public License along with this program; if not, write to the # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. Any Red Hat trademarks that are incorporated in the # source code or documentation are not subject to the GNU General Public # License and may only be used or replicated with the express permission of # Red Hat, Inc. # """ The configuration classes and routines in yum are splattered over too many places, hard to change and debug. The new structure here will replace that. Its goal is to: * accept configuration options from all three sources (the main config file, repo config files, command line switches) * handle all the logic of storing those and producing related values. * returning configuration values. * optionally: asserting no value is overridden once it has been applied somewhere (e.g. do not let a new repo be initialized with different global cache path than an already existing one). """ from __future__ import absolute_import from __future__ import unicode_literals from dnf.conf.config import PRIO_DEFAULT, PRIO_MAINCONFIG, PRIO_AUTOMATICCONFIG from dnf.conf.config import PRIO_REPOCONFIG, PRIO_PLUGINDEFAULT, PRIO_PLUGINCONFIG from dnf.conf.config import PRIO_COMMANDLINE, PRIO_RUNTIME from dnf.conf.config import BaseConfig, MainConf, RepoConf Conf = MainConf config.py000064400000047737147205131140006403 0ustar00# dnf configuration classes. # # Copyright (C) 2016-2017 Red Hat, Inc. # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of # the GNU General Public License v.2, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY expressed or implied, including the implied warranties of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. You should have received a copy of the # GNU General Public License along with this program; if not, write to the # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. Any Red Hat trademarks that are incorporated in the # source code or documentation are not subject to the GNU General Public # License and may only be used or replicated with the express permission of # Red Hat, Inc. # from __future__ import absolute_import from __future__ import unicode_literals from dnf.yum import misc from dnf.i18n import ucd, _ from dnf.pycomp import basestring, urlparse import fnmatch import dnf.conf.substitutions import dnf.const import dnf.exceptions import dnf.pycomp import dnf.util import hawkey import logging import os import libdnf.conf import libdnf.repo import tempfile PRIO_EMPTY = libdnf.conf.Option.Priority_EMPTY PRIO_DEFAULT = libdnf.conf.Option.Priority_DEFAULT PRIO_MAINCONFIG = libdnf.conf.Option.Priority_MAINCONFIG PRIO_AUTOMATICCONFIG = libdnf.conf.Option.Priority_AUTOMATICCONFIG PRIO_REPOCONFIG = libdnf.conf.Option.Priority_REPOCONFIG PRIO_PLUGINDEFAULT = libdnf.conf.Option.Priority_PLUGINDEFAULT PRIO_PLUGINCONFIG = libdnf.conf.Option.Priority_PLUGINCONFIG PRIO_COMMANDLINE = libdnf.conf.Option.Priority_COMMANDLINE PRIO_RUNTIME = libdnf.conf.Option.Priority_RUNTIME logger = logging.getLogger('dnf') class BaseConfig(object): """Base class for storing configuration definitions. Subclass when creating your own definitions. """ def __init__(self, config=None, section=None, parser=None): self.__dict__["_config"] = config self._section = section def __getattr__(self, name): if "_config" not in self.__dict__: raise AttributeError("'{}' object has no attribute '{}'".format(self.__class__, name)) option = getattr(self._config, name) if option is None: return None try: value = option().getValue() except Exception as ex: return None if isinstance(value, str): return ucd(value) return value def __setattr__(self, name, value): option = getattr(self._config, name, None) if option is None: # unknown config option, store to BaseConfig only return super(BaseConfig, self).__setattr__(name, value) self._set_value(name, value, PRIO_RUNTIME) def __str__(self): out = [] out.append('[%s]' % self._section) if self._config: for optBind in self._config.optBinds(): try: value = optBind.second.getValueString() except RuntimeError: value = "" out.append('%s: %s' % (optBind.first, value)) return '\n'.join(out) def _has_option(self, name): method = getattr(self._config, name, None) return method is not None def _get_value(self, name): method = getattr(self._config, name, None) if method is None: return None return method().getValue() def _get_priority(self, name): method = getattr(self._config, name, None) if method is None: return None return method().getPriority() def _set_value(self, name, value, priority=PRIO_RUNTIME): """Set option's value if priority is equal or higher than current priority.""" method = getattr(self._config, name, None) if method is None: raise Exception("Option \"" + name + "\" does not exists") option = method() if value is None: try: option.set(priority, value) except Exception: pass else: try: if isinstance(value, list) or isinstance(value, tuple): option.set(priority, libdnf.conf.VectorString(value)) elif (isinstance(option, libdnf.conf.OptionBool) or isinstance(option, libdnf.conf.OptionChildBool) ) and isinstance(value, int): option.set(priority, bool(value)) else: option.set(priority, value) except RuntimeError as e: raise dnf.exceptions.ConfigError(_("Error parsing '%s': %s") % (value, str(e)), raw_error=str(e)) def _populate(self, parser, section, filename, priority=PRIO_DEFAULT): """Set option values from an INI file section.""" if parser.hasSection(section): for name in parser.options(section): value = parser.getSubstitutedValue(section, name) if not value or value == 'None': value = '' if hasattr(self._config, name): try: self._config.optBinds().at(name).newString(priority, value) except RuntimeError as e: logger.error(_('Invalid configuration value: %s=%s in %s; %s'), ucd(name), ucd(value), ucd(filename), str(e)) else: if name == 'arch' and hasattr(self, name): setattr(self, name, value) else: logger.debug( _('Unknown configuration option: %s = %s in %s'), ucd(name), ucd(value), ucd(filename)) def dump(self): # :api """Return a string representing the values of all the configuration options. """ output = ['[%s]' % self._section] if self._config: for optBind in self._config.optBinds(): # if not opt._is_runtimeonly(): try: output.append('%s = %s' % (optBind.first, optBind.second.getValueString())) except RuntimeError: pass return '\n'.join(output) + '\n' @staticmethod def write_raw_configfile(filename, section_id, substitutions, modify): # :api """ 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 """ parser = libdnf.conf.ConfigParser() parser.read(filename) # b/c repoids can have $values in them we need to map both ways to figure # out which one is which if not parser.hasSection(section_id): for sect in parser.getData(): if libdnf.conf.ConfigParser.substitute(sect, substitutions) == section_id: section_id = sect for name, value in modify.items(): if isinstance(value, list): value = ' '.join(value) parser.setValue(section_id, name, value) parser.write(filename, False) class MainConf(BaseConfig): # :api """Configuration option definitions for dnf.conf's [main] section.""" def __init__(self, section='main', parser=None): # pylint: disable=R0915 config = libdnf.conf.ConfigMain() super(MainConf, self).__init__(config, section, parser) self._set_value('pluginpath', [dnf.const.PLUGINPATH], PRIO_DEFAULT) self._set_value('pluginconfpath', [dnf.const.PLUGINCONFPATH], PRIO_DEFAULT) self.substitutions = dnf.conf.substitutions.Substitutions() self.arch = hawkey.detect_arch() self._config.system_cachedir().set(PRIO_DEFAULT, dnf.const.SYSTEM_CACHEDIR) # setup different cache and log for non-privileged users if dnf.util.am_i_root(): cachedir = dnf.const.SYSTEM_CACHEDIR logdir = '/var/log' else: try: cachedir = logdir = misc.getCacheDir() except (IOError, OSError) as e: msg = _('Could not set cachedir: {}').format(ucd(e)) raise dnf.exceptions.Error(msg) self._config.cachedir().set(PRIO_DEFAULT, cachedir) self._config.logdir().set(PRIO_DEFAULT, logdir) # track list of temporary files created self.tempfiles = [] def __del__(self): for file_name in self.tempfiles: os.unlink(file_name) @property def get_reposdir(self): # :api """Returns the value of reposdir""" myrepodir = None # put repo file into first reposdir which exists or create it for rdir in self._get_value('reposdir'): if os.path.exists(rdir): myrepodir = rdir break if not myrepodir: myrepodir = self._get_value('reposdir')[0] dnf.util.ensure_dir(myrepodir) return myrepodir def _check_remote_file(self, optname): """ In case the option value is a remote URL, download it to the temporary location and use this temporary file instead. """ prio = self._get_priority(optname) val = self._get_value(optname) if isinstance(val, basestring): location = urlparse.urlparse(val) if location[0] in ('file', ''): # just strip the file:// prefix self._set_value(optname, location.path, prio) else: downloader = libdnf.repo.Downloader() temp_fd, temp_path = tempfile.mkstemp(prefix='dnf-downloaded-config-') self.tempfiles.append(temp_path) try: downloader.downloadURL(None, val, temp_fd) except RuntimeError as e: raise dnf.exceptions.ConfigError( _('Configuration file URL "{}" could not be downloaded:\n' ' {}').format(val, str(e))) else: self._set_value(optname, temp_path, prio) finally: os.close(temp_fd) def _search_inside_installroot(self, optname): """ Return root used as prefix for option (installroot or "/"). When specified from commandline it returns value from conf.installroot """ installroot = self._get_value('installroot') if installroot == "/": return installroot prio = self._get_priority(optname) # don't modify paths specified on commandline if prio >= PRIO_COMMANDLINE: return installroot val = self._get_value(optname) # if it exists inside installroot use it (i.e. adjust configuration) # for lists any component counts if not isinstance(val, str): if any(os.path.exists(os.path.join(installroot, p.lstrip('/'))) for p in val): self._set_value( optname, libdnf.conf.VectorString([self._prepend_installroot_path(p) for p in val]), prio ) return installroot elif os.path.exists(os.path.join(installroot, val.lstrip('/'))): self._set_value(optname, self._prepend_installroot_path(val), prio) return installroot return "/" def prepend_installroot(self, optname): # :api prio = self._get_priority(optname) new_path = self._prepend_installroot_path(self._get_value(optname)) self._set_value(optname, new_path, prio) def _prepend_installroot_path(self, path): root_path = os.path.join(self._get_value('installroot'), path.lstrip('/')) return libdnf.conf.ConfigParser.substitute(root_path, self.substitutions) def _configure_from_options(self, opts): """Configure parts of CLI from the opts """ config_args = ['plugins', 'version', 'config_file_path', 'debuglevel', 'errorlevel', 'installroot', 'best', 'assumeyes', 'assumeno', 'clean_requirements_on_remove', 'gpgcheck', 'showdupesfromrepos', 'plugins', 'ip_resolve', 'rpmverbosity', 'disable_excludes', 'color', 'downloadonly', 'exclude', 'excludepkgs', 'skip_broken', 'tsflags', 'arch', 'basearch', 'ignorearch', 'cacheonly', 'comment'] for name in config_args: value = getattr(opts, name, None) if value is not None and value != []: if self._has_option(name): appendValue = False if self._config: try: appendValue = self._config.optBinds().at(name).getAddValue() except RuntimeError: # fails if option with "name" does not exist in _config (libdnf) pass if appendValue: add_priority = dnf.conf.PRIO_COMMANDLINE if add_priority < self._get_priority(name): add_priority = self._get_priority(name) for item in value: if item: self._set_value(name, self._get_value(name) + [item], add_priority) else: self._set_value(name, [], dnf.conf.PRIO_COMMANDLINE) else: self._set_value(name, value, dnf.conf.PRIO_COMMANDLINE) elif hasattr(self, name): setattr(self, name, value) else: logger.warning(_('Unknown configuration option: %s = %s'), ucd(name), ucd(value)) if getattr(opts, 'gpgcheck', None) is False: self._set_value("localpkg_gpgcheck", False, dnf.conf.PRIO_COMMANDLINE) if hasattr(opts, 'main_setopts'): # now set all the non-first-start opts from main from our setopts # pylint: disable=W0212 for name, values in opts.main_setopts.items(): for val in values: if hasattr(self._config, name): try: # values in main_setopts are strings, try to parse it using newString() self._config.optBinds().at(name).newString(PRIO_COMMANDLINE, val) except RuntimeError as e: raise dnf.exceptions.ConfigError( _("Error parsing --setopt with key '%s', value '%s': %s") % (name, val, str(e)), raw_error=str(e)) else: # if config option with "name" doesn't exist in _config, it could be defined # only in Python layer if hasattr(self, name): setattr(self, name, val) else: msg = _("Main config did not have a %s attr. before setopt") logger.warning(msg, name) def exclude_pkgs(self, pkgs): # :api name = "excludepkgs" if pkgs is not None and pkgs != []: if self._has_option(name): self._set_value(name, pkgs, dnf.conf.PRIO_COMMANDLINE) else: logger.warning(_('Unknown configuration option: %s = %s'), ucd(name), ucd(pkgs)) def _adjust_conf_options(self): """Adjust conf options interactions""" skip_broken_val = self._get_value('skip_broken') if skip_broken_val: self._set_value('strict', not skip_broken_val, self._get_priority('skip_broken')) @property def releasever(self): # :api return self.substitutions.get('releasever') @releasever.setter def releasever(self, val): # :api if val is None: self.substitutions.pop('releasever', None) return self.substitutions['releasever'] = str(val) @property def arch(self): # :api return self.substitutions.get('arch') @arch.setter def arch(self, val): # :api if val is None: self.substitutions.pop('arch', None) return if val not in dnf.rpm._BASEARCH_MAP.keys(): msg = _('Incorrect or unknown "{}": {}') raise dnf.exceptions.Error(msg.format("arch", val)) self.substitutions['arch'] = val self.basearch = dnf.rpm.basearch(val) @property def basearch(self): # :api return self.substitutions.get('basearch') @basearch.setter def basearch(self, val): # :api if val is None: self.substitutions.pop('basearch', None) return if val not in dnf.rpm._BASEARCH_MAP.values(): msg = _('Incorrect or unknown "{}": {}') raise dnf.exceptions.Error(msg.format("basearch", val)) self.substitutions['basearch'] = val def read(self, filename=None, priority=PRIO_DEFAULT): # :api if filename is None: filename = self._get_value('config_file_path') parser = libdnf.conf.ConfigParser() try: parser.read(filename) except RuntimeError as e: raise dnf.exceptions.ConfigError(_('Parsing file "%s" failed: %s') % (filename, e)) except IOError as e: logger.warning(e) self._populate(parser, self._section, filename, priority) # update to where we read the file from self._set_value('config_file_path', filename, priority) @property def verbose(self): return self._get_value('debuglevel') >= dnf.const.VERBOSE_LEVEL class RepoConf(BaseConfig): """Option definitions for repository INI file sections.""" def __init__(self, parent, section=None, parser=None): mainConfig = parent._config if parent else libdnf.conf.ConfigMain() super(RepoConf, self).__init__(libdnf.conf.ConfigRepo(mainConfig), section, parser) # Do not remove! Attribute is a reference holder. # Prevents premature removal of the mainConfig. The libdnf ConfigRepo points to it. self._mainConfigRefHolder = mainConfig if section: self._config.name().set(PRIO_DEFAULT, section) def _configure_from_options(self, opts): """Configure repos from the opts. """ if getattr(opts, 'gpgcheck', None) is False: for optname in ['gpgcheck', 'repo_gpgcheck']: self._set_value(optname, False, dnf.conf.PRIO_COMMANDLINE) repo_setopts = getattr(opts, 'repo_setopts', {}) for repoid, setopts in repo_setopts.items(): if not fnmatch.fnmatch(self._section, repoid): continue for name, values in setopts.items(): for val in values: if hasattr(self._config, name): try: # values in repo_setopts are strings, try to parse it using newString() self._config.optBinds().at(name).newString(PRIO_COMMANDLINE, val) except RuntimeError as e: raise dnf.exceptions.ConfigError( _("Error parsing --setopt with key '%s.%s', value '%s': %s") % (self._section, name, val, str(e)), raw_error=str(e)) else: msg = _("Repo %s did not have a %s attr. before setopt") logger.warning(msg, self._section, name) read.py000064400000012213147205131140006026 0ustar00# read.py # Reading configuration from files. # # Copyright (C) 2014-2017 Red Hat, Inc. # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of # the GNU General Public License v.2, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY expressed or implied, including the implied warranties of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. You should have received a copy of the # GNU General Public License along with this program; if not, write to the # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. Any Red Hat trademarks that are incorporated in the # source code or documentation are not subject to the GNU General Public # License and may only be used or replicated with the express permission of # Red Hat, Inc. # from __future__ import absolute_import from __future__ import unicode_literals from dnf.i18n import _, ucd import dnf.conf import libdnf.conf import dnf.exceptions import dnf.repo import glob import logging import os logger = logging.getLogger('dnf') class RepoReader(object): def __init__(self, conf, opts): self.conf = conf self.opts = opts def __iter__(self): # get the repos from the main yum.conf file for r in self._get_repos(self.conf.config_file_path): yield r # read .repo files from directories specified by conf.reposdir repo_configs = [] for reposdir in self.conf.reposdir: for path in glob.glob(os.path.join(reposdir, "*.repo")): repo_configs.append(path) # remove .conf suffix before calling the sort function # also split the path so the separators are not treated as ordinary characters repo_configs.sort(key=lambda x: dnf.util.split_path(x[:-5])) for repofn in repo_configs: try: for r in self._get_repos(repofn): yield r except dnf.exceptions.ConfigError: logger.warning(_("Warning: failed loading '%s', skipping."), repofn) def _build_repo(self, parser, id_, repofn): """Build a repository using the parsed data.""" substituted_id = libdnf.conf.ConfigParser.substitute(id_, self.conf.substitutions) # Check the repo.id against the valid chars invalid = dnf.repo.repo_id_invalid(substituted_id) if invalid is not None: if substituted_id != id_: msg = _("Bad id for repo: {} ({}), byte = {} {}").format(substituted_id, id_, substituted_id[invalid], invalid) else: msg = _("Bad id for repo: {}, byte = {} {}").format(id_, id_[invalid], invalid) raise dnf.exceptions.ConfigError(msg) repo = dnf.repo.Repo(substituted_id, self.conf) try: repo._populate(parser, id_, repofn, dnf.conf.PRIO_REPOCONFIG) except ValueError as e: if substituted_id != id_: msg = _("Repository '{}' ({}): Error parsing config: {}").format(substituted_id, id_, e) else: msg = _("Repository '{}': Error parsing config: {}").format(id_, e) raise dnf.exceptions.ConfigError(msg) # Ensure that the repo name is set if repo._get_priority('name') == dnf.conf.PRIO_DEFAULT: if substituted_id != id_: msg = _("Repository '{}' ({}) is missing name in configuration, using id.").format( substituted_id, id_) else: msg = _("Repository '{}' is missing name in configuration, using id.").format(id_) logger.warning(msg) repo.name = ucd(repo.name) repo._substitutions.update(self.conf.substitutions) repo.cfg = parser return repo def _get_repos(self, repofn): """Parse and yield all repositories from a config file.""" substs = self.conf.substitutions parser = libdnf.conf.ConfigParser() parser.setSubstitutions(substs) try: parser.read(repofn) except RuntimeError as e: raise dnf.exceptions.ConfigError(_('Parsing file "{}" failed: {}').format(repofn, e)) except IOError as e: logger.warning(e) # Check sections in the .repo file that was just slurped up for section in parser.getData(): if section == 'main': continue try: thisrepo = self._build_repo(parser, ucd(section), repofn) except (dnf.exceptions.RepoError, dnf.exceptions.ConfigError) as e: logger.warning(e) continue else: thisrepo.repofile = repofn thisrepo._configure_from_options(self.opts) yield thisrepo substitutions.py000064400000005152147205131140010056 0ustar00# substitutions.py # Config file substitutions. # # Copyright (C) 2012-2016 Red Hat, Inc. # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of # the GNU General Public License v.2, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY expressed or implied, including the implied warranties of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. You should have received a copy of the # GNU General Public License along with this program; if not, write to the # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. Any Red Hat trademarks that are incorporated in the # source code or documentation are not subject to the GNU General Public # License and may only be used or replicated with the express permission of # Red Hat, Inc. # import logging import os import re from dnf.i18n import _ ENVIRONMENT_VARS_RE = re.compile(r'^DNF_VAR_[A-Za-z0-9_]+$') logger = logging.getLogger('dnf') class Substitutions(dict): # :api def __init__(self): super(Substitutions, self).__init__() self._update_from_env() def _update_from_env(self): numericvars = ['DNF%d' % num for num in range(0, 10)] for key, val in os.environ.items(): if ENVIRONMENT_VARS_RE.match(key): self[key[8:]] = val # remove "DNF_VAR_" prefix elif key in numericvars: self[key] = val def update_from_etc(self, installroot, varsdir=("/etc/yum/vars/", "/etc/dnf/vars/")): # :api for vars_path in varsdir: fsvars = [] try: dir_fsvars = os.path.join(installroot, vars_path.lstrip('/')) fsvars = os.listdir(dir_fsvars) except OSError: continue for fsvar in fsvars: filepath = os.path.join(dir_fsvars, fsvar) val = None if os.path.isfile(filepath): try: with open(filepath) as fp: val = fp.readline() if val and val[-1] == '\n': val = val[:-1] except (OSError, IOError, UnicodeDecodeError) as e: logger.warning(_("Error when parsing a variable from file '{0}': {1}").format(filepath, e)) continue if val is not None: self[fsvar] = val