
    Kc#                         d dl mZ d dlZd dlZd dlmZ d dlZd dlZd dlm	Z	m
Z
 ddlT 	 d dlmZ n	#  dZY nxY w G d	 d
e          ZdS )    )GtkN)NamedTemporaryFile)TimedOperationOperationCanceled   )*)journalFc                   D    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )ErrorLogCheckpointc                 
   t                               | |d           |                     t          d          t          d                    }t          j                            t          d                    }t	          j                    }|                    d           |	                    t          j
        j                   |                    |ddd           || _        |                    |ddd           t	          j                    | _        | j                            dd           | j                            d           |                    | j        ddd           |                    ||            i | _        d S )NzError log checkpoint	DebuggingzThis step will enable debugging output from the CUPS scheduler.  This may cause the scheduler to restart.  Click the button below to enable debugging.zEnable Debuggingr   FT)Question__init__initial_vbox_r   Buttonnew_with_label
HButtonBoxset_border_width
set_layoutButtonBoxStyleSTART
pack_startbuttonLabellabelset_alignmentset_line_wrapnew_pagepersistent_answers)selftroubleshooterpager   	buttonboxs        C/usr/share/system-config-printer/troubleshoot/ErrorLogCheckpoint.pyr   zErrorLogCheckpoint.__init__&   s\   41GHHH  !K.."# %L #M #MN N
 **A.@,A,ABBN%%	""A&&&c06777feUA666E5!444Y\\

  !Q'''
  $'''UE1555t,,,"$    c                    | j                             dd          sd S | j        j        d         }|                                }|                    d           |                                }t          t          |	                                                    dk    rd S d|t          j        <   | j        j        }| j         d         }|                    dd          |d<   |                    |           d S )	Nerror_log_debug_logging_setF!_authenticated_connection_factoryr   0cups_server_settings
MaxLogSize2000000)r    getr"   answersget_connection	_set_lockadminGetServerSettingslenlistkeyscupsCUPS_SERVER_DEBUG_LOGGINGadminSetServerSettings)r!   fcsettingsr/   orig_settingss         r%   __del__zErrorLogCheckpoint.__del__;   s    &**,I,13 3 	F'(KL	U++..X]]%%&&''1,,F36/0%-/0FG!.!2!2L)!L!L	  (+++++r&   c                 |   i | _         | j        j         }|d         sdS |d         | _        | j                                        }d }	 t	          ||          | _        | j                                        }n## t          $ r Y dS t          j	        $ r i }Y nw xY wd| _
        | j                            d           t          t          |                                                    dk    rdS || j        d	<   	 t#          |t          j                           dk    rdS n# t&          $ r Y nt(          $ r Y nw xY wdS )
Ncups_queue_listedF_authenticated_connectionc                      t          j        d            t          j        d           t          j                    } |                                 S )Nc                     dS )N  )xs    r%   <lambda>zGErrorLogCheckpoint.display.<locals>.getServerSettings.<locals>.<lambda>X   s    " r&   rC   )r6   setPasswordCB	setServer
Connectionr2   )r:   s    r%   getServerSettingsz5ErrorLogCheckpoint.display.<locals>.getServerSettingsV   sD    ---NB""A++...r&   parentrC   r   Tr+   )r/   r"   authconn
get_windowr   oprunRuntimeErrorr6   IPPErrorforward_allowedr   set_textr3   r4   r5   r    intr7   KeyError
ValueError)r!   r/   rL   rJ   r;   s        r%   displayzErrorLogCheckpoint.displayM   s   %-*+ 	5 ;<$//22	/ 	/ 	/	$&7GGGDGw{{~~HH 	 	 	55} 	 	 	HHH	  %
R   X]]%%&&''1,,4>FD#$:;	HT;<==BBu C  	 	 	D 	 	 	D	 ts0   /A8 8
BBB;#D! !
D9-	D98D9c                 R    | j                             d| j        |          | _        d S )Nclicked)r   connectenable_clickedbutton_sigid)r!   handlers     r%   connect_signalsz"ErrorLogCheckpoint.connect_signalsx   s,     K//D<O18: :r&   c                 D    | j                             | j                   d S N)r   
disconnectr]   r!   s    r%   disconnect_signalsz%ErrorLogCheckpoint.disconnect_signals|   s!     122222r&   c                    | j         j        }|d         si S | j                                         }| j                            | j                   d| j        v r| j        S t                      }	 t          | j        j        dgd|i|          | _	        | j	        
                                 n# t          t          j        f$ r}|| j        d<   Y d }~ned }~wt          j        $ rP}|| j        d<   | j         j        }|d         }|                                | _        | j        | j        d<   Y d }~nd }~ww xY w	 t!          j        |j                  }n# t&          $ r g d	}Y nw xY w|d
         | j        d<   |d
         | j        d<   t(          rt)          j                    }|                                 |                                d         }|| j        d<   || j        d<   t0          j                            t5          j                              }	|	                    d          }
|
| j        d<   |
| j        d<   | j        S )Nr?   error_log_checkpointz/admin/log/error_logfile)argskwargsrL   error_log_checkpoint_excr)   r@   )r   r   r   r   r   r   r      __CURSORerror_log_cursorz%F %Terror_log_timestamp)r"   r/   rN   updater    r   r   rM   getFilerO   rP   rQ   r6   rR   	HTTPErrorr0   osstatnameOSErrorr	   Reader	seek_tailget_previousdatetimefromtimestamptimestrftime)r!   r/   rL   tmpfefactorystatbufjcursornow	timestamps              r%   collect_answerz!ErrorLogCheckpoint.collect_answer   sp   %-*+ 	I$//22T4555!T\11<!##	F$dm&;.D-E06~/57 7 7DG GKKNNNNdm, 	9 	9 	978DL3444444~ 	F 	F 	F78DL34 )1GABG#2255DM8<DL4555555	F	,gty))GG 	, 	, 	,+++GGG	, 07qz+,:A!* 67 		G!!AKKNNN^^&&z2F/5DL+,:@D#$67#1149<<@@Cg..I2;DL./=FD#$9:|s7   .>B- -D4
CD4$AD//D48E E#"E#c                     | j         S ra   )rS   rc   s    r%   can_click_forwardz$ErrorLogCheckpoint.can_click_forward   s    ##r&   c                    | j                                         }| j                                          	 t          | j        j        |          | _        | j                                        }nH# t          j	        t          f$ r/ | j                                          d| _         ||           Y d S w xY w|                                | j        d<   d}	 t          |t          j                           }n# t"          $ r d}Y nw xY w	 t          ||                   }n# t"          t$          f$ r d}Y nw xY w|dk    s|dk    rd|t          j        <   d||<   d	}d
 }		 t'          dt)          |          z              t          |	| j        |f|          | _        | j                                         d}n # t          j	        $ r Y nt*          $ r Y nw xY w|r1d| j        d<   | j                            t1          d                     n'| j                            t1          d                     d| _        | j                                           ||           d S )NrK   Tr+   r,   r   r*   1Fc                     |                      |           d}|dk    rH	 t          j        d           |                                  d S # t          $ r |dz  }Y nw xY w|dk    Fd S d S )Nr      )r8   r{   sleep_connectrQ   )
connectionr;   attempts      r%   set_settingsz7ErrorLogCheckpoint.enable_clicked.<locals>.set_settings   s    118<<< ll%
A"++...' % % %1% lllllls   (A	 	AAzSettings to set: )rh   rL   r(   zDebug logging enabled.z"Debug logging was already enabled.)r"   rN   busyr   rM   r2   rO   rP   r6   rR   r   readyrS   copyr    rU   r7   rV   rW   
debugprintreprrQ   r   rT   r   )
r!   r   r^   rL   r;   
MAXLOGSIZE
prev_debugprev_logsizesuccessr   s
             r%   r\   z!ErrorLogCheckpoint.enable_clicked   s   $//22  ###	$dm&J-35 5 5DGw{{~~HH01 	 	 	%%(((#'D GVFF		 ;C--:J:J 67
	ht'EFGGJJ 	 	 	JJJ		 455LL*% 	 	 	LLL	 ??lc117:HT34#&HZ G% % %
/$//ABBB(,04x/I179 9 9 =        BIM'(EF
##Q'?%@%@AAAJ#G!H!HIII#!!$$$sO   9A. .AB32B3C5 5DDD D43D4AF6 6G	GGc                     | j                                          | j        j        }|d         }|                                | _        | j        | j        d<   d S )Nr)   r@   )rO   cancelr"   r/   r0   rM   )r!   r/   r   s      r%   cancel_operationz#ErrorLogCheckpoint.cancel_operation   sT     %-=>..1148M0111r&   N)__name__
__module____qualname__r   r=   rX   r_   rd   r   r   r\   r   rD   r&   r%   r   r   %   s        % % %*, , ,$) ) )V: : :3 3 3/ / /b$ $ $? ? ?BB B B B Br&   r   )gi.repositoryr   r6   rr   tempfiler   ry   r{   timedopsr   r   basesystemdr	   r   r   rD   r&   r%   <module>r      s   ,        				 ' ' ' ' ' '   6 6 6 6 6 6 6 6    GGGVB VB VB VB VB VB VB VB VB VBs   1 7