o
    Ìv›aô  ã                   @   s@   d Z ddlmZmZ ddlmZ ddlmZ G dd„ deƒZ	dS )z&Manage the Glances server static list.é    )ÚgaierrorÚgethostbyname)Úrange)Úloggerc                   @   s6   e Zd ZdZdZddd„Zdd„ Zdd	„ Zd
d„ ZdS )ÚGlancesStaticServerz6Manage the static servers list for the client browser.Z
serverlistNc                 C   s   |   |¡| _d S )N)ÚloadÚ_server_list)ÚselfÚconfigÚargs© r   ú5/usr/lib/python3/dist-packages/glances/static_list.pyÚ__init__"   s   zGlancesStaticServer.__init__c                 C   sv  g }|du rt  d¡ |S | | j¡st  d| j ¡ |S t  d| j ¡ tddƒD ]~}i }dt|ƒ }dD ]}| | jd	||f ¡||< q6|d
 dur¨|d du rVd|d< d|d< d|d< z
t	|d
 ƒ|d< W n t
y… } zt  d|d
 |f ¡ W Y d}~q*d}~ww |d
 d |d  |d< d|d< d|d< t  d|d
  ¡ | |¡ q*t  dt|ƒ ¡ t  d| ¡ |S )z1Load the server list from the configuration file.Nz9No configuration file available. Cannot load server list.zCNo [%s] section in the configuration file. Cannot load server list.z8Start reading the [%s] section in the configuration fileé   é   z
server_%s_)ÚnameÚportÚaliasz%s%sr   r   Z61209ZglancesZusernameÚ ZpasswordZipz(Cannot get IP address for server %s (%s)ú:ÚkeyZUNKNOWNÚstatusZSTATICÚtypez Add server %s to the static listz/%s server(s) loaded from the configuration filezStatic server list: %s)r   ÚdebugZhas_sectionÚ_sectionZwarningÚinfor   ÚstrZ	get_valuer   r   ÚerrorÚappendÚlen)r	   r
   Zserver_listÚiZ
new_serverZpostfixÚsÚer   r   r   r   (   sD   
'Ú%Ý€þ
€zGlancesStaticServer.loadc                 C   s   | j S )z.Return the current server list (list of dict).©r   )r	   r   r   r   Úget_servers_listV   s   z$GlancesStaticServer.get_servers_listc                 C   s   || j | |< dS )zCSet the key to the value for the server_pos (position in the list).Nr#   )r	   Z
server_posr   Úvaluer   r   r   Ú
set_serverZ   s   zGlancesStaticServer.set_server)NN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r$   r&   r   r   r   r   r      s    
.r   N)
r*   Zsocketr   r   Zglances.compatr   Zglances.loggerr   Úobjectr   r   r   r   r   Ú<module>   s
   