U
    ZŠ8dÒ  ã                   @   sH   d Z ddlZddlZddlmZ ddlZddlZG dd„ dejjƒZdS )z Debian crash database interface.é    N)ÚMIMETextc                   @   s2   e Zd ZdZdd„ Zdd„ Zddd„Zd	d
„ ZdS )ÚCrashDatabasezk
    Debian crash database
    This is a Apport CrashDB implementation for interacting with Debian BTS
    c                 C   sH   t jj | ||¡ || _| j d¡s.d| jd< | j d¡sDd| jd< dS )z¹
        Initialize crash database connection.

        Debian implementation is pretty basic as most of its bug management
        processes revolve around the email interface
        Úsmtphostzreportbug.debian.orgÚ	recipientzsubmit@bugs.debian.orgN)ÚapportÚcrashdbr   Ú__init__ÚoptionsÚget)ÚselfZ	auth_filer	   © r   ú</usr/lib/python3/dist-packages/apport/crashdb_impl/debian.pyr      s    
zCrashDatabase.__init__c                 C   sD   | j  d¡sd|krd|d< d|kr4| ¡ s4d|d< tjj | |¡S )zz
        Check if this report can be uploaded to this database.
        Checks for the proper settings of apport.
        ÚsenderZUnreportableReasonz<Please configure sender settings in /etc/apport/crashdb.confZ
Stacktracez>Incomplete backtrace. Please install the debug symbol packages)r	   r
   Zhas_useful_stacktracer   r   r   Úaccepts)r   Úreportr   r   r   r   (   s
    zCrashDatabase.acceptsNc              	   C   sj  |   |¡st‚z|d  d¡\}}W n ttfk
r>   Y dS X t ¡ }|j d| d  	d¡¡ |j d| d  	d¡¡ |j d	 	d¡¡ z
|d
= W n tk
r¬   Y nX | |¡ |j 
d¡ t|j ¡  d¡ƒ}|d |d< | jd |d< | jd |d< | d| jd ¡ | dd|d  ¡  ¡ t | jd ¡}| | jd | jd | ¡  	d¡¡ | ¡  dS )zÍUpload given problem report return a handle for it.

        In Debian, we use BTS, which is heavily email oriented
        This method crafts the bug into an email report understood by Debian BTS
        ZPackageú Fz	Package: Ú
zUTF-8z	Version: z


z=============================

ZCoreDumpr   ZTitleZSubjectr   ZFromr   ZTozX-Debbugs-CCZUsertagz	apport-%sZProblemTyper   N)r   ÚAssertionErrorÚsplitÚKeyErrorÚ
ValueErrorÚtempfileZNamedTemporaryFileÚfileÚwriteÚencodeÚseekr   ÚreadÚdecoder	   Z
add_headerÚlowerÚsmtplibZSMTPZsendmailZ	as_stringÚquit)r   r   Zprogress_callbackZbuggyPackageZbuggyVersionZtempÚmsgÚsr   r   r   Úupload6   s0    

$zCrashDatabase.uploadc                 C   s   dS )aA  
        Return an URL that should be opened after report has been uploaded
        and upload() returned handle.

        Should return None if no URL should be opened (anonymous filing without
        user comments); in that case this function should do whichever
        interactive steps it wants to perform.
        Nr   )r   r   Zhandler   r   r   Úget_comment_urlh   s    	zCrashDatabase.get_comment_url)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   r$   r   r   r   r   r      s
   
2r   )	r(   r   r   Zemail.mime.textr   r   Zapport.crashdbr   r   r   r   r   r   Ú<module>   s
   