fddlZddlZddlmZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlZ ddlZddl mZddlmZ ddlmZddlmZddlZddlZddlZdd lmZdd lmZm Z m!Z!dd l"m#Z#dd l$m%Z%dd l&m'Z'Gdde(Z)e*dk(r/e)Z+e,e+j[e+j]dyy#e$rejZ YwxYw#e$rddlZYwxYw#e$r ddlmZYwxYw)N)md5) maketrans)NamedTemporaryFile)escape) ConfigParser)gettext)AptAuth) SourcesList SourceEntryDeb822SourceEntry)InvalidShortcutException)shortcut_handler)GioceZdZdZdZeed\ZZZ edede diZ d=dZ d Z d Z d Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"d Z#d!Z$d"Z%d#Z&d$Z'd%Z(d&Z)d'Z*d(Z+d)Z,d*Z-d+Z.d,Z/d-Z0d.Z1d/Z2d0Z3d1Z4d2Z5d3Z6d>d4Z7d>d5Z8d?d6Z9d7Z:d8Z;d9Ze?d@d<Z@y)ASoftwarePropertiesz /usr/share/app-install/channels/z$/etc/update-manager/release-upgradesnormalltsneverNcP|dz|_||_|dk7r tjj d||dk(rd}||_||_t||_tjj|_ g|_ d|_ |j|j|j!g|_t%j&|_t+||_t/j0|_t5j6|j8y) z Provides the core functionality to configure the used software repositories, the corresponding authentication keys and update automation z/etc/popularity-contest.conf/DirNz/usr/share/software-properties/)deb822F)rootdir) popconfilerapt_pkgconfigsetoptionsdatadirr sourceslist aptsourcesdistro get_distro seen_servermodified_sourceslistreload_sourceslistbackup_sourceslistbackup_apt_confcustom_mirrorsqueueQueuemyqueuer apt_keyr Cancellable cancellableatexitregisterwait_for_threads)selfr!r rrs G/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py__init__zSoftwareProperties.__init__Ws<}|jtjjk7s/|j @y)z9 wait for all running threads (PPA key fetchers) to exit N) threading enumerateidentcurrent_threadjoin)r5ts r6r4z#SoftwareProperties.wait_for_threadss>  " I,,.44 4 r8ci|_tjjD]A}tj j tj|}||j|<Cy)z$Backup all apt configuration optionsN)apt_conf_backupsoftwarepropertiesCONF_MAPkeysrrfind_i)r5optionvalues r6r*z"SoftwareProperties.backup_apt_confsXD$--224-%%&8&A&A&&IJ',V$-r8c|jjD]I}tjj t j |t|j|K|jy)z$Restore the stored apt configurationN) rArDrrrrBrCstr write_config)r5rFs r6restore_apt_confz#SoftwareProperties.restore_apt_confsa&&++->-66v>t33F;< >> r8ctjjtjddkDrOtjjtjddk(r/t j jdrtjStjjtjddk(rCtjjtjddk(rtjStjjtjddk(rCtjjtjddk(rtjSytjjtjddk(rCtjjtjddk(rtjSy)z Parse the apt cron configuration. Try to fit a predefined use case and return it. Special case: if the user made a custom configurtation, that we cannot represent it will return None autoupdater unattendedr z/usr/bin/unattended-upgrade autodownloadN) rrrErBrCospathexistsUPDATE_INST_SECUPDATE_DOWNLOAD UPDATE_NOTIFY UPDATE_MANUALr5s r6get_update_automation_levelz.SoftwareProperties.get_update_automation_levelsg~~/88FG!K >> !3!#>~#N OST T ^^ " "#5#>#>|#L MQR R%55 5 ^^ " "#5#>#>|#L MQR R ^^ " "#5#>#>~#N OST T%33 3   1::<H IQ N   1::>J Kq P!///r8c|tjk(rvtjj tj dt dtjj tj dt dn|tjk(rvtjj tj dt dtjj tj dt dn6|tjk(rutjj tj dt dtjj tj dt dntjj tj dt dtjj tj dt dtjj tj dt d|jy)z Set the apt periodic configurtation to the selected update automation level. To synchronize the cache update and the actual upgrading function, the upgrade function, e.g. unattended, will run every day, if enabled. rNr rOrrMN) rBrSrrrrCrIrTrUset_modified_config)r5states r6set_update_automation_levelz.SoftwareProperties.set_update_automation_levels  "222-66|Dc!fM-66~FAO $44 4-66~FAO-66|Dc!fM $22 2-66~FAO-66|Dc!fM-66|Dc!fM-66|Dc!fM-66~FAOr8c|tjjtjdk(sKtjj tjdt ||jyy)z8Set the interval in which we check for available updatesrMN)rrrErBrCrrIrZ)r5dayss r6set_update_intervalz&SoftwareProperties.set_update_intervals]W^^**+=+F+F|+TU U ..  /88FD R  " " $Vr8cbtjjtjdS)z3 Returns the interval of the apt periodic cron job rM)rrrErBrCrWs r6get_update_intervalz&SoftwareProperties.get_update_intervals# >> !3!>$44 5  ) )) ^F KK**+ 8, ZZ ( + 1 1 3d2288:$!Q 9(  ' ''r8c(tjj|jsAt |jd5}|j d|j |zdddyt |jd5}td5}|D]g}|j}|jjdr"|j d |j |zT|j |d zi|jtj|j|jtj|j|jddddddy#1swYyxYw#1swYxYw#1swYyxYw) z set the release upgrade policy: RELEASE_UPGRADES_NORMAL, RELEASE_UPGRADES_LTS, RELEASE_UPGRADES_NEVER wz[DEFAULT] Prompt=%s NTrzw+)modepromptz Prompt=%s  )rPrQrRreopenwriterkrstriprj startswithflushshutilcopymodenamecopy)r5ifoutlines r6set_release_upgrades_policyz.SoftwareProperties.set_release_upgrades_policysC 77>>$44 5 **3 /O1 ($*J*J1*MMNO  d(( - 84FD4Q 8UX$zz| ::< " "8 , ))MD$D$DQ$GG H ))DI    iik ood00#((; kk#((D667 8 8 O  8 8 8 s1"E0 FCE<F0E9<F FFctjj|jrt |j5}|j j d}dddD]@} |j d\}}|dk(r$|jdjdk(ryBy#1swYOxYw#t$rY[wxYw) z Will return True if the user wants to participate in the popularity contest. Otherwise it will return False. Special case: if no popcon is installed it will return False rwN= PARTICIPATE"yesTF) rPrQrRrrxrgsplitrzrj ValueError)r5rlinesrkeyrGs r6get_popcon_participationz+SoftwareProperties.get_popcon_participations ww~~doo& $// " 'a&&(..&% ' D "jjo U-'EKK,<,B,B,D,M    ' '  s B--;B9-B69 CCc |dk(rd}nd}tjj|jrGt |jd5}|Dcgc]}t j dd|z|}}dddnt}t dd 5}|j|jd ddd|j}g}|jd |z|jd t|z|jd t |jd5}|jdddycc}w#1swY?xYw#1swYxYw#1swYyxYw)z? Enable or disable the participation in the popularity contest Trnortz^(PARTICIPATE=)(".+?")z\1"%s"Nz /dev/urandomrbizMY_HOSTID="%s" zPARTICIPATE="%s" zUSE_HTTP="yes" rs)rPrQrRrrxresubrupdaterg hexdigestappendrI writelines) r5 is_helpfulrGrrrmrids r6set_popcon_pariticipationz,SoftwareProperties.set_popcon_pariticipationsBT ww~~doo&$//3 ' -:!+-VV5y57H$O-E- - - E .$ ' #1 HHQVVD\ " # [[] )B./ +c%j89 )* doos #q U- - -  # #s6 E!D?0E!E$E?EE EE%ct|jjdkrd|j_yd|j_i}g}|j |jj |j |jj |D]b}|j|vr0|jD] }||jj|"At|j||j<dt|jjdkDr-|jj||jj<|jjD]}|j|vs|j|vs tt||jt|jz dk(r[tt|j|jjz dk(rd|j_yy)zReturn True if all distro componets are also available as source code. Otherwise return Flase. Special case: If the configuration cannot be represented return Noner FTrN)lenr$source_code_sourcesget_source_codeextend main_sources child_sourcestemplatecompsaddr cdrom_sources cdrom_compssource_template enabled_comps)r5 templatessourcessourcecomps r6get_source_code_statez(SoftwareProperties.get_source_code_states  4;; * *+a/', #'+ # t{{//0t{{001 ?F)+"LL9Dfoo.22489.1-> &//*  ? t{{(( )A -59[[5L5LIdkk11 2kk55 Fi/9,S6??34s6<<7HHIQNV\\*T[[-F-FFG1L.3 +   r8cfd|jfd|jfd|j fd|j ffD]\}}t d|d||j rId|j j fd|j jffD]\}}t d|d|t dy ) z4Print the data of a source entry to the command linezURI:zComps:zEnabled:zValid: z MatchURI:zBaseURI:rwN)urirdisabledinvalidprintr match_uribase_uri)r5rlabelrGs r6print_source_entryz%SoftwareProperties.print_source_entryEs"FJJ/$fll3&FOO(;<$&..&89;) %'( )  +V__-F-FG *FOO,D,DEG -NUE eU+ , - $Kr8ctd|jD]}t|jtdy)zPrint the complete sources.listzSTART SOURCES.LIST:zEND SOURCES.LIST N)rr"rIr5rs r6massive_debug_outputz'SoftwareProperties.massive_debug_outputRs7  "" fjjl r8c~||j_|jj|}|j|S)z! change the main download server )r$default_server change_serverset_modified_sourceslist)r5serverress r6change_main_download_serverz.SoftwareProperties.change_main_download_serverYs3!'DKK ++ # #F +C!!# Jr8cZ|jj||jy)z Enable a component of the distroN)r$enable_componentrr5rs r6rz#SoftwareProperties.enable_component`s KK  &!!#r8cZ|jj||jy)z!Disable a component of the distroN)r$disable_componentrrs r6rz$SoftwareProperties.disable_componentes KK!!$'!!#r8ct|jjjD]}|j|k(s|cSyN)r$rchildrenr)r5rrs r6_find_template_from_stringz-SoftwareProperties._find_template_from_stringjs2KK//88 $ r8c~t|tr|j|}|jjD]-}|j |k(s|j j|/|jjD]-}|j |k(s|j j|/|jy)7Enable a child repo of the distribution main repositoryN) isinstancerIrr$rrr"removerr)r5rrs r6disable_child_sourcez'SoftwareProperties.disable_child_sourceos(C 00:h++++, ??h &    # #F +,++11, ??h &    # #F +, !!#r8ct|tr|j|}|jdk(r|jj }n |j}|jj ||j|jy)rN)rdist) rrIrrr$r add_sourcerr)r5r child_uris r6enable_child_sourcez&SoftwareProperties.enable_child_source|sm(C 00:hD KK.. %% KKyx}}=!!#r8c(g}|j|jj|j|jj|jjD]}|j j ||jy)z%Remove all distro source code sourcesN)rr$rrrr"rrr5rrs r6disable_source_code_sourcesz.SoftwareProperties.disable_source_code_sourcesslG NN4;;++, NN4;;,,-++11( '(!!#r8c Xg}|j|jj|j|jj|jjD]}|j j ||D]i}|j jd|j|j|jd|j j|dz|j|k|jjD]}|j jd|jjj|jjj |jd|j j|dz|j||j#y)z0Enable source code source for all distro sourcesdeb-srczAdded by software-propertiesr )parentN)rr$rrrr"rrrrrindexfilerrrrrrs r6enable_source_code_sourcesz-SoftwareProperties.enable_source_code_sourcess`G NN4;;++, NN4;;,,-++11( '(, Y#ZZ#[[#\\;!--33F;A=#[[$*  ,,++++, Y![[88AA![[88==#\\;!--33F;A=#[[$*  ,, !!#r8cbg|_|jjD]}t|tr"t |j |j }n@t|tr"t|j |j }ntd||jj|y)z+Store a backup of the source.list in memoryrrsectionrUnknown source: N) sourceslist_backupr"listrr rrr TypeErrorr)r5r source_bkps r6r)z%SoftwareProperties.backup_sourceslists D""''3 fk *$&++6;;GJ  1 2*6;;V[[QJ.vh78 8 &&z23r8c~|j|jjD]}t||k(s|cSyr)r(r"rrI)r5rrs r6_find_source_from_stringz+SoftwareProperties._find_source_from_stringsA ""'' V   r8ct|tr|j|}|j |_|j y)z&Enable or disable the selected channelN)rrIrrrrs r6toggle_source_usez$SoftwareProperties.toggle_source_uses8&#,,V4f //)FO!!#r8ct|jjD]\}}t||k(s|jj|j}t |t r$t |||jj|<n#t|||jj|<|jyy)NTF) r;r"rrIrrr r r)r5 old_entry new_entryrentryrs r6replace_source_entryz'SoftwareProperties.replace_source_entrys#D$4$4$9$9: Uy $$U+00 e. /+|jjD]$}|j|k(s|d |jzz }&\|d |zz }e|S)z5Render a nice output to show the source in a treeviewNPrwru[…]zz r z %s)rzrpm-srcz (Source Code)z %szz %sz (%s)z Source CodeF)rcommentrreplacerzrrrrn_r descriptionchild has_component componentsr)r5rrcontentscrs r6 render_sourcez SoftwareProperties.render_sources $ >>!025&&tS1779#2>;= *0&++FH6<< 1$*A )H*{{44EAo$666 + +H' *0V[[AH\\ &EAI% &{{44EAo$666!> uv~~- -H ?? E )  .??006$__77?66T>$(>>H? -H .r8cd}d}d}d}tdd}|jr>d}|jj}|jj|jk(r9d}n6|j d|j d|j}|jrd}|jjdrd}|||||j|fS)z&extract attributes to sort the sourcesr 0123456789 9876543210rrsrc) rrr distributionr$rrrrrnfind translate)r5rcur_sys has_template has_comment is_sourcerevert_numbersdescs r6get_comparablez!SoftwareProperties.get_comparable(sglki |Return a list of sources that are not part of the distribution) r"rrr$rrrdisabled_sourcesrr)r5 isv_sourcesrs r6get_isv_sourcesz"SoftwareProperties.get_isv_sources=sK""'''~~ $++22 2 $++33 3 $++33 3 $++66 6 88 8   v &' r8c.|jjS)z-Return the list of CDROM based distro sources)r$rrWs r6get_cdrom_sourcesz$SoftwareProperties.get_cdrom_sourcesJs ;; $ $$r8cJ|j|jjvdfS)zReturn a tuple: the first value describes if a component is enabled in the Internet repositories. The second value describes if the first value is inconsistent.F)rr$download_compsrs r6get_comp_download_statez*SoftwareProperties.get_comp_download_stateNs" II33 3U ;;r8cg}|jjD]-}|j|k(s|j|j/t |dkDr/t |jj t|z dk(ryt |dkDr/t |jj t|z dk7ryy)zReturn a tuple: the first value describes if a component is enabled in one of the child source that matcth the given template. The second value describes if the first value is inconsistent.r)TF)FT)FF)r$rrrrrrr)r5rrrs r6get_comp_child_statez'SoftwareProperties.get_comp_child_stateUs E**& >>X % LL %& 5zA~ DKK % %E 23q8 Ua DKK % %E 23q8r8c|jjg|_|jj |jyr)r"refreshsourceslist_visibler$ get_sourcesrWs r6r(z%SoftwareProperties.reload_sourceslistjs4DKKD,,-r8c 0|jdz|jdz|jdzg}|D]#}tjj|s#nt dtjj }tjj |s%tj|jdt|dd5}|jd d d d d }tjj |r]tj|tj}|tjzs$t d |ztj|d |D]}g}tjj|s&t|d5}|j!}d d d t"j$j'd}t|d5}|D]A} |j)D]} | j+d| zdk\s0|j| C|j)D])} |jd| d|j-| d+ d d d y #1swYxYw#1swYxYw#1swY)xYw)z+Write the current apt configuration to filez/etc/apt/apt.conf.d/10periodicz#/etc/apt/apt.conf.d/20auto-upgradesz+/etc/apt/apt.conf.d/15adept-periodic-updatezNo config found, creating oneT)parentsrrsrNz/etc/cron.daily/aptz file '%s' not executable, fixingirtz APT::PeriodiczAPT::Periodic::%szAPT::Periodic::z "z"; )rrPrQisfilerdirnamerRpathlibPathmkdirrxrystatST_MODES_IXUSRchmod readlinesrrsubtreerr rE) r5 conffilesrr(acpermperiodiccontentcnfrrrs r6rJzSoftwareProperties.write_configos5>>CCKKMI       +,"g WW^^G $ W##D#1  ! c "a   B ww~~b WWR[ &dT\\! 0256 UHg  ! (C  "AKKM' "nn$$_5(C HA dxxz .#671< ggdm  88: Ha GGQ 1 F G H H HH  " " H Hs+I2I?"0J AJ 2I<?J J cn|jjd|jjy)zQBackup the existing sources.list files and write the current configurationz.saveN)r"backupsaverWs r6rz#SoftwareProperties.save_sourceslists* G$r8ct|}tjj|jrt j d|jzD]}t |5}|D]|}|jjdr#|t|k(s2tjjtjj|dccdddcS dddy#1swYxYw)zs helper that checks if a given line is in the source list return the channel name or None if not found z %s/*.list#rN) r rPrQrR CHANNEL_PATHglobrxrzr{splitextbasename)r5srclinesrcentryfilenamerrs r6_get_channel_from_linez)SoftwareProperties._get_channel_from_lines 7#H ww~~d''(ii d.?.? ?@E( (^ Eq Edzz|&&s+;t,,WW%%bgg&6&6x&@A!DD  E E E E EE   E Es%4C3AC3&C33C< c|jj}|j|}|r$|jd|d}|j |yy)z helper that adds the gpg key of the channel to the apt keyring *if* the channel is in /usr/share/app-install/channels rz.keyTF)r rrDr=add_key)r5shortcutrAchannelkeyps r6&check_and_add_key_for_channel_shortcutz9SoftwareProperties.check_and_add_key_for_channel_shortcutsM ""$))G))'2G --w 7d ll4  r8cy)z) abstract interface to keep the UI alive NrWs r6update_interfacez#SoftwareProperties.update_interfacesr8c|jds|S|jd} |jddd}d|d|jjd|}|S#t$rd}Y.wxYw)z short cut - this: apt-add-repository http://packages.medibuntu.org free non-free same as apt-add-repository 'deb http://packages.medibuntu.org/ '$(lsb_release -cs)' free non-free' httprrr mainzdeb )r{r IndexErrorr$codename)r5rrepoareass r6expand_http_linez#SoftwareProperties.expand_http_linesr ??6 " k ::<?D 3q!!$#DKK$8$8% AD K sA A,+A,cx t|j}|j||S#t$rYywxYw)z* Add a source for the given line. F)rrzradd_source_from_shortcut)r5renable_source_coderGs r6add_source_from_linez'SoftwareProperties.add_source_from_linesA#DJJL1  ( (3E FF $ s - 99c |jj}|j}|j|}|rdnd}||ddz}t||}t||}|js |jry|j |s|j |jj|j|j|j|j|j|j|j|jj||j|j|j|j|j|j|j!|j"rF|j"j$r0ddl} | j)} | j%|jy ) z Add a source with the given shortcut and add the signing key if the site is a known channel or the shortcut implementer adds it. rz # deb-srcrNF)rr architecturesr) sources_listT)r rsourceparts_filerUrrJrFr"rrnrrrrrr[rr raptCache) r5rGrXdeb_linerdebsrc_entry_type debsrc_line new_deb_entrynew_debsrc_entryr^caches r6rWz+SoftwareProperties.add_source_from_shortcuts ##%**H  $ $D$$X.H%7 [#hqrl2K$/M";5 0 8 8   6 6x @++&**&++&,,!.!6!6+00'4'B'B D *)--)..)//!1!9!9.33'7'E'E G !!# || ++  "2"7"7 8 r8cl|rt|tr$|j|}|j|dy|`|j|dt j|}d|_d|_|j|dd|_|j|dyt|tr|j|}|y|jtjjdk7r|jjdr;|jjjtd|jn:|jjjt!d|j |jj#||j'y#t$$rYwxYw) zRemove the given sourceTNFrzDir::Etc::sourcelistz.sourcesr)r)rrIr remove_sourcerrnrrrr find_fileendswithr"rrr r rrr)r5rremove_source_codes r6rgz SoftwareProperties.remove_sourcesp FC ..v6 64(    65)6"  65) 65) &#,,V4f ~ {{gnn../EFF   j ) $$%6r %LM $$[&++%FG  f% !!#    s;F'' F32F3ctjj|sy |jj |}|S#YyxYw)z7Add a gnupg key to the list of trusted software vendorsF)rPrQrRr/r)r5rQrs r6rFzSoftwareProperties.add_key3s= 77>>$ llt$ s ?Actj}|j|jd|j |j |j S)ztj |}|j|}|j}|j }|jd|d|dS)z" Return the PackageKit package id ;) rrPackage current_verver_strarchDepCacheget_candidate_verr)r5 apt_cachepkgcur_ververr}depcache candidates r6get_package_idz!SoftwareProperties.get_package_idTsy c7?? ++ +ooGoo||##I...s3 ~~((C ..r8c0tj|}|j|}g} |jj dD]6}|D]/\}}} |j |dk7s|j ||18 |S#ttf$rgcYSwxYw)zF Get the package dependencies, which can be filtered out by a pattern Depends) rr~rdepends_list_strrir rKeyErrorr) rpackagepatternrr dependenciesdep_listdep_namedep_verdep_ops r6get_dependenciesz#SoftwareProperties.get_dependenciesbs *H**73IL!2266yA =H-5 =)'6==)R/ '' ((;< = =  i  s;B&BBB)NNrF)F)Tr)A__name__ __module__ __qualname__r=rerrangerfRELEASE_UPGRADES_LTSRELEASE_UPGRADES_NEVERrkr7r4r*rKrXr\r_rarqrrrrrrrrrrrrrrr)rrrrrrrZrrrrrr r(rJrrDrJrMrUrYrWrgrFrqrurwr staticmethodrrLr8r6rrDsg2,A  58n heg! '+R -.(%L(&0 2%N  $ $  $ $$$< 3$  (T.* %<*. /Hb  0" G$L)$V" /r8r__main__)/rrhashlibrrrPr>r}r:r2rmr)stringr ImportErrorrIr,r,r-rxml.sax.saxutilsr configparserrrrr#aptsources.distrorBr aptsources.sourceslistr r r "softwareproperties.shortcuthandlerrsoftwareproperties.shortcutsr gi.repositoryrobjectrrsprrqrrLr8r6rs4    (#('!PPG9m m ` z"&&()  #[mm) ('(s4CC C,CC C)(C), C:9C: