o
    åvŽfÒ  ã                   @   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   sL   t jj | ||¡ || _| j d¡sd| jd< | j d¡s$d| jd< dS 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)ÚselfÚ	auth_filer	   © r   ú</usr/lib/python3/dist-packages/apport/crashdb_impl/debian.pyr      s   
ÿzCrashDatabase.__init__c                 C   sD   | j  d¡sd|vrd|d< d|v r| ¡ sd|d< tjj | |¡S )zz
        Check if this report can be uploaded to this database.
        Checks for the proper settings of apport.
        ÚsenderÚUnreportableReasonz<Please configure sender settings in /etc/apport/crashdb.confÚ
Stacktracez>Incomplete backtrace. Please install the debug symbol packages)r	   r
   Úhas_useful_stacktracer   r   r   Úaccepts)r   Úreportr   r   r   r   (   s
   zCrashDatabase.acceptsNc              	   C   sf  |   |¡sJ ‚z|d  d¡\}}W n ttfy   Y dS w t ¡ }|j d| d  d¡¡ |j d| d  d¡¡ |j d	 d¡¡ z|d
= W n	 tyT   Y nw | |¡ |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
        ÚPackageú Fz	Package: Ú
zUTF-8z	Version: z


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

ÚCoreDumpr   ÚTitleÚSubjectr   ÚFromr   ÚTozX-Debbugs-CCÚUsertagz	apport-%sÚProblemTyper   N)r   ÚsplitÚKeyErrorÚ
ValueErrorÚtempfileÚNamedTemporaryFileÚfileÚwriteÚencodeÚseekr   ÚreadÚdecoder	   Ú
add_headerÚlowerÚsmtplibÚSMTPÚsendmailÚ	as_stringÚquit)r   r   Úprogress_callbackÚbuggyPackageÚbuggyVersionÚtempÚmsgÚsr   r   r   Úupload6   s4   ÿ
ÿ
$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   Úhandler   r   r   Úget_comment_urlh   s   	zCrashDatabase.get_comment_url)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r7   r9   r   r   r   r   r      s    
2r   )	r=   r,   r"   Úemail.mime.textr   r   Úapport.crashdbr   r   r   r   r   r   Ú<module>   s    