Ë
    ëSûe†"  ã                   ó$  — d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 	 ddlmZ dd	lmZmZmZ e
j$                  j&                  ZdZdZdZe
j$                  j&                  ZdZdZ G d„ de«      Z G d„ d«      Zd„ Zy# e$ r	  ed
«      ‚w xY w)aÅ  
Copyright (c) 2022, Ian Santopietro
All rights reserved.

This file is part of RepoLib.

RepoLib is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

RepoLib is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with RepoLib.  If not, see <https://www.gnu.org/licenses/>.
é    N)Ú	SourceKeyé   )ÚSourceÚSourceError)Ú
SourceFile)Úutil)Ú	Launchpad)Ú
BadRequestÚNotFoundÚUnauthorizedzfMissing optional dependency "launchpadlib". Try `sudo apt install python3-launchpadlib` to install it.zhttp://ppa.launchpad.netÚubuntuÚmainÚppaú:c            	       óö   ‡ — e Zd ZdZeZededefd„«       Z	dddœˆ fd„
Z
defd	„Zd
eddfd„Zddedededdfd„Zedefd„«       Zej"                  dd„«       Zedefd„«       Zej"                  dd„«       Zˆ xZS )Ú	PPASourcea   PPA Source shortcut

    These are given in the format ppa:owner/name. Much of this code is adapted 
    from SoftwareProperties.

    Arguments:
        shortcut (str): The ppa: shortcut to process
        fetch_data (bool): Whether to try and fetch metadata from Launchpad.
    ÚshortcutÚreturnc                 ót   — | j                  t        › d�«      r | j                  d«      }t        |«      dkD  ryy)zÚDetermine whether a PPA shortcut is valid.
        
        Arguments:
            shortcut(str): The shortcut to validate
        
        Returns: bool
            `True` if the PPA is valid, otherwise False
        r   ú/é   TF)Ú
startswithÚprefixÚsplitÚlen)r   Ú	shortlists     ú7/usr/lib/python3/dist-packages/repolib/shortcuts/ppa.pyÚ	validatorzPPASource.validator?   s8   € ð ×Ñ¤& ¨˜|Ô,Ø Ÿ™ sÓ+ˆIÜ�9‹~ Ò!ØØó    Ú T)ÚlineÚ
fetch_datac                ó(  •— |r |j                  d«      st        d|› d�«      ‚t        ‰| �  ||«       t	        j
                  t        «      | _        || _        d | _	        d| _
        d| _        d| _        |r| j                  | j                  «       y y )Nzppa:zThe PPA shortcut ú is malformedTr    )r   r   ÚsuperÚ__init__ÚloggingÚ	getLoggerÚ__name__Úlogr!   r   Útwin_sourceÚ_displaynameÚ_descriptionÚload_from_shortcut)Úselfr!   r"   ÚargsÚkwargsÚ	__class__s        €r   r&   zPPASource.__init__P   sˆ   ø€ ÙØ—?‘? 6Ô*Ü!Ð$5°d°V¸=Ð"IÓJÐJÜ‰Ñ˜˜vÔ&Ü×$Ñ$¤XÓ.ˆŒØˆŒ	ØˆŒØˆÔØˆÔØˆÔÙØ×#Ñ# D§I¡IÕ.ð r   c                 óP   — d}|| j                   z  }|dz  }|| j                  z  }|S )Nr    z

)ÚdisplaynameÚdescription)r/   Úoutputs     r   Úget_descriptionzPPASource.get_description^   s6   € ØˆØ�$×"Ñ"Ñ"ˆØ�&ÑˆØ�$×"Ñ"Ñ"ˆØˆr   ÚdataNc                 ó.   — | j                  |d   ¬«       y )Nr   )r   )r.   )r/   r8   s     r   Úload_from_datazPPASource.load_from_datae   s   € Ø×Ñ¨¨a©ÐÕ1r   ÚmetaÚkeyc                 óÄ  — | j                  «        |r|| _        | j                  st        d«      ‚| j                  | j                  «      st        d| j                  › d�«      ‚| j                  j	                  t
        t        z   d«      }|j                  d«      | _        | j                  d   }| j                  d   }t
        › d|› d|› �| _	        | j                  › d	t        j                  › �t        j                  vrct        | j                  ¬
«      }t        |_        || _        | j                   t        j                  t#        | j                   j$                  «      <   n5t        j                  t#        | j                   j$                  «         | _        | j                   j'                  | «       | j                  | _        t*        › d|› d|› dt,        › �g| _        t        j0                  g| _        t4        g| _        |s|rGt9        ||«      | _        | j:                  j<                  | _        | j:                  j>                  | _        | j:                  r|r| j:                  j<                  | _        | j:                  r×|rÕtA        | j                  ¬
«      }t#        |j$                  «      t        jB                  vrT|jE                  | j:                  jF                  ¬«       |t        jB                  t#        |j$                  «      <   || _$        n"t        jB                  |j$                     | _$        t#        | jH                  j$                  «      | _%        d| _&        y)a+  Translates the shortcut line into a full repo.
        
        Arguments:
            shortcut(str): The shortcut to load, if one hasn't been loaded yet.
            meta(bool): Whether to fetch repo metadata from Launchpad
            key(bool): Whether to fetch and install a signing key
        zNo PPA shortcut providedz	The line r$   r    r   r   r   ú-ú.©Úname)ÚfingerprintTN)'Úreset_valuesr!   r   r   Úreplacer   Ú
delineatorr   Ú
info_partsÚidentÚBASE_FORMATÚvaluer   Úfilesr   ÚformatÚfileÚstrÚpathÚ
add_sourcerA   ÚBASE_URLÚ	BASE_DISTÚurisÚDISTRO_CODENAMEÚsuitesÚ
BASE_COMPSÚ
componentsÚget_info_from_lpr   r4   r5   r   ÚkeysÚload_key_datarB   r<   Ú	signed_byÚenabled)	r/   r   r;   r<   r!   Ú	ppa_ownerÚppa_nameÚnew_fileÚrepo_keys	            r   r.   zPPASource.load_from_shortcuth   si  € ð 	×ÑÔÙØ ˆDŒIà�yŠyÜÐ8Ó9Ð9à�~‰~˜dŸi™iÔ(Ü 	¨$¯)©)¨°MÐBÓCÐCà�y‰y× Ñ ¤¬*Ñ!4°bÓ9ˆØŸ*™* S›/ˆŒØ—O‘O AÑ&ˆ	Ø—?‘? 1Ñ%ˆä�x˜q  ¨1¨X¨JÐ7ˆŒ
Ø�j‰jˆ\˜œ;×,Ñ,Ð-Ð.´d·j±jÑ@Ü! t§z¡zÔ2ˆHÜ)ˆHŒOØ ˆDŒIØ.2¯i©iŒD�J‰J”s˜4Ÿ9™9Ÿ>™>Ó*Ò+äŸ
™
¤3 t§y¡y§~¡~Ó#6Ñ7ˆDŒIà�	‰	×Ñ˜TÔ"à—J‘JˆŒ	Ü �z  9 +¨Q¨x¨j¸¼)¸ÐEÐFˆŒ	Ü×+Ñ+Ð,ˆŒÜ%˜,ˆŒá‘3Ü'¨	°8Ó<ˆDŒHØ#Ÿx™x×3Ñ3ˆDÔØ#Ÿx™x×3Ñ3ˆDÔà�8Š8™ØŸ™×,Ñ,ˆDŒIà�8Š8™Ü  d§j¡jÔ1ˆHÜ�8—=‘=Ó!¬¯©Ñ2Ø×&Ñ&°4·8±8×3GÑ3GÐ&ÔHØ08”—	‘	œ#˜hŸm™mÓ,Ñ-Ø%-�•äŸ9™9 X§]¡]Ñ3�”Ü  §¡§¡Ó/ˆDŒNàˆ�r   c                 ó˜   — | j                   r| j                   S | j                  r| j                  j                  | _         | j                   S )z)The name of the PPA provided by launchpad)r,   r   r4   ©r/   s    r   r4   zPPASource.displayname£   ó>   € ð ×ÒØ×$Ñ$Ð$Ø�8Š8Ø $§¡× 4Ñ 4ˆDÔØ× Ñ Ð r   c                 ó   — || _         y©z%Cache this for use without hitting LPN)r,   )r/   r4   s     r   r4   zPPASource.displayname¬   s   € ð (ˆÕr   c                 ó˜   — | j                   r| j                   S | j                  r| j                  j                  | _         | j                   S )z0The description of the PPA provided by Launchpad)r-   r   r5   ra   s    r   r5   zPPASource.description±   rb   r   c                 ó   — || _         yrd   )r-   )r/   Údescs     r   r5   zPPASource.descriptionº   s   € ð !ˆÕr   )r    TT)r   N)r)   Ú
__module__Ú__qualname__Ú__doc__rH   Údefault_formatÚstaticmethodrM   Úboolr   r&   r7   Úlistr:   r.   Úpropertyr4   Úsetterr5   Ú__classcell__)r2   s   @r   r   r   2   sç   ø„ ñð !€Nàð˜3ð  4ò ó ðð  $&°$ö /ð ó ð2 4ð 2¨Dó 2ñ9¨#ð 9°tð 9Àdð 9ÐTXó 9ðv ð!˜Sò !ó ð!ð ×Ñò(ó ð(ð ð!˜Sò !ó ð!ð ×Ñò!ó ô!r   r   c                   ó‚   — e Zd ZdZd„ Zed„ «       Zed„ «       Zed„ «       Zede	fd„«       Z
ede	fd„«       Zed	„ «       Zy
)ÚPPAzo An object to fetch data from PPAs. 
    
    Portions of this class were adapted from Software Properties
    c                 óf   — || _         || _        d | _        d | _        d | _        d | _        d | _        y )N)ÚteamnameÚppanameÚ_lapÚ_lpteamÚ_lpppaÚ_signing_key_dataÚ_fingerprint)r/   ru   rv   s      r   r&   zPPA.__init__Å   s5   € Ø ˆŒØˆŒØˆŒ	ØˆŒØˆŒØ!%ˆÔØ ˆÕr   c                 ó²   — | j                   s@t        j                  | j                  › d| j                  j
                  › �dd¬«      | _         | j                   S )z The Launchpad Object.r?   Ú
productionÚdevel)Úservice_rootÚversion)rw   r	   Úlogin_anonymouslyrh   r2   r)   ra   s    r   ÚlapzPPA.lapÎ   sM   € ð �yŠyÜ!×3Ñ3Ø—?‘?Ð# 1 T§^¡^×%<Ñ%<Ð$=Ð>Ø)ØôˆDŒIð
 �y‰yÐr   c                 óJ  — | j                   s7	 | j                  j                  | j                  «      | _         | j                   S | j                   S # t        $ r!}d| j                  › d�}t        |«      |‚d}~wt        $ r!}d| j                  › d�}t        |«      |‚d}~ww xY w)z* The Launchpad object for the PPA's owner.zUser/Team "z" not foundNzInvalid user/team name "ú")rx   r‚   Úpeopleru   r   r   r   ©r/   ÚerrÚmsgs      r   Úlpteamz
PPA.lpteamÙ   s–   € ð �|Š|ð0Ø#Ÿx™xŸ™¨t¯}©}Ó=�”ð �|‰|Ðˆt�|‰|Ðøô ò 0Ø# D§M¡M ?°+Ð>�Ü! #Ó&¨CÐ/ûÜò 0Ø0°·±°¸qÐA�Ü! #Ó&¨CÐ/ûð0ús#   Ž*A Á	B"ÁA5Á5B"ÂBÂB"c                 óf  — | j                   s8	 | j                  j                  | j                  ¬«      | _         | j                   S | j                   S # t        $ r.}d| j
                  › d| j                  › d�}t        |«      |‚d}~wt        $ r!}d| j                  › d�}t        |«      |‚d}~ww xY w)z" The Launchpad object for the PPA.r@   zPPA "r   z"" not foundNzInvalid PPA name "r„   )ry   r‰   ÚgetPPAByNamerv   r   ru   r   r
   r†   s      r   Úlpppaz	PPA.lpppaç   s¥   € ð �{Š{ð0Ø"Ÿk™k×6Ñ6¸D¿L¹LÐ6ÓI�”ð �{‰{Ðˆt�{‰{Ðøô ò 0Ø˜dŸm™m˜_¨A¨d¯l©l¨^¸<ÐH�Ü! #Ó&¨CÐ/ûÜò 0Ø*¨4¯<©<¨.¸Ð:�Ü! #Ó&¨CÐ/ûð0ús#   Ž+A Á	B0Á)BÂB0ÂB+Â+B0r   c                 ó6   — | j                   j                  xs dS )z str: The description of the PPA.r    )rŒ   r5   ra   s    r   r5   zPPA.descriptionõ   ó   € ð �z‰z×%Ñ%Ò+¨Ð+r   c                 ó6   — | j                   j                  xs dS )z  str: the fancy name of the PPA.r    )rŒ   r4   ra   s    r   r4   zPPA.displaynameú   rŽ   r   c                 óh   — | j                   s| j                  j                  | _         | j                   S )z) str: the fingerprint of the signing key.)r{   rŒ   Úsigning_key_fingerprintra   s    r   rB   zPPA.fingerprintÿ   s+   € ð × Ò Ø $§
¡
× BÑ BˆDÔØ× Ñ Ð r   N)r)   rh   ri   rj   r&   ro   r‚   r‰   rŒ   rM   r5   r4   rB   © r   r   rs   rs   ¿   s’   „ ñò
!ð ñó ðð ñó ðð ñó ðð ð,˜Sò ,ó ð,ð ð,˜Sò ,ó ð,ð ñ!ó ñ!r   rs   c                 ó   — t        | |«      }|S )a   Attempt to get information on a PPA from launchpad over the internet.

    Arguments:
        owner_name (str): The Launchpad user owning the PPA.
        ppa (str): The name of the PPA

    Returns:
        json: The PPA information as a JSON object.
    )rs   )Ú
owner_namer   s     r   rW   rW     s   € ô ˆj˜#Ó
€CØ€Jr   )rj   r'   Úrepolib.keyr   Úsourcer   r   rL   r   r    r   Úlaunchpadlib.launchpadr	   Úlazr.restfulclient.errorsr
   r   r   ÚImportErrorÚSourceFormatÚLEGACYrH   rP   rQ   rU   ÚDEFAULT_FORMATr   rE   r   rs   rW   r’   r   r   ú<module>r�      s«   ðñó( å !ç (Ý Ý ðÝ0ßLÑLð ×Ñ×&Ñ&€Ø%€Ø€	Ø€
à×"Ñ"×)Ñ)€à	€Ø€
ôK!�ô K!÷ZE!ñ E!óPøðK ò Ù
ð	/óð ðús   ¢B ÂB