
    Hf#                         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 	 d dlmZ  G d	 d
e      Zy#  dZY xY w)    )GtkN)NamedTemporaryFile)TimedOperationOperationCanceled   )*)journalFc                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)ErrorLogCheckpointc                    t         j                  | |d       | j                  t        d      t        d            }t        j
                  j                  t        d            }t	        j                         }|j                  d       |j                  t        j                  j                         |j                  |ddd       || _        |j                  |ddd       t	        j                         | _        | j                  j!                  dd       | j                  j#                  d       |j                  | j                  ddd       |j%                  ||        i | _        y )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  !K."# %L #MN
 **A.@,ABNN%	""A&c00667feUA6E5!4YY\


  !Q'

  $'UE15t,"$    c                    | j                   j                  dd      sy | j                  j                  d   }|j	                         }|j                  d       |j                         }t        t        |j                                     dk(  ry d|t        j                  <   | j                  j                  }| j                   d   }|j                  dd      |d<   |j                  |       y )	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''(KL	U++.X]]%&'1,36//0%%--//0FG!.!2!2L)!L	  (+r&   c                 `   i | _         | j                  j                   }|d   sy|d   | _        | j                  j                         }d }	 t	        ||      | _        | j
                  j                         }d| _
        | j                  j                  d       t        t        |j                                     dk(  ry|| j                   d	<   	 t#        |t        j$                           dk7  ry	 y# t        $ r Y yt        j                  $ r i }Y w xY w# t&        $ r Y yt(        $ r Y yw xY w)
Ncups_queue_listedF_authenticated_connectionc                      t        j                  d        t        j                  d       t        j                         } | j	                         S )Nc                      y)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   s7    -NNB"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   s0   %%--*+ ;<$$//2	/	$&7GDGww{{~H  %

R X]]%&'1,>FD##$:;	HT;;<=B C -  	}} 	H	  	   		s0   ,C2 D 2	D=DD	D-"D-,D-c                 \    | j                   j                  d| j                  |      | _        y )Nclicked)r   connectenable_clickedbutton_sigid)r!   handlers     r%   connect_signalsz"ErrorLogCheckpoint.connect_signalsx   s&     KK//D<O<O18:r&   c                 N    | j                   j                  | j                         y N)r   
disconnectr]   r!   s    r%   disconnect_signalsz%ErrorLogCheckpoint.disconnect_signals|   s     1 12r&   c                     | j                   j                  }|d   si S | j                   j                         }| j                  j                  | j                         d| j                  v r| j                  S t               }	 t        | j                  j                  dgd|i|      | _	        | j                  j                          	 t!        j"                  |j$                        }|d
   | j                  d<   |d
   | j                  d<   t(        rt)        j*                         }|j-                          |j/                         d   }|| j                  d<   || j                  d<   t0        j0                  j3                  t5        j4                               }	|	j7                  d      }
|
| j                  d<   |
| j                  d<   | j                  S # t        t        j                  f$ r}|| j                  d<   Y d }~9d }~wt        j                  $ rc}|| j                  d<   | j                   j                  }|d   }|j                         | _        | j                  | j                  d<   Y d }~d }~ww xY w# t&        $ r g d	}Y w xY w)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   s$   %%--*+I$$//2T445!T\\1<<!#	F$dmm&;&;.D-E06~/57DG GGKKN	,ggtyy)G 07qz+,:A!* 67!AKKN^^&z2F/5DLL+,:@D##$67##11499<@Cg.I2;DLL./=FD##$9:||= dmm, 	978DLL34~~ 	F78DLL34 ))11GABG#225DM8<DLL45	F  	,+G	,s8   AG I< I9+H  I9AI44I9<JJc                     | j                   S ra   )rS   rc   s    r%   can_click_forwardz$ErrorLogCheckpoint.can_click_forward   s    ###r&   c                    | j                   j                         }| j                   j                          	 t        | j                  j
                  |      | _        | j                  j                         }|j                         | j                  d<   d}	 t        |t        j                            }	 t        ||         }|dk(  s|dk7  rd|t        j                   <   d||<   d	}d
 }		 t'        dt)        |      z          t        |	| j                  |f|      | _        | j                  j                          d}|rXd| j                  d<   | j,                  j/                  t1        d             n$| j,                  j/                  t1        d             d| _        | j                   j                           ||       y # t        j                  t        f$ r, | j                   j                          d| _         ||       Y y w xY w# t"        $ r d}Y cw xY w# t"        t$        f$ r d}Y lw xY w# t        j                  $ r Y t*        $ r Y w xY w)NrK   Tr+   r,   r   r*   1Fc                     | j                  |       d}|dk  r(	 t        j                  d       | j                          y y y # t        $ r |dz  }Y nw xY w|dk  rC)Nr      )r8   r{   sleep_connectrQ   )
connectionr;   attempts      r%   set_settingsz7ErrorLogCheckpoint.enable_clicked.<locals>.set_settings   sg    118< l%

A"++.	 #
 ( %1% ls   %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  #	$dmm&J&J-35DGww{{~H ;C--:J 67
	ht'E'EFGJ	 45L ?lc17:HT334#&HZ G%
/$/AB(,04x/I179  IM''(EF

##Q'?%@AJJ#G!HI#!!$q 01 	%%(#'D V		  	J	 *% 	L	: ==  sP   A F? H 3H )AH1 ?AHHHHH.-H.1IIIc                     | j                   j                          | j                  j                  }|d   }|j	                         | _        | j
                  | j                  d<   y )Nr)   r@   )rO   cancelr"   r/   r0   rM   )r!   r/   r   s      r%   cancel_operationz#ErrorLogCheckpoint.cancel_operation   sQ     %%--=>..148MM01r&   N)__name__
__module____qualname__r   r=   rX   r_   rd   r   r   r\   r   rD   r&   r%   r   r   %   s3    %*,$)V:3/b$?BBr&   r   )gi.repositoryr   r6   rr   tempfiler   ry   r{   timedopsr   r   basesystemdr	   r   r   rD   r&   r%   <module>r      sC   ,   	 '   6 VB VBGs	   = A