
    e                         d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ  G d de j                        Z	 G d de      Z
y)	    N)getpass)banner)UIBasec                       e Zd ZdZd Zd Zy)TTYFormatterzBSpecific Formatter that adds thread information to the log output.c                 X    t        j                  j                  | g|i | d | _        y N)logging	Formatter__init___last_log_thread)selfargskwargss      -/usr/share/offlineimap3/offlineimap/ui/TTY.pyr   zTTYFormatter.__init__   s(    ""49$9&9 $    c                     t         j                  j                  | |      }|j                  }|dk(  r|S || j                  k7  r|| _        |d|}|S d|z  }|S )z*Override format to add thread information.
MainThreadz:
 z %s)r
   r   format
threadNamer   )r   recordlog_strt_names       r   r   zTTYFormatter.format#   sm     ##**48 ""\!NT***$*D!$*G4G  goGr   N)__name__
__module____qualname____doc__r   r    r   r   r   r      s    L%
r   r   c                   ,    e Zd Zd Zd ZddZd Zd Zy)TTYUIc                    t        j                         }t        d      | _        |j	                  | j                         | j
                  j                  |       | j
                  j                  t               |j                          |S )zBackend specific console handler

        Sets up things and adds them to self.logger.
        :returns: The logging.Handler() for console outputz%(message)s)
r
   StreamHandlerr   	formattersetFormatterlogger
addHandlerinfor   
createLock)r   chs     r   setup_consolehandlerzTTYUI.setup_consolehandler7   sb     ""$ &m4
'r" 
	r   c                 ~    t         j                  j                         xr t         j                  j                         S )z7TTYUI is reported as usable when invoked on a terminal.)sysstdoutisattystdinr   s    r   isusablezTTYUI.isusableJ   s)     zz  "9syy'7'7'99r   Nc                     |r| j                  |d|       | j                  j                          	 t        d|z        | j                  j	                          S # | j                  j	                          w xY w)z2TTYUI backend is capable of querying the password.z: zEnter password for user '%s': )warn_log_con_handleracquirer   release)r   usernameconfigerrmsgs       r   r   zTTYUI.getpassO   sb     II(F34%%'	,;hFG!!))+D!!))+s   A A8c                     t        t        j                         d   t              r,| j                  j                  d       | j                          y t        j                  |        y )N   z8Timer interrupted at user request; program terminating.
)	
isinstancer,   exc_infoKeyboardInterruptr%   r3   	terminater   mainExceptionr0   s    r   r@   zTTYUI.mainExceptionZ   sG    cllnQ'):;KK . /NN  &r   c                     |dkD  rD|dz  ||z
  dz  k7  r!| j                   j                  d|dz  z         t        j                  |       y)aY  Sleep for sleepsecs, display remainingsecs to go.

        Does nothing if sleepsecs <= 0.
        Display a message on the screen if we pass a full minute.

        This implementation in UIBase does not support this, but some
        implementations return 0 for successful sleep and 1 for an
        'abort', ie a request to sync immediately.r   <   zNext refresh in %.1f minutesg      N@)r%   r'   timesleep)r   	sleepsecsremainingsecss      r   sleepingzTTYUI.sleepingb   sS     q="}y'@R&GG  !?%,". /JJy!r   r	   )r   r   r   r*   r1   r   r@   rG   r   r   r   r    r    6   s    &:
	,'r   r    )r
   r,   rC   r   offlineimapr   offlineimap.ui.UIBaser   r   r   r    r   r   r   <module>rJ      s7   $  
    (7$$ 6;F ;r   