o
    vb¿a³  ã                   @   s¬   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ G dd„ deƒZdS )z&Manage the Glances standalone session.é    N)ÚWINDOWS)Úlogger)Úglances_processes)ÚGlancesStats)ÚGlancesCursesStandalone)ÚGlancesStdout)ÚGlancesStdoutCsv)ÚGlancesStdoutIssue)ÚGlancesStdoutApiDoc)ÚOutdated)ÚCounterc                   @   sN   e Zd ZdZddd„Zedd„ ƒZdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚGlancesStandalonez>This class creates and manages the Glances standalone session.Nc                 C   s¤  || _ || _|j| _|j| _tƒ }| ¡  t||d| _	t
 d | ¡ ¡¡ |jr2|  ¡  t d¡ |js?t
 d¡ t ¡  n	t
 d¡ t ¡  |jd urQ|jt_tsZ|jrZt ¡  | ¡  | j	 ¡  t
 d | ¡ ¡¡ | jrzt
 d¡ dt_d S |jr‹t
 d¡ t||d| _d S |j rœt
 d	¡ t!||d| _d S |j"r±t
 d
 |j"¡¡ t#||d| _d S |j$rÆt
 d |j$¡¡ t%||d| _d S dt_t&||d| _d S )N)ÚconfigÚargsz+Plugins initialisation duration: {} secondsr   z+Extended stats for top process are disabledz*Extended stats for top process are enabledz'First stats update duration: {} secondsz+Quiet mode is ON, nothing will be displayedzIssue mode is ONzFields descriptions mode is ONz8Stdout mode is ON, following stats will be displayed: {}z<Stdout CSV mode is ON, following stats will be displayed: {}é2   )'r   r   ÚquietÚ_quietÚtimeÚrefresh_timer   Úresetr   Ústatsr   ÚdebugÚformatÚgetZmodules_listÚdisplay_modules_listÚsysÚexitZenable_process_extendedr   Zdisable_extendedZenable_extendedZprocess_filterr   Zno_kernel_threadsZdisable_kernel_threadsÚupdateÚinfoZmax_processesZstdout_issuer	   ÚscreenZstdout_apidocr
   Ústdoutr   Z
stdout_csvr   r   )Úselfr   r   Zstart_duration© r"   ú4/usr/lib/python3/dist-packages/glances/standalone.pyÚ__init__*   sP   










zGlancesStandalone.__init__c                 C   s   | j S )N)r   ©r!   r"   r"   r#   r   n   s   zGlancesStandalone.quietc              	   C   sH   t d d t| jjddƒ¡¡ƒ t d d t| jjddƒ¡¡ƒ dS )zDisplay modules listzPlugins list: {}z, F)ZenablezExporters list: {}N)Úprintr   ÚjoinÚsortedr   ZgetPluginsListZgetExportsListr%   r"   r"   r#   r   r   s   ÿ
ÿz&GlancesStandalone.display_modules_listc                 C   s   | j  | j¡ }|  ¡  |S )z`Special mode for the --issue option
        Update is done in the sceen.update function
        )r   r   r   Úend)r!   Úretr"   r"   r#   Úserve_issuey   s   zGlancesStandalone.serve_issuec                 C   sš   t ƒ }| j ¡  t d | ¡ ¡¡ t ƒ }| j | j¡ t d | ¡ ¡¡ | j| ¡  }|dkr3|nd}| j	sD| j
j| j|d }|S t |¡ d}|S )ziMain loop for the CLI.

        return True if we should continue (no exit key has been pressed)
        z"Stats updated duration: {} secondsz#Stats exported duration: {} secondsr   )ZdurationT)r   r   r   r   r   r   r   Zexportr   r   r   r   Úsleep)r!   ZcounterZcounter_exportZadapted_refreshr*   r"   r"   r#   Z__serve_once   s    

ÿ
ýzGlancesStandalone.__serve_oncec                 C   s   |   ¡ r		 |   ¡ s|  ¡  dS )z&Wrapper to the serve_forever function.N)Ú_GlancesStandalone__serve_oncer)   r%   r"   r"   r#   Úserve_forever¥   s   ÿzGlancesStandalone.serve_foreverc                 C   s   | j s| j ¡  | j ¡  dS )zEnd of the standalone CLI.N)r   r   r)   r   r%   r"   r"   r#   r)   ®   s   
zGlancesStandalone.end)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   Úpropertyr   r   r+   r-   r.   r)   r"   r"   r"   r#   r   &   s    
D
$	r   )r2   r   r   Zglances.globalsr   Zglances.loggerr   Zglances.processesr   Zglances.statsr   Zglances.outputs.glances_cursesr   Zglances.outputs.glances_stdoutr   Z"glances.outputs.glances_stdout_csvr   Z$glances.outputs.glances_stdout_issuer	   Z%glances.outputs.glances_stdout_apidocr
   Zglances.outdatedr   Zglances.timerr   Úobjectr   r"   r"   r"   r#   Ú<module>   s   