
    KcM                         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	 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   )*)journalFc                   &    e Zd Zd Zd Zd Zd ZdS )ErrorLogFetchc                 v   t                               | |d           |                     t          d          t          d                    }t	          j                    | _        | j                            d           |                    | j        ddd           |	                    ||            i | _
        d S )NzError log fetchzRetrieve Journal EntrieszNo system journal entries were found. This may be because you are not an administrator. To fetch journal entries please run this command:Fr   )Question__init__initial_vbox_r   Entryentryset_editable
pack_startnew_pagepersistent_answers)selftroubleshooterpages      >/usr/share/system-config-printer/troubleshoot/ErrorLogFetch.pyr   zErrorLogFetch.__init__'   s    41BCCC  !$>"?"?"# %? #@ #@A A
 Y\\

'''UE1555t,,,"$    c                 |   | j         j        }| j                                         }i | _        |                    d          }|                    d          }|                    d          }d| j        v s	d| j        v rd }d }d }t
          j                            t          j                                                  d          }| j         j        d         | _	        d	|v r	 t          | j	        j        |
          | _        | j                                        }n# t          j        $ r Y dS w xY wd|t          j        <   |d         }	|	                    dd          |d<   d}
d }	 t          || j	        |f|
          | _        | j                                         d| j        d<   n# t          j        $ r Y nw xY wi | _        t"          rY|Wd t#          j                    }|                    |           |                    d           fd|D             | j        d<   |t          || j	        f|
          | _        | j                                        }|_t+          |          }|                    |           |                                }t1          j        |           dd |D             i| _        t5          | j                            dg                     t5          | j                            dg                     z   dk    r%d|d|d}| j                            |           dS dS )Nerror_log_checkpointerror_log_cursorerror_log_timestamp	error_logr   c                    |                                  }|                     d           |                                  t          d          5 }d}	 |                     d|           d}n@# t
          j        $ r. 	 t          j        |j	                   n# t          $ r Y nw xY wY nw xY w|                     |           |r|j        cd d d            S 	 d d d            n# 1 swxY w Y   d S )NF)deletez/admin/log/error_log)fileT)_get_prompt_allowed_set_prompt_allowed_connectr   getFilecups	HTTPErrorosremovenameOSErrorr"   )cprompttmpfsuccesss       r   	fetch_logz(ErrorLogFetch.display.<locals>.fetch_logA   so   **--F!!5)))JJMMM#E222 %dII5dICCC"GG~   	49----"    %%v... %9% % % % % % % %%% % % % % % % % % % % % % % % 4sZ   C#A,+C#,B)<BB)
B# B)"B##B)&C#(B)) C##C'*C'z%F %T_authenticated_connectionerror_log_debug_logging_set)parentF0cups_server_settings
MaxLogSize2000000c                     |                      |           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      )adminSetServerSettingstimesleepr%   RuntimeError)
connectionsettingsattempts      r   set_settingsz+ErrorLogFetch.display.<locals>.set_settingsd   s    118<<< ll%
A"++...' % % %1% lllllls   (A	 	AATerror_log_debug_logging_unsetc                     	 d| d                  }n# t           t          f$ r d}Y nw xY w|dz   | d                             d          z   dz   | d         z   S )N	XACEWNIDdPRIORITY __REALTIME_TIMESTAMPz[%m/%b/%Y:%T]MESSAGE)
IndexError	TypeErrorstrftime)xprioritys     r   journal_formatz-ErrorLogFetch.display.<locals>.journal_format~   s    #*1Z=9HH"I. # # #"HHH# !301::?KKL	l+ ,s    ''zcups.service)_SYSTEMD_UNITc                 &    g | ]} |          S  rR   ).0rM   rO   s     r   
<listcomp>z)ErrorLogFetch.display.<locals>.<listcomp>   s#    &E&E&Ea~~q'9'9&E&E&Er   c                 6    g | ]}|                                 S rR   )strip)rS   rM   s     r   rT   z)ErrorLogFetch.display.<locals>.<listcomp>   s     .I.I.Iaqwwzz.I.I.Ir   r   z+su -c 'journalctl -u cups.service --since="z" --until="z"' > troubleshoot-logs.txt)r   answers
get_windowgetr   datetimefromtimestampr<   rL   authconnr   adminGetServerSettingsoprunr'   IPPErrorCUPS_SERVER_DEBUG_LOGGINGr   Readerseek_cursor	add_matchopenseek	readlinesr)   r*   lenr   set_text)r   rW   r4   
checkpointcursor	timestampr1   nowr@   orig_settingsr0   rB   rtmpfnameflinescmdrO   s                    @r   displayzErrorLogFetch.display4   s   %-$//22[["899
011KK!677	4222000JF	 	 	* --ty||<<EEwOO+34OP(G33($-*N179 9 97;;>>=   uu 8;HT34#$:;M%2%6%6i%P%PH\"G% % %(,+/=(*C179 9 9 KO'(GHH=     	Fv), , , !!AMM6"""KK~K666&E&E&E&E1&E&E&EDL#!$i'+}&6-35 5 5DG w{{~~H#(OO
###	8$$$!,.I.I5.I.I.IK!!9b1122!!;334459:; ; ; IIsss$C J%%%4us%   %9D D21D2+AF- -F?>F?c                 l    | j                                         }|                    | j                   |S )N)r   copyupdaterW   )r   rW   s     r   collect_answerzErrorLogFetch.collect_answer   s/    )..11%%%r   c                     | j                                          | j        j        }|d         }|                                | _        | j        | j        d<   d S )N!_authenticated_connection_factoryr2   )r^   cancelr   rW   get_connectionr\   )r   rW   factorys      r   cancel_operationzErrorLogFetch.cancel_operation   sT     %-=>..1148M0111r   N)__name__
__module____qualname__r   rt   rx   r~   rR   r   r   r
   r
   &   sY        % % %m m m^  
B B B B Br   r
   )gi.repositoryr   r'   r)   tempfiler   rZ   r<   timedopsr   basesystemdr   r   r
   rR   r   r   <module>r      s   .        				 ' ' ' ' ' '   # # # # # #    GGGIB IB IB IB IBH IB IB IB IB IBs   / 5