3 ddttD}tdd|D}tdd|D}||fS)ai Easy validation mimicking configobj Returns two dicts, first with default values (default None) global_default[consts.CFG_SOMETHING] = consts.CFG_DEF_SOMETHING or None second with configobj function for value type (default "get" for string, others eg getboolean, getint) global_function[consts.CFG_SOMETHING] = consts.CFG_FUNC_SOMETHING or get } cSs2g|]*}|jdr|jd r|jd r|qS)ZCFG_ CFG_FUNC_CFG_DEF_) startswith).0optr r r s  z7GlobalConfig.get_global_config_spec..css0|](}tt|ttd|dddfVqdS)rN)getattrconsts)rrr r r sz6GlobalConfig.get_global_config_spec..css0|](}tt|ttd|dddfVqdS)rrNget)rr)rrr r r r!s)dirrdict)optionsZglobal_defaultZglobal_functionr r r get_global_config_specs z#GlobalConfig.get_global_config_speccCs\tjd|ytdddd}t|_t|$}|jdtjd|j |WdQRX|j \|_ }x|j tjD]}||j kry$t |||}|tj||j |<Wqtk rtd |YqXqrtjd ||f|jtj|d d |j |<qrWWn^tk r(}ztd |WYdd}~Xn0tk rV}ztd|WYdd}~XnXdS)z& Loads global configuration file. z2reading and parsing global configuration file '%s'=#F)Z delimitersZinline_comment_prefixesstrict[z] Nz2Global TuneD configuration file '%s' is not valid.z/Unknown option '%s' in global config file '%s'.T)rawz/Global TuneD configuration file '%s' not found.z3Error parsing global TuneD configuration file '%s'.)logdebugrstrZ optionxformopenZ read_stringrZMAGIC_HEADER_NAMEreadrrrrrrinforIOError)r rZ config_parserfZ_global_config_funcZoptionfuncer r r r $s* (  zGlobalConfig.load_configNcCs|jj||S)N)rr)r keydefaultr r r r?szGlobalConfig.getcCs |jj|j||dkrdSdS)N1TF)r get_boolr)r r-r.r r r r0BszGlobalConfig.get_boolrcCs.|jj||}|r*t|tr |St|dS|S)Nr)rr isinstanceint)r r-r.ir r r get_intGs   zGlobalConfig.get_intcCs||j|<dS)N)r)r r-valuer r r setPszGlobalConfig.setcCsH|j|}|dkr|S|jj|}|dkr@tjd||f|S|SdS)Nz%Error parsing value '%s', using '%s'.)rr get_sizer#error)r r-r.valretr r r r7Ss  zGlobalConfig.get_size)N)N)r)N)__name__ __module__ __qualname__rZGLOBAL_CONFIG_FILEr staticmethodrr rr0r4r6r7r r r r r s    )Z tuned.logsZtunedZtuned.utils.config_parserrrZtuned.exceptionsrZ tuned.constsrZtuned.utils.commandsr__all__Zlogsrr#rr r r r s