|fqddlZddlZddlZddlZddlZddlmZddlmZm Z m Z ddl m Z ddl m ZddlmZddlmZmZmZej*dZGd d eZGd d eZGd deZy)N) get_distro) SourceEntry SourcesListDeb822SourceEntry)suppress)gettext)urlparse)get_source_entry_from_listcopy_source_entrydeb822_source_entry_containsz=gpg -q --no-options --no-default-keyring --batch --keyring %sceZdZdZ d-dZedZedZedZedZ e dZ e d Z e d Z e d Ze d Ze d Zd.dZe dZe dZdZdZdZdZdZdZe dZe dZe dZe dZdZdZe dZ e dZ!e dZ"e d Z#e d!Z$d"Z%d#Z&e d$Z'e d%Z(e d&Z)e d'Z*e d(Z+d)Z,d.d*Z-d.d+Z.d,Z/y)/ShortcutHandleraCSuperclass for shortcut handler implementations. This provides a way to take a apt repository reference, in various forms, and write the specific apt configuration to local files. This also can remove previously written configuration from local files. This class and any subclasses should never modify any main apt configuration files, only specifically named files in '.d' subdirs (e.g. sources.list.d, etc) should be modified. The only exception to that rule is adding or removing sourceslist lines or components of existing source entries. Nc ||_|xsg|_||_t|_|xs|jj |_||_||_||_d|_ d|_ d|_ d|_ yN) shortcut components enable_sourcerdistrocodenamepocketdry_rundeb822 _source_entry _filebase _username _password) selfrrrrrrrkwargss D/usr/lib/python3/dist-packages/softwareproperties/shortcuthandler.py__init__zShortcutHandler.__init__7sr  $** l  8DKK$8$8    "cLt|}|jxr |jS)z(Return if the uri is in valid uri format)r schemenetlocclsuriparseds r is_valid_urizShortcutHandler.is_valid_uriKs #}}..r!ct|}|j|jjddj S)z6Return the uri with the username and password stripped@r$)r _replacer$ rpartitiongeturlr%s ruri_strip_authzShortcutHandler.uri_strip_authQs=#fmm&>&>s&CA&FGNNPPr!ct|j|}|d|d|j}|j|j S)z6Return the uri with the username and password included:r+r-)r r1r$r.r0)r&r'usernamepasswordr(r$s ruri_insert_authzShortcutHandler.uri_insert_authYsC#,,S12%x?f-4466r!cd}|dz } tj5}|d|z }t|ts|j }t j |jd|t jjj}ddd jDcgc](}|jds|jd d *c}S#1swYLxYw#t j$r#}ttd|zgcYd}~Sd}~wwxYwcc}w#t $rttd zgcYSwxYw) zReturn an array of fingerprint(s) for provided key(s). The 'keys' parameter should be in text (str) or binary (bytes) format; it is converted to bytes if needed, and then passed to the 'gpg' program. z6gpg -q --no-options --no-keyring --batch --with-colonsz& --with-fingerprint --with-fingerprint --homedir T)checkinputstdoutNz,Warning: gpg error while processing keys: %sfprr3 zWarning: invalid gpg output: %s)tempfileTemporaryDirectory isinstancebytesencode subprocessrunsplitPIPEr;decodeCalledProcessErrorprint_ splitlines startswithKeyError)r&keyscmdhomedirr;els r fingerprintszShortcutHandler.fingerprints`s)G (( ,,. P'WI..!$.;;=D# 4t/9@@Fvvx  P -3->->-@XALLQVDWAGGCLOX X P P ,,  !CDqH II  Y  !67&@ AI s_C*A6CC*D(.D#D#D(C'#C**D =DD D #D(("E  E c td|jjddj|jjS)NzArchive for codename: z components: ,)rJrdistjoincompsrs r descriptionzShortcutHandler.description|sA##%**88D,,.44578 9r!c|jSr) archive_linkrYs rweb_linkzShortcutHandler.web_links   r!c6|jjSr)rr'rYs rr\zShortcutHandler.archive_links!%%%r!ch|jr|jd|jS|jS)N-)rrrYs rrVzShortcutHandler.dists& ;;"mmT[[9 9}}r!c.|jjS)z*Text indicating a binary-type SourceEntry.)r binary_typerYs rrbzShortcutHandler.binary_type{{&&&r!c.|jjS)z*Text indicating a source-type SourceEntry.)r source_typerYs rrezShortcutHandler.source_typercr!c|js tdt|j}|s|S||jk(r|j dn9||j k(r|j |j ntd|zt|tr|g|_ t|S||_ t|S)a"Get the SourceEntry representing this archive/shortcut. This should never include any authentication data; if required, the username and password should only be available from the username and password properties, as well as from the netrcparts_content property. If pkgtype is provided, it must be either binary_type or source_type, in which case this returns a SourceEntry with the requested type. If pkgtype is not specified, this returns a SourceEntry with an implementation-dependent type (in most cases, implementations should default to binary_type). Note that the default SourceEntry will be returned without modification, and the implementation will determine if it is enabled or disabled; while the source-type SourceEntry will be enabled or disabled based on self.enable_source. The binary-type SourceEntry will always be enabled. The SourceEntry 'file' field should always be set to the value of sourceparts_file. z3Implementation class did not set self._source_entryTzInvalid pkgtype: %s) rNotImplementedErrorr rb set_enabledrer ValueErrorr@rtypestype)rpkgtyperQs rrzShortcutHandler.SourceEntrys,!!%&[\ \ d00 1H d&& & MM$  (( ( MM$,, -2W<= = a* +iAG!##AF ##r!c|jS)aWReturn the username used for authentication If authentication is used, return the username; otherwise return None. By default, this returns the private variable self._username, which defaults to None. Subclasses should override this method and/or set self._username if they have authentication data. )rrYs rr4zShortcutHandler.username~~r!c|jS)aWReturn the password used for authentication If authentication is used, return the password; otherwise return None. By default, this returns the private variable self._password, which defaults to None. Subclasses should override this method and/or set self._password if they have authentication data. )rrYs rr5zShortcutHandler.passwordrnr!cd|j|j|jy)zSave all data for this shortcut to file(s). This writes everything to the relevant files. By default, it calls add_source(), add_key(), and add_login(). Subclasses should override it if other actions are required. N) add_sourceadd_key add_loginrYs raddzShortcutHandler.adds!   r!cD|j|jy)a<Remove all data for this shortcut from file(s). This removes everything from the relevant files. By default, it only calls remove_source() and remove_login(). Subclasses should override it if other actions are required. Note that by default is does not call remove_key(). N) remove_source remove_loginrYs rremovezShortcutHandler.removes  r!cBtd}d}|j|j}|D]#}t|tst ||s!|}n|.t td|j|jfzn|jdddg|j}|j|_ |j|_ |j|_ |j|_|jr_|jj!}|Dcgc]}d|j#r|ndz}}ddj%|z|j&d <|}|j(r|j*t-|jvrd}|j|j*}|D]#}t|tst ||s!|}n|.t td|j*|jfzn|j|j*g|_ |j.st0j2j5|js|jj7|j8rIt0j2j5|j8s t1j:|j8d t=|jd 5t1j>|j|j@ddd|jCyycc}w#1swY xYw) NTrFound existing %s entry in %sfile . z Signed-Byw)"rrrbr@rr rIrJr~rtsourceparts_filerjurissuitesrXtrustedparts_contentrKstriprWsectionrresetrospathexistsrLsourceparts_pathmkdiropenchmodsourceparts_modesave)r sourceslistnewentrybinentryslinesrRsrcentrys r_add_deb822_sourcez"ShortcutHandler._add_deb822_sources!. ##D$4$45 Aa!23+Ax8     !348H8H8@ 8GG H#r2r2,0,A,A'CH%^^HN$MMHM&ooHO%^^HN((11<<>BGHQQWWYC8HH04tyy7G0G  -   $"2"2#hnn:M"MH''(8(89H  !!%67/8< H  #a78D>(--0MM,,T-B-BCGGNN4+@+@AHHT22E:(---CHHX]]D,A,ABC    /I:CCsL +LLch|jr|jy|j|j}|j|j}|j }t }t||}|.ttd|j|jfznY|j|j|j|j|j|j}|j |_|j|jk7r"ttd|jzn|j"r> 'H!) 1 1H  ==HMM ) !ABX]]R S   'O00HM !788==H I    !45 8VV W !+, x}}/MM N!  -k8D   !34 x}}7UU V"LL]]]]]]#>> 'H!) 1 1H  ==HMM ) !ABX]]R S    !45 8VV W !+, x}}/MM N|| (--!?@ 2 ww~~i0!,,T-B-BC "t/D/D E!6!6>i-2D122  2    22s 5P((P1 c td}|j|j}|D]U}t|tst ||s!t td|jz|}|j|n|js\|j|Dcgc]}|j|jk(s| c}s! tj|jyyycc}w#ttf$rYywxYw)NTrzzRemoving entry from %s)rrrbr@rr rIrJr~rxrrrOSErrorIOError)rrrrs r_remove_deb822_sourcez%ShortcutHandler._remove_deb822_sources!. ##D$4$45 Aa!23+Ax8a01QVV<=""8, ||    *F!aff .EAFIIhmm,GF )s"C+C+ C00DDc |jr|jyt}t|Dcgc]}|jc}}|j |j }|j |j}d|_d|_|D]E}t||g|ttd|j|jfzd|_G|Dcgc]}|j|jk(s| }}|Dcgc]}|jr|jr| c}sQ|D]L}|js-ttd|j|jfz|j|N|j sR|j#|t|Dcgc]}|jc}z D]} t%j|yycc}wcc}wcc}wcc}w#t&t(f$rYBwxYw)a~Remove the apt SourceEntries. This uses SourcesList to remove the binary-type and source-type SourceEntries. This must disable the corresponding SourceEntries, from whatever file(s) they are located in. This must not disable more than matches, e.g. if the existing SourceEntry line contains more components this must edit the existing line to remove this SourceEntry's component(s). After disabling all matching SourceEntries, if the sourceparts_file is empty or contains only invalid and/or disabled SourceEntries, this may remove the sourceparts_file. NFzDisabling %s entry in %sTz"Removing disabled %s entry from %s)rrrrr~rrbrerr rIrJrkrinvalidrxrrrrr) rrrQ orig_filesrrr file_entriesr~s rrvzShortcutHandler.remove_sources ;;  & & ( !m +6Q!&&67 ##D$4$45##D$4$45!! "A)8H*=qAMa23qvvqvv6FFG!  " $/Ra!&&D??r!c\|jrdnd}|j||jS)aiGet the sources.list.d filename, without the leading path. By default, this combines the filebase with the codename, and uses a extension of 'list' if deb822 is not enabled, and 'sources' if deb822 is enabled. This is different than the trustedparts or netrcparts filenames, which use only the filebase plus extension. sourceslistsuffix)r_filebase_to_filenamer)rexts rsourceparts_filenamez$ShortcutHandler.sourceparts_filenames+ ;;iF))#dmm)DDr!cN|j|j|jS)aGet the sources.list.d absolute-path filename. Note that the add_source() function will not use this file if this shortcut's SourceEntry matches a known apt template; instead the entries will be placed in the main sources.list file. Also, if the SourceEntry already exists in the SourcesList, it will be edited in place, instead of using this file. See add_source() for more details. )_filename_to_filerrrYs rrz ShortcutHandler.sourceparts_files#%%d&;&;T=V=VWWr!cy)zMode of sourceparts file. Note that add_source() will only use this mode if it creates a new file for sourceparts_file; if the file already exists or if the SourceEntry is saved in a different file, this mode is not used. rYs rrz ShortcutHandler.sourceparts_modesr!c|jryt|j|jfsy|j}|j}t |t s|j }|j|}ttd|dj|fzt|z}d}|jstjj|s|j!|j"rJtjj|j"s!tj$|j"d|j&r5t)|d5tj*||j&ddd t-j.5}|d|d |z }t1j2|j5d | dddyy#1swYZxYw#1swYyxYw#t0j6$r}t9|d}~wwxYw) a[Add the GPG key(s) corresponding to this repo. By default, if self.trustedparts_content contains content, and self.trustedparts_file points to a file, the key(s) will be added to the file. If the file does not yet exist, and self.trustedparts_mode is set, the file will be created with that mode. Nz$Adding key to %s with fingerprint %srUz--importrrwbr8rT)r9r:)ralltrustedparts_filerr@rArBrSrIrJrWGPG_KEYRING_CMDrrrrrLtrustedparts_pathrtrustedparts_moderrr>r?rCrDrErHShortcutException)rdestrNfprOactionrPrQs rrrzShortcutHandler.add_keys ;; D**D,E,EFG %%(($&;;=D   t $ a674":NNO$||77>>$'OOD$:$:;GGNN4+A+ABHHT33%@))dD)?t'='=>? +002Hg[ 6(;;CNN399;d$GHH??HH00 +'** +sB!G?G'2GG'GG$ G'$G''H : HH c,t|j|jfsy|j}|j|j}tj j |syttd|dj|fzt|z}ddj|z}|js tj5}|d|d|z }tj|j!ddddt'|d 5}|j|j) }dddrt j*|yyy#1swYXxYw#tj"$r}t%|d}~wwxYw#1swYUxYw) aRemove the GPG key(s) corresponding to this repo. By default, if self.trustedparts_content contains content, and self.trustedparts_file points to a file, the key(s) will be removed from the file. If the file contains no more keys after removal, the file will be removed. This does not consider other files; multiple repositories may use the same signing key. This only modifies/removes self.trustedparts_file. Nz(Removing key from %s with fingerprint %srUz--delete-keys %srr8T)r9rb)rrrrSrrrrIrJrWrrr>r?rCrDrErHrrreadrx) rrrrOrrPrQfemptys r remove_keyzShortcutHandler.remove_keys`D**D,E,EFG %%   t88 9ww~~d#  a:;tSXXb\>RRS$#chhrl2|| +002X>XYYr!cy)z&Content to put into trusted.gpg.d fileNrrYs rrz$ShortcutHandler.trustedparts_contentVsr!cy)zMode of trustedparts filerrrYs rrz!ShortcutHandler.trustedparts_mode[r!ct|j|jfsy|j}|j}tjj | }d}|st |d5}|jDcgc]}|j}}dddtt5dd}dddt|jDcgc]}|jvc}rttd|zyttd|z|js|r|j|j rJtjj |j s!tj"|j d|j$r5t |d 5tj&||j$dddt |d 5}|dk7r|j)d|j)|jdddyycc}w#1swYxYw#1swY~xYwcc}w#1swYuxYw#1swYyxYw) zAdd the login credentials corresponding to this repo. By default, if self.netrcparts_content contains content, and self.netrcparts_file points to a file, the file will be created and content placed into it. Nrrz!Authentication data already in %sz Adding authentication data to %srrra)rnetrcparts_filenetrcparts_contentrrrr readlinesrrrMrKrIrJrrLnetrcparts_pathrnetrcparts_moderwrite)rrcontentnewfile finalcharrrRrs rrszShortcutHandler.add_login`sD(($*A*ABC ##))ggnnT** dC ;A,-KKM:q:: ;(# *!"IbM  *0B0B0DE1AGGI&EFa;''dC=t';';<=dC 1A$GGDM//0  1 1; ; ; * *E== 1 1sH+H&>H!H&. H3I0!I%2I!H&&H03H=IIct|j|jfsy|j}t|jj Dcgc]}|j c}}t jj|syt|d5}t|jDcgc]}|j c}}ddd|zsttd|zn[ttd|z|js8t|d5}|jdj||z ddd|jsMt|d5}|j!j }dddrt j"|yyycc}wcc}w#1swYxYw#1swYyxYw#1swYExYw)aRemove the login credentials corresponding to this repo. By default, if self.netrcparts_content contains content, and self.netrcparts_file points to a file, the content will be removed from the file. If the file is empty (other than whitespace) after removal, the file will be removed. This does not consider other files; this only modifies/removes self.netrcparts_file. Nrz'Authentication data not contained in %sz$Removing authentication data from %srr)rrrrrKrrrrrrrIrJrrrWrrx)rrrRrr filecontentrs rrwzShortcutHandler.remove_logins~D(($*A*ABC ##$*A*A*L*L*NOQqwwyOPww~~d#  $_ B!++-@Qqwwy@AK BW$ !=>E F !:;dB C<<$_>GGDIIkG&;<=>||dC -AFFHNN,, - $P A B B>> - -s<F*F42F/ F4$$G( G /F44F=G  Gc@tjjdS)z@Return result of apt_pkg.config.find_dir("Dir::Etc::netrcparts")zDir::Etc::netrcpartsrrYs rrzShortcutHandler.netrcparts_paths~~&&'=>>r!c$|jdS)z7Get the auth.conf.d filename, without the leading path.confrrYs rnetrcparts_filenamez#ShortcutHandler.netrcparts_filenames))&11r!cN|j|j|jS)z+Get the auth.conf.d absolute-path filename.)rrrrYs rrzShortcutHandler.netrcparts_files#%%d&:&:Daptsources.distroraptsources.sourceslistrrr contextlibrrrJ urllib.parser softwareproperties.sourceutilsr r r initrobjectr Exceptionrrrr!rr sn$ (PP !JJ   QG (fG (T   0 r!