o
    van                     @   s4   d Z ddlmZmZ ddlmZ G dd deZdS )z/Manage the Glances web/url list (Ports plugin).    )rangeurlparse)loggerc                   @   s>   e Zd ZdZdZdZdZdddZdd	 Zd
d Z	dd Z
dS )GlancesWebListz-Manage the Web/Url list for the ports plugin.Zports<      Nc                 C   s   |  || _d S )N)load	_web_list)selfconfigargs r   2/usr/lib/python3/dist-packages/glances/web_list.py__init__"   s   zGlancesWebList.__init__c                 C   s8  g }|du rt d |S || jst d| j  |S t d| j  t|j| jd| jd}t|j| jd| jd}tdd	D ]}i }d
t	| }|| jd|df |d< |d du r`qBt
|d }t|jrpt|js}t d|d | jf  qB|j| jd| d|j d|d< d|d< d|d< ||d< t|j| jd| |d|d< |j| jd| dd|d< |d durt|d d |d< dt	| |d< |j| jd| dd|d< |j| jd| dd}	|j| jd| dd}
|
du r|	du rd|d< n|	|
d |d< t d!|d   || qBt d"|  |S )#z.Load the web list from the configuration file.Nz8No configuration file available. Cannot load ports list.zBNo [%s] section in the configuration file. Cannot load ports list.z8Start reading the [%s] section in the configuration filerefresh)defaulttimeout      zweb_%s_z%s%sZurlz7Bad URL (%s) in the [%s] section of configuration file.z%sdescriptionz%sdescriptionstatusr   elapsedz	%stimeoutz%srtt_warningZrtt_warningg     @@Zweb_Zindicez%sssl_verifyTZ
ssl_verifyz%shttp_proxyz%shttps_proxyZproxies)ZhttpZhttpsz!Add Web URL %s to the static listzWeb list loaded: %s)r   debugZhas_section_sectionintZ	get_value_default_refresh_default_timeoutr   strr   boolZschemeZnetlocerrorappend)r
   r   Zweb_listr   r   iZnew_webZpostfixZ	url_parseZ
http_proxyZhttps_proxyr   r   r   r   +   sz   
OM





zGlancesWebList.loadc                 C   s   | j S )z.Return the current server list (dict of dict).r	   )r
   r   r   r   get_web_list   s   zGlancesWebList.get_web_listc                 C   s   || j | |< dS )z<Set the key to the value for the pos (position in the list).Nr"   )r
   poskeyvaluer   r   r   
set_server   s   zGlancesWebList.set_server)NN)__name__
__module____qualname____doc__r   r   r   r   r   r#   r'   r   r   r   r   r      s    
	Vr   N)r+   Zglances.compatr   r   Zglances.loggerr   objectr   r   r   r   r   <module>   s   