
    f1%                         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 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e	      Zy)    )gettext)	Launchpad)NotFound
BadRequestUnauthorized)ShortcutHandlerShortcutExceptionInvalidShortcutException)SourcesListShortcutHandler)URIShortcutHandler)Deb822SourceEntry)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                        e Zd Zd fd	Zed        Zed        Zed        Zed        Zed        Z	ed        Z
d fd	Z fd	Zd
 Zd Zd Zd Zd Z xZS )PPAShortcutHandlerc                    t        t        | 
  |fddi| | | _        d | _        d | _        d | _        d | _        d| _        | j                  |      sKd| _
        t        | j                  |      | j                  |      f      st        d      |z  }t        |      | j                   d| j"                  | _        | j'                          | j                  r	 | j(                   | j,                  s| j.                  }|s$dg}| j(                  j0                  rt3        d       | j(                  j4                  rt6        nt8        }|j;                  | j                   | j"                  	      }t=        d d
      }| j>                  g|_         |g|_!        | jD                  g|_#        ||_$        | jK                  tM        |             y y # t*        $ r t        t        d            w xY w)Ndeb822TFz%ERROR: '%s' is not a valid ppa formatz-ubuntu-zERROR: Can't find ppar   zDPPA publishes dbgsym, you may need to include 'main/debug' component)teamppa )'superr   __init___lp_anon_signing_key_data_lp_lpteam_lpppa_is_sourceslist
_match_ppar   any
_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formatr   binary_typetypesurisdistsuitescomps_set_source_entrystr)
selfshortcutloginkwargsmsgr7   
uri_formaturientry	__class__s
            8/usr/lib/python3/dist-packages/softwareproperties/ppa.pyr   zPPAShortcutHandler.__init__4   s    $0Q$Q&Q!	!%$ x(  DK1//9; <@AHL.s33+/==$,,G K

 !!OOE::33`a 48::3E3E/>J##DLL#IC%dB/E++,EKEJ II;ELEK""3u:.# " % K.q1H/IJJKs   G
 
G(c                     | j                   s`| j                  rt        j                  }nt        j                  } || j
                  d| j                  j                  dd      | _         | j                   S )N.
productiondevel)service_rootversion)r   r   r   login_anonymously
login_with
__module__rB   __name__)r:   
login_funcs     rC   lpzPPAShortcutHandler.lph   sX    xx}}&88
&11
!T__dnn>U>U"V/;*13DH xx    c                 V   | j                   s7	 | j                  j                  | j                        | _         | j                   S | j                   S # t        $ r$ t        d      | j                  z  }t        |      t        $ r$ t        d      | j                  z  }t        |      w xY w)Nz8ERROR: user/team '%s' not found (use --login if private)z"ERROR: invalid user/team name '%s')r   rO   peopler%   r   r$   r	   r   r:   r>   s     rC   lpteamzPPAShortcutHandler.lpteamt   s    ||-#ww~~dmm< ||t||  -STW[WdWdd',, -=>N',,-s   *A AB(c                 p   | j                   s8	 | j                  j                  | j                        | _         | j                   S | j                   S # t        $ r0 t        d      | j                  | j                  fz  }t        |      t        $ r$ t        d      | j                  z  }t        |      w xY w)N)namez5ERROR: ppa '%s/%s' not found (use --login if private)zERROR: invalid ppa name '%s')	r   rT   getPPAByNamer&   r   r$   r%   r	   r   rS   s     rC   r)   zPPAShortcutHandler.lpppa   s    {{-"kk66DLL6I {{t{{  -PQt||45',, -784<<G',,-s   +A A$B5c                 .    | j                   j                  S N)r)   descriptionr:   s    rC   rZ   zPPAShortcutHandler.description   s    zz%%%rP   c                 .    | j                   j                  S rY   )r)   web_linkr[   s    rC   r]   zPPAShortcutHandler.web_link   s    zz"""rP   c                    | j                   s| j                  j                         }| j                  j                  }|st	        t        d             ned|v rt	        t        d             nL|| j                  |      vr9t        d      |dj                  | j                  |            fz  }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$   fingerprintsjoinr	   )r:   keyfingerprintr>   s       rC   trustedparts_contentz'PPAShortcutHandler.trustedparts_content   s    %%**..0C**<<Kabcd{*a[\] D$5$5c$::QR#SXXd.?.?.D%EFG',,%(D"%%%rP   c                     t         t        |   |      }|| j                  k7  s| j                  r|S t        t        |j                        t        dg      z
        |_        |S )N)pkgtyper   )r   r   SourceEntrysource_typer+   listsetr7   )r:   ri   rA   rB   s      rC   rj   zPPAShortcutHandler.SourceEntry   sY    ($;G;Ld&&&$//L
 3u{{+c<..AABrP   c                     t         t        |   |       t        | j	                         j
                        t        t              z
  }|r't        t        d      dj                  |      z         y y )Nz*Warning: components '%s' not valid for PPA )
r   r   r8   rm   rj   r7   PPA_VALID_COMPSr-   r$   rd   )r:   lineinvalid_compsrB   s      rC   r8   z$PPAShortcutHandler._set_source_entry   sZ     $9$?D,,.445O8LL!@ACHH]D[[\ rP   c                 *   |j                  d      \  }}}|j                         dk(  sy|j                  d      \  }}}|j                  d      }d|v r.|j                  d      \  }}}|j                         dk7  ryd|v ry|| _        |xs d| _        y)N:r   F/~ubuntuT)
rpartitionlower	partitionlstripr%   r&   )r:   r;   prefixr$   r   r%   r&   rw   s           rC   r    zPPAShortcutHandler._match_ppa   s    #..s3C||~&!$s!31g??3''>#*#4#4S#9 VQ||~)g~ '%rP   c                 V    	 | j                  t        |            S # t        $ r Y yw xY w)NF)_match_handlerr   r
   )r:   r;   s     rC   r"   zPPAShortcutHandler._match_uri   s0    	&&'9('CDD' 		s    	((c                 h    	 | j                  t        |            }d| _        |S # t        $ r Y yw xY w)NFT)r~   r   r
   r   )r:   r;   handlers      rC   r#   z%PPAShortcutHandler._match_sourceslist   s@    	))*DX*NOG  $ ( 		s   % 	11c                    t        |j                         j                        }|j                  t        vry|j
                  j                         j                  d      j                  d      }t        |      dk  ry|d   | _	        |d   | _
        |j                  | _        |j                  | _        | j                  |j                         j                          y)NFru      r      T)r   rj   r@   hostnamePPA_VALID_HOSTNAMESpathstripsplitlenr%   r&   username	_usernamepassword	_passwordr8   rq   )r:   r   parsedr   s       rC   r~   z!PPAShortcutHandler._match_handler   s    '--/334"55{{  "((-33C8t9q=QAw )) ))w22499:rP   c                    | j                   s| j                  j                  sy | j                  r| j                  ry 	 | j
                  j                  | j
                  j                  j                        }|j                  | j                        }t        |      }|j                  | _        |j                  | _        y # t        $ r0 t        d      | j                  | j                   fz  }t#        |      w xY w)N)archivezMCould not find PPA subscription for ppa:%s/%s, you may need to request access)r   r)   r.   r   r   rO   rR   merV   getArchiveSubscriptionURLr   r   r   r   r$   r%   r&   r	   )r:   r   urlr   r>   s        rC   r(   zPPAShortcutHandler._set_auth   s    ==

 2 2>>dnn	-

0B..tzz.BC c]F#__DN#__DN  	)deMM4<<01C#C((	)s   AC 9C:)FrY   )rM   rL   __qualname__r   propertyrO   rT   r)   rZ   r]   rg   rj   r8   r    r"   r#   r~   r(   __classcell__)rB   s   @rC   r   r   3   s    2/h 	 	 
 
   & & # # & &"	]("-rP   r   N)r   r$   launchpadlib.launchpadr   lazr.restfulclient.errorsr   r   r   "softwareproperties.shortcuthandlerr   r	   r
   softwareproperties.sourceslistr   softwareproperties.urir   aptsources.sourceslistr   urllib.parser   r0   r/   r   r   rp   r    rP   rC   <module>r      s~   . ! , J JJ J E 5 4 ! IX ^%%#$--  <(M- M-rP   