
    Se                         d Z ddlZddlm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 ej                  j                  Zd	Zd
ZdZej                  j                  ZdZdZ G d de      Zy)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)Path)	SourceKey   )SourceSourceError)
SourceFile)utilzhttp://apt.pop-os.org/stagingmainzDhttps://raw.githubusercontent.com/pop-os/pop/master/scripts/.iso.ascpopdev:c            	            e Zd ZdZ ed      ZeZede	de
fd       Zddd fd	
Z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 xZS )PopdevSourcez PopDev Source shortcut

    These are given in the format popdev:branchname. 

    Arguments:
        shortcut (str): The ppa: shortcut to process
    z/etc/apt/preferences.dshortcutreturnc                     d| v ry| j                  d      }	 |d   sy	 | j                  t         d      r | j                  d      }t	        |      dkD  ryy# t        $ r Y yw xY w)zDetermine whether a PPA shortcut is valid.
        
        Arguments:
            shortcut(str): The shortcut to validate
        
        Returns: bool
            `True` if the PPA is valid, otherwise False
        /Fr      r   T)split
IndexError
startswithprefixlen)r   shortcut_split	shortlists      :/usr/lib/python3/dist-packages/repolib/shortcuts/popdev.py	validatorzPopdevSource.validator7   s{     (?!,	!!$ %
 &|, s+I9~!  		s   A 	A$#A$ T)line
fetch_datac                   |r |j                  d      st        d| d      t        |   ||       t	        j
                  t              | _        || _        d| _	        d | _
        d| _        d| _        |r| j                  |       y y )Nzppa:zThe PPA shortcut  is malformedTr   )r   r   super__init__logging	getLogger__name__logr   twin_source
prefs_pathbranch_name
branch_urlload_from_shortcut)selfr   r   argskwargs	__class__s        r   r#   zPopdevSource.__init__R   s    ??6*!$5dV="IJJv&$$X.	 $! ##D)     Nc                    t        |   |i | | j                  j                  d| j                         d}|d| j
                   dz  }|dz  }| j                  j                  d| j                  |       	 t        | j                  d      5 }|j                  |       d d d        | j                  j                  d| j                         y # 1 sw Y   0xY w# t        $ r t        j                         }	 |j                  d	d
      }|j                  t        | j                        |       nJ# t        j                   j"                  $ r* | j                  j%                  d       t'        d       Y Y y w xY wY w xY w)NzSaving prefs file for %szPackage: *
zPin: release o=pop-os-staging-
zPin-Priority: 1002
z%s prefs for pin priority:
%sw)modezorg.pop_os.repolibz/RepozDBus service not found!z%Permission denied. Please use `sudo`.zPin priority saved for %s)r"   
tasks_saver'   infoidentr+   debugopenprefswritePermissionErrordbus	SystemBus
get_objectoutput_prefs_to_diskstr
exceptionsDBusExceptioncriticalprint)r-   r.   r/   prefs_contents
prefs_filebusprivileged_objectr0   s          r   r6   zPopdevSource.tasks_save`   sF   D+F+0$**=':4??:K2NN007^T	djjs+ 1z  01 	2DJJ?1 1 	.."C$'NN3G$Q!!66s4::W??00 !!";<=> X		sO   9C C"C CC F ;7D32F 3AE:6F 9E::F ?F c                      y)NzPop Development Staging branch )r-   s    r   get_descriptionzPopdevSource.get_descriptiony   s    0r1   datac                 l    | j                   j                  d|d          | j                  |d          y )NzLoading line %sr   )r   )r'   r9   r,   )r-   rN   s     r   load_from_datazPopdevSource.load_from_data}   s.    ($q'2a1r1   metaget_keyc                    | j                          |r|| _        | j                  st        d      | j                  | j                        st        d| j                   d      | j                  j                  d| j                         |j                  t              | _        dj                  | j                  dd       | _
        t        j                  | j                        | _        | j                  j                  d	| j                         t         d
| j                   | _        | j                   dt         j"                   t        j$                  vrct'        | j                        }t         |_        || _        | j*                  t        j$                  t-        | j*                  j.                        <   n5t        j$                  t-        | j*                  j.                           | _        | j*                  j1                  |        d| j                   | _        t4         d| j                   g| _        t        j8                  g| _        t<        g| _        tA        d      }|jC                  tD               || _#        t-        | jF                  j.                        | _$        | jJ                  d| j                   z  | _&        | jL                  | _'        d| _(        y)zTranslates the shortcut line into a full repo.
        
        Arguments:
            shortcut(str): The shortcut to load, if one hasn't been loaded yet.
        zNo PPA shortcut providedz	The line r!   zLoading shortcut %sr   r   N)namezPopdev branch name: %s-.zPop Development Branch r   r   )urlzpop-os-staging-T))reset_valuesr   r   r   r'   r9   r   
delineator
info_partsjoinr+   r	   scrub_filenamer*   r   r8   BASE_FORMATvaluefilesr   formatfilerB   path
add_sourcerT   BASE_URLurisDISTRO_CODENAMEsuites
BASE_COMPS
componentsr   load_key_dataBASE_KEYURLkey	signed_by	prefs_dirr)   r;   enabled)r-   r   rQ   rR   new_filerl   s         r   r,   zPopdevSource.load_from_shortcut   s    	 DIyy899~~dii(	$))MBCC,dii8"..4((4??12#67..DOOD/1A1ABxq!1!1 23
jj\;,,-.djj@!tzz2H)HO DI.2iiDJJs499>>*+

3tyy~~#67DI		T"-d.>.>-?@	 z4??"345	++,%,X&k*TXX]]+.._T=M=M<N+OO__
r1   )r   N)r   TT)r&   
__module____qualname____doc__r   rn   r]   default_formatstaticmethodrB   boolr   r#   r6   rM   listrP   r,   __classcell__)r0   s   @r   r   r   ,   s     -.I N3 4  4 $&$ *@21 124 2D 2/# /t /$ /X\ /r1   r   )rs   r$   pathlibr   r>   repolib.keyr   sourcer   r   ra   r   r   r	   SourceFormatDEFAULTr]   rd   rh   rk   DEFAULT_FORMATr   rY   r   rL   r1   r   <module>r      sj   (    ! (  ''*
T""**	
D6 Dr1   