Your IP : 3.145.43.92


Current Path : /usr/lib/python3.6/site-packages/tuned/utils/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/tuned/utils/__pycache__/global_config.cpython-36.pyc

3

�<�e��@s\ddlZddlmZmZddlmZddljZddl	m
Z
dgZejj
�ZGdd�d�ZdS)�N)�ConfigParser�Error)�TunedException)�commands�GlobalConfigc@sdeZdZejfdd�Zedd��Zejfdd�Zddd	�Z	dd
d�Z
dd
d�Zdd�Zddd�Z
dS)rcCsi|_|j|d�t�|_dS)N)�	file_name)�_cfg�load_configr�_cmd)�selfZconfig_file�r�#/usr/lib/python3.6/global_config.py�__init__
szGlobalConfig.__init__cCs>dd�tt�D�}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|]*}|jd�r|jd�r|jd�r|�qS)ZCFG_�	CFG_FUNC_�CFG_DEF_)�
startswith)�.0�optrrr
�
<listcomp>s
z7GlobalConfig.get_global_config_spec.<locals>.<listcomp>css0|](}tt|�ttd|dd�d�fVqdS)r�N)�getattr�consts)rrrrr
�	<genexpr> sz6GlobalConfig.get_global_config_spec.<locals>.<genexpr>css0|](}tt|�ttd|dd�d�fVqdS)rrN�get)rr)rrrrr
r!s)�dirr�dict)�optionsZglobal_defaultZglobal_functionrrr
�get_global_config_specs
z#GlobalConfig.get_global_config_speccCs\tjd|�y�tdddd�}t|_t|��$}|jdtjd|j	�|�WdQRX|j
�\|_}x�|jtj�D]�}||jkr�y$t
|||�}|tj|�|j|<Wq�tk
r�td	|��Yq�Xqrtjd
||f�|jtj|dd�|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_prefixes�strict�[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'.)�log�debugr�strZoptionxform�openZread_stringrZMAGIC_HEADER_NAME�readrrrrrr�infor�IOError)rrZ
config_parser�fZ_global_config_funcZoption�func�errr
r	$s*
(
 zGlobalConfig.load_configNcCs|jj||�S)N)rr)r�key�defaultrrr
r?szGlobalConfig.getcCs |jj|j||��dkrdSdS)N�1TF)r
�get_boolr)rr-r.rrr
r0BszGlobalConfig.get_boolrcCs.|jj||�}|r*t|t�r |St|d�S|S)Nr)rr�
isinstance�int)rr-r.�irrr
�get_intGs

zGlobalConfig.get_intcCs||j|<dS)N)r)rr-�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)rr-r.�val�retrrr
r7Ss
zGlobalConfig.get_size)N)N)r)N)�__name__�
__module__�__qualname__rZGLOBAL_CONFIG_FILEr�staticmethodrr	rr0r4r6r7rrrr
rs


	)Z
tuned.logsZtunedZtuned.utils.config_parserrrZtuned.exceptionsrZtuned.constsrZtuned.utils.commandsr�__all__Zlogsrr#rrrrr
�<module>s



?>