????

Your IP : 3.15.190.254


Current Path : /lib/python3.6/site-packages/glances/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/glances/__pycache__/config.cpython-36.pyc

3

Eo�c.�@s�dZddlZddlZddlZddlmZddlZddlmZm	Z	m
Z
mZddlm
Z
mZmZmZmZddlmZdd�Zd	d
�Zdd�Zd
d�ZGdd�de�ZdS)zManage the configuration file.�N)�open)�ConfigParser�
NoOptionError�NoSectionError�system_exec)�BSD�LINUX�MACOS�SUNOS�WINDOWS)�loggercCs\trtjjd�}n*tr$tjjd�}ntjjd�p:tjjd�}|dkrJd}ntjj|d�}|S)z�Return the per-user config dir (full path).

    - Linux, *BSD, SunOS: ~/.config/glances
    - macOS: ~/Library/Application Support/glances
    - Windows: %APPDATA%\glances
    �APPDATAz~/Library/Application SupportZXDG_CONFIG_HOMEz	~/.configN��glances)r�os�environ�getr	�path�
expanduser�join)r�r�/usr/lib/python3.6/config.py�user_config_dirsrcCsbtr*tjjtjjd�p tjjd�dd�}n4tr<tjjd�}n"tjjtjjd�pXtjjd�d�}|S)z�Return the per-user cache dir (full path).

    - Linux, *BSD, SunOS: ~/.cache/glances
    - macOS: ~/Library/Caches/glances
    - Windows: {%LOCALAPPDATA%,%APPDATA%}\glances\cache
    ZLOCALAPPDATAr
r�cachez~/Library/Caches/glancesZXDG_CACHE_HOMEz~/.cache)rrrrrrr	r)rrrr�user_cache_dir,s&"rcCsHtstrd}ntstrd}ntjjd�}|dkr6d}ntjj|d�}|S)z�Return the system-wide config dir (full path).

    - Linux, SunOS: /etc/glances
    - *BSD, macOS: /usr/local/etc/glances
    - Windows: %APPDATA%\glances
    z/etcz/usr/local/etcr
Nrr)	rr
rr	rrrrr)rrrr�system_config_dir=srcCsBtstststrd}ntjjd�}|dkr0d}ntjj|d�}|S)z�Return the system-wide config dir (full path).

    - Linux, SunOS, *BSD, macOS: /usr/share/doc (as defined in the setup.py files)
    - Windows: %APPDATA%\glances
    z/usr/share/docr
Nrr)	rr
rr	rrrrr)rrrr�default_config_dirRsrc@s�eZdZdZd'dd�Zdd�Zdd�Zd	d
�Zedd��Z	d
d�Z
dd�Zdd�Zdd�Z
ddddgfdd�Zdd�Zd(dd�Zd)dd �Zd*d"d#�Zd+d%d&�ZdS),�Configz�This class is used to access/read config file, if it exists.

    :param config_dir: the path to search for config file
    :type config_dir: str or None
    NcCsX||_d|_d|_tjd�|_ytdd�|_Wntk
rJt�|_YnX|j	�dS)Nzglances.confz	(\`.+?\`))Z
interpolation)
�
config_dir�config_filename�_loaded_config_file�re�compile�
re_patternr�parser�	TypeError�read)�selfrrrr�__init__lszConfig.__init__cCsbg}|jr|j|j�|jtjjt�|j��|jtjjt�|j��|jtjjt�|j��|S)a�Get a list of config file paths.

        The list is built taking into account of the OS, priority and location.

        * custom path: /path/to/glances
        * Linux, SunOS: ~/.config/glances, /etc/glances
        * *BSD: ~/.config/glances, /usr/local/etc/glances
        * macOS: ~/Library/Application Support/glances, /usr/local/etc/glances
        * Windows: %APPDATA%\glances

        The config file will be searched in the following order of priority:
            * /path/to/file (via -C flag)
            * user's home directory (per-user settings)
            * system-wide directory (system-wide settings)
            * default pip directory (as defined in the setup.py file)
        )	r�appendrrrrrrr)r'�pathsrrr�config_file_paths{szConfig.config_file_pathscCs�x�|j�D]�}tjdj|��tjj|�r
yDt|dd��}|jj	|�|jj
|�WdQRXtjdj|��Wn>tk
r�}z"tj
dj||��tjd�WYdd}~XnX||_Pq
W|j�dS)z=Read the config file, if it exists. Using defaults otherwise.zSearch glances.conf file in {}zutf-8)�encodingNzRead configuration file '{}'z(Can not read configuration file '{}': {}�)r+r�debug�formatrr�existsrr$Z	read_filer&�info�UnicodeDecodeError�error�sys�exitr �sections_set_default)r'Zconfig_file�f�errrrrr&�szConfig.readcCs�|jjd�s|jjd�|jddd�|jjd�s>|jjd�|jddd�|jjd�sd|jjd�|jdd�|jdd�|jdd	�|jjd�s�|jjd�|jdd
�|jdd�|jdd�d
tj�d}|jddt||d�t||d�t|�g�d+tj�}|jddt||d�t||d�t|�g�|jjd��sZ|jjd�|jdd
�|jdd�|jjd��s�|jjd�|jddddgd�|jjd��s�|jjd�|jd�|jjd��s�|jjd�|jd�|jjd��s|jjd�|jdd�|jdd�|jjd��s4|jjd�|jd�|jjd��sX|jjd�|jdd d!d"d#gd�|jdd$d%d&d!gd�|jdd'd#d(d)gd�|jjd*��s�|jjd*�|jd*d�|jd*d�dS),N�globalZstrftime_formatrZcheck_updateZfalseZ	quicklookZcpuZmemZswap�user�systemZstealg�?gY@Ziowaitg�������?g�������?i �Zctx_switchesZpercpu�loadz0.7z1.0z5.0)�cwcZmemswapZnetwork�rxZtxZfsZsensorsZtemperature_coreZ60�70Z80Ztemperature_hddZ45Z52Zbattery�90Z95Zprocesslistgj�@)r$�has_sectionZadd_section�set_default�set_default_cwc�multiprocessing�	cpu_count�str)r'Ziowait_bottleneckZctx_switches_bottleneckrrrr6�sv


zConfig.sections_set_defaultcCs|jS)z%Return the loaded configuration file.)r )r'rrr�loaded_config_fileszConfig.loaded_config_filecCsPi}xF|jj�D]8}i||<x*|jj|�D]}|jj||�|||<q*WqW|S)z"Return the configuration as a dict)r$�sectionsZoptionsr)r'Z
dictionary�section�optionrrr�as_dictszConfig.as_dictcCs
|jj�S)zReturn a list of all sections.)r$rH)r'rrrrHszConfig.sectionscCs|jj|�S)z#Return the items list of a section.)r$�items)r'rIrrrrLszConfig.itemscCs|jj|�S)z-Return info about the existence of a section.)r$rA)r'rIrrrrAszConfig.has_sectionZ50r?r@cCs\|dkrd}n|d}|j||d|d�|j||d|d�|j||d|d	�dS)
z5Set default values for careful, warning and critical.Nr�_ZcarefulrZwarningr-Zcritical�)rB)r'rIZ
option_headerr=�headerrrrrC!szConfig.set_default_cwccCs"|jj||�s|jj|||�dS)z4If the option did not exist, create a default value.N)r$Z
has_option�set)r'rIrJ�defaultrrrrB+szConfig.set_defaultcCs�|}y|jj||�}Wnttfk
r.YnX|dk	r�y6|jj|�}x$|D]}|j|t|dd���}qLWWntk
r�YnX|S)aGet the value of an option, if it exists.

        If it did not exist, then return the default value.

        It allows user to define dynamic configuration key (see issue#1204)
        Dynamic value should starts and end with the ` char
        Example: prefix=`hostname`
        Nr-���)	r$rrrr#�findall�replacerr%)r'rIrJrQ�ret�match�mrrr�	get_value0s	
 zConfig.get_valuercCs0y|jj||�Sttfk
r*t|�SXdS)z-Get the int value of an option, if it exists.N)r$Zgetintrr�int)r'rIrJrQrrr�
get_int_valueIszConfig.get_int_value�cCs0y|jj||�Sttfk
r*t|�SXdS)z/Get the float value of an option, if it exists.N)r$Zgetfloatrr�float)r'rIrJrQrrr�get_float_valuePszConfig.get_float_valueTcCs0y|jj||�Sttfk
r*t|�SXdS)z.Get the bool value of an option, if it exists.N)r$Z
getbooleanrr�bool)r'rIrJrQrrr�get_bool_valueWszConfig.get_bool_value)N)N)r)r[)T)�__name__�
__module__�__qualname__�__doc__r(r+r&r6�propertyrGrKrHrLrArCrBrXrZr]r_rrrrrds 
\	



r)rcrr4rD�iorr!Zglances.compatrrrrZglances.globalsrrr	r
rZglances.loggerrrrrr�objectrrrrr�<module>
s