o
    U7eS#                     @   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    