o
    UÀ7eS#  ã                   @   s    d dl m Z d dlmZ d dlmZmZmZ d dlm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ dZd	Zeeƒjeeƒjd
dgZddgZG dd„ de	ƒZdS )é    )Úgettext)Ú	Launchpad)ÚNotFoundÚ
BadRequestÚUnauthorized)ÚShortcutHandlerÚShortcutExceptionÚInvalidShortcutException)ÚSourcesListShortcutHandler)ÚURIShortcutHandler)Úurlparsez5https://ppa.launchpadcontent.net/{team}/{ppa}/ubuntu/z=https://private-ppa.launchpadcontent.net/{team}/{ppa}/ubuntu/zppa.launchpad.netzprivate-ppa.launchpad.netÚmainú
main/debugc                       s¨   e Zd Zd‡ fdd„	Zedd„ ƒZedd„ ƒZedd	„ ƒZed
d„ ƒZedd„ ƒZ	edd„ ƒZ
d ‡ fdd„	Z‡ fdd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )!ÚPPAShortcutHandlerFc           	         s,  t t| ƒj|fi |¤Ž | | _d | _d | _d | _d | _d| _t	|  
|¡|  |¡|  |¡fƒs9tdƒ| }t|ƒ‚d| j| jf | _|  ¡  | jr\z| j W n ty[   ttdƒƒ‚w | js”| j}|sodg}| jjrotdƒ | jjrutnt}|j| j| jd�}d| j|| jd	 |¡f }|   |¡ d S d S )
NFz%ERROR: '%s' is not a valid ppa formatz%s-ubuntu-%szERROR: Can't find ppar   zDPPA publishes dbgsym, you may need to include 'main/debug' component)ÚteamÚppaz%s %s %s %sú )!Úsuperr   Ú__init__Ú_lp_anonÚ_signing_key_dataÚ_lpÚ_lpteamÚ_lpppaÚ_is_sourceslistÚanyÚ
_match_ppaÚ
_match_uriÚ_match_sourceslistÚ_r	   ÚteamnameÚppanameÚ	_filebaseÚ	_set_authÚlpppar   Ú_source_entryÚ
componentsÚpublish_debug_symbolsÚprintÚprivateÚPRIVATE_PPA_URI_FORMATÚPPA_URI_FORMATÚformatÚbinary_typeÚdistÚjoinÚ_set_source_entry)	ÚselfÚshortcutÚloginÚkwargsÚmsgÚcompsÚ
uri_formatÚuriÚline©Ú	__class__© ú8/usr/lib/python3/dist-packages/softwareproperties/ppa.pyr   2   s@   
þ
ÿõzPPAShortcutHandler.__init__c                 C   s>   | j s| jr
tj}ntj}|d| j| jjf ddd�| _ | j S )Nz%s.%sÚ
productionÚdevel)Úservice_rootÚversion)r   r   r   Úlogin_anonymouslyÚ
login_withÚ
__module__r;   Ú__name__)r1   Ú
login_funcr<   r<   r=   Úlp[   s   þzPPAShortcutHandler.lpc                 C   sl   | j s3z| j | j¡| _ W | j S  ty!   tdƒ| j }t|ƒ‚ ty2   tdƒ| j }t|ƒ‚w | j S )Nz8ERROR: user/team '%s' not found (use --login if private)z"ERROR: invalid user/team name '%s')r   rG   Úpeopler    r   r   r   r   ©r1   r5   r<   r<   r=   Úlpteamg   s   úþzPPAShortcutHandler.lpteamc                 C   st   | j s7z| jj| jd�| _ W | j S  ty%   tdƒ| j| jf }t|ƒ‚ ty6   tdƒ| j }t|ƒ‚w | j S )N)Únamez5ERROR: ppa '%s/%s' not found (use --login if private)zERROR: invalid ppa name '%s')	r   rJ   ÚgetPPAByNamer!   r   r   r    r   r   rI   r<   r<   r=   r$   t   s   ù
ÿþzPPAShortcutHandler.lpppac                 C   ó   | j jS ©N)r$   Údescription©r1   r<   r<   r=   rO   ‚   ó   zPPAShortcutHandler.descriptionc                 C   rM   rN   )r$   Úweb_linkrP   r<   r<   r=   rR   †   rQ   zPPAShortcutHandler.web_linkc                 C   s~   | j s<| j ¡ }| jj}|sttdƒƒ n$d|v r ttdƒƒ n||  |¡vr9tdƒ|d |  |¡¡f }t|ƒ‚|| _ | j S )NzHWarning: could not get PPA signing_key_fingerprint from LP, using anywayÚredactedzAPrivate PPA fingerprint redacted, using key anyway (LP: #1879781)z6Fingerprints do not match, not importing: '%s' != '%s'ú,)	r   r$   ÚgetSigningKeyDataÚsigning_key_fingerprintr(   r   Úfingerprintsr/   r   )r1   ÚkeyÚfingerprintr5   r<   r<   r=   Útrustedparts_contentŠ   s   
ÿz'PPAShortcutHandler.trustedparts_contentNc                    sD   t t| ƒj|d�}|| jks| jr|S tt|jƒtdgƒ ƒ|_|S )N)Úpkgtyper   )r   r   ÚSourceEntryÚsource_typer&   ÚlistÚsetr6   )r1   r[   Úentryr:   r<   r=   r\   œ   s
   zPPAShortcutHandler.SourceEntryc                    sH   t t| ƒ |¡ t|  ¡ jƒttƒ }|r"ttdƒd 	|¡ ƒ d S d S )Nz*Warning: components '%s' not valid for PPAr   )
r   r   r0   r_   r\   r6   ÚPPA_VALID_COMPSr(   r   r/   )r1   r9   Úinvalid_compsr:   r<   r=   r0   §   s
   ÿz$PPAShortcutHandler._set_source_entryc                 C   s‚   |  d¡\}}}| ¡ dksdS | d¡\}}}| d¡}d|v r7| d¡\}}}| ¡ dkr1dS d|v r7dS || _|p=d| _dS )Nú:r   Fú/ú~ÚubuntuT)Ú
rpartitionÚlowerÚ	partitionÚlstripr    r!   )r1   r2   Úprefixr   r   r    r!   rf   r<   r<   r=   r   ®   s   

zPPAShortcutHandler._match_ppac                 C   s&   z|   t|ƒ¡W S  ty   Y dS w )NF)Ú_match_handlerr   r	   )r1   r2   r<   r<   r=   r   Â   s
   ÿzPPAShortcutHandler._match_uric                 C   s2   z	|   t|ƒ¡}W n
 ty   Y dS w d| _|S )NFT)rl   r
   r	   r   )r1   r2   Úhandlerr<   r<   r=   r   È   s   ÿz%PPAShortcutHandler._match_sourceslistc                 C   sz   t | ¡ jƒ}|jtvrdS |j ¡  d¡ d¡}t|ƒdk r!dS |d | _	|d | _
|j| _|j| _|  | ¡ j¡ dS )NFrd   é   r   é   T)r   r\   r8   ÚhostnameÚPPA_VALID_HOSTNAMESÚpathÚstripÚsplitÚlenr    r!   ÚusernameÚ	_usernameÚpasswordÚ	_passwordr0   r9   )r1   rm   Úparsedrr   r<   r<   r=   rl   Ð   s   


z!PPAShortcutHandler._match_handlerc                 C   sŒ   | j s| jjs	d S | jr| jrd S | jj ¡ D ] }t|ƒ}|j	 
d| j› d| j› d�¡r7|j| _|j| _ d S qtdƒ| j| jf }t|ƒ‚)Nrd   z/ubuntuzMCould not find PPA subscription for ppa:%s/%s, you may need to request access)r   r$   r)   rw   ry   rG   ÚmeÚgetArchiveSubscriptionURLsr   rr   Ú
startswithr    r!   rv   rx   r   r   )r1   Úurlrz   r5   r<   r<   r=   r#   á   s   ý
ÿzPPAShortcutHandler._set_auth)FrN   )rE   rD   Ú__qualname__r   ÚpropertyrG   rJ   r$   rO   rR   rZ   r\   r0   r   r   r   rl   r#   Ú__classcell__r<   r<   r:   r=   r   1   s*    )





r   N)r   r   Úlaunchpadlib.launchpadr   Úlazr.restfulclient.errorsr   r   r   Ú"softwareproperties.shortcuthandlerr   r   r	   Úsoftwareproperties.sourceslistr
   Úsoftwareproperties.urir   Úurllib.parser   r+   r*   rp   rq   ra   r   r<   r<   r<   r=   Ú<module>   s    û