<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
<e                 @   s\   d dl Zd dlmZmZ d dlmZ d dljZd dl	m
Z
 dgZejj ZG dd dZdS )    N)ConfigParserError)TunedException)commandsGlobalConfigc               @   sd   e Zd ZejfddZedd ZejfddZddd	Z	dd
dZ
dddZdd ZdddZdS )r   c             C   s   i | _ | j|d t | _d S )N)	file_name)_cfgload_configr   _cmd)selfZconfig_file r   #/usr/lib/python3.6/global_config.py__init__   s    zGlobalConfig.__init__c              C   s>   dd t tD } tdd | D }tdd | D }||fS )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
		}
		c             S   s2   g | ]*}|j d r|j d r|j d r|qS )ZCFG_	CFG_FUNC_CFG_DEF_)
startswith).0optr   r   r   
<listcomp>   s    
z7GlobalConfig.get_global_config_spec.<locals>.<listcomp>c             s   s0   | ](}t t|t td |dd  dfV  qdS )r      N)getattrconsts)r   r   r   r   r   	<genexpr>    s    z6GlobalConfig.get_global_config_spec.<locals>.<genexpr>c             s   s0   | ](}t t|t td |dd  dfV  qdS )r   r   Nget)r   r   )r   r   r   r   r   r   !   s    )dirr   dict)optionsZglobal_defaultZglobal_functionr   r   r   get_global_config_spec   s    
z#GlobalConfig.get_global_config_specc             C   s\  t jd|  ytdddd}t|_t|$}|jdtj d |j	  | W dQ R X | j
 \| _}x|jtjD ]}|| jkry$t||| }|tj|| j|< W q tk
r   td	| Y qX qrt jd
||f  |jtj|dd| j|< qrW W n^ tk
r( } ztd| W Y dd}~X n0 tk
rV } ztd| W Y dd}~X nX dS )z&
		Loads global configuration file.
		z2reading and parsing global configuration file '%s'=#F)Z
delimitersZinline_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   strZoptionxformopenZread_stringr   ZMAGIC_HEADER_NAMEreadr   r   r   r   r   r   infor   IOError)r   r   Zconfig_parserfZ_global_config_funcZoptionfuncer   r   r   r	   $   s*    
(
 zGlobalConfig.load_configNc             C   s   | j j||S )N)r   r   )r   keydefaultr   r   r   r   ?   s    zGlobalConfig.getc             C   s    | j j| j||dkrdS dS )N1TF)r
   get_boolr   )r   r-   r.   r   r   r   r0   B   s    zGlobalConfig.get_boolr   c             C   s.   | j j||}|r*t|tr |S t|dS |S )Nr   )r   r   
isinstanceint)r   r-   r.   ir   r   r   get_intG   s    

zGlobalConfig.get_intc             C   s   || j |< d S )N)r   )r   r-   valuer   r   r   setP   s    zGlobalConfig.setc             C   sH   | j |}|d kr|S | jj|}|d kr@tjd||f  |S |S d S )Nz%Error parsing value '%s', using '%s'.)r   r
   get_sizer#   error)r   r-   r.   valretr   r   r   r7   S   s    
zGlobalConfig.get_size)N)N)r   )N)__name__
__module____qualname__r   ZGLOBAL_CONFIG_FILEr   staticmethodr   r	   r   r0   r4   r6   r7   r   r   r   r   r      s   


	)Z
tuned.logsZtunedZtuned.utils.config_parserr   r   Ztuned.exceptionsr   Ztuned.constsr   Ztuned.utils.commandsr   __all__Zlogsr   r#   r   r   r   r   r   <module>   s   

