o U7e}@sddlmZmZddlZddlZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z zddlmZWn eyFejZYnwddlZzddlZWn ey^ddlZYnwddl mZddlmZzddlmZWneyddlmZYnwddlmZddlZddlZddlZd d lmZdd l m!Z!m"Z"dd l#m$Z$dd l%m&Z&ddl'm(Z(Gddde)Z*e+dkre*Z,e-e,.e,/ddSdS))absolute_importprint_functionN)md5) maketrans)NamedTemporaryFile)escape) ConfigParser)gettext)AptAuth) SourcesList SourceEntry)InvalidShortcutException)shortcut_handler)Gioc@seZdZdZdZeed\ZZZ edede diZ dud d Z d d Z d dZ ddZddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Z d5d6Z!d7d8Z"d9d:Z#d;d<Z$d=d>Z%d?d@Z&dAdBZ'dCdDZ(dEdFZ)dGdHZ*dIdJZ+dKdLZ,dMdNZ-dOdPZ.dQdRZ/dSdTZ0dUdVZ1dWdXZ2dYdZZ3d[d\Z4d]d^Z5d_d`Z6dvdbdcZ7dvdddeZ8dwdgdhZ9didjZ:dkdlZ;dmdnZe?dxdsdtZ@dS)ySoftwarePropertiesz /usr/share/app-install/channels/z$/etc/update-manager/release-upgradesnormalltsneverN/cCs|d|_||_|dkrtjd||dkrd}||_||_t|_t j |_ g|_ d|_ |||g|_t|_t|d|_t|_t|jdS)z Provides the core functionality to configure the used software repositories, the corresponding authentication keys and update automation z/etc/popularity-contest.confrDirNz/usr/share/software-properties/F)rootdir) popconfilerapt_pkgconfigsetoptionsdatadirr sourceslist aptsourcesdistro get_distro seen_servermodified_sourceslistreload_sourceslistbackup_sourceslistbackup_apt_confcustom_mirrorsqueueQueuemyqueuer apt_keyr Cancellable cancellableatexitregisterwait_for_threads)selfrrrr3G/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py__init__Xs(     zSoftwareProperties.__init__cCs*tD]}|jtjkr|qdS)z9 wait for all running threads (PPA key fetchers) to exit N) threading enumerateidentcurrent_threadjoin)r2tr3r3r4r1s z#SoftwareProperties.wait_for_threadscCs6i|_tjD]}tjtj|}||j|<qdS)z$Backup all apt configuration optionsN)apt_conf_backupsoftwarepropertiesCONF_MAPkeysrrfind_i)r2optionvaluer3r3r4r's  z"SoftwareProperties.backup_apt_confcCs:|jD]}tjtj|t|j|q|dS)z$Restore the stored apt configurationN) r<r?rrrr=r>str write_config)r2rAr3r3r4restore_apt_confs   z#SoftwareProperties.restore_apt_confcCstjtjddkrStjtjddkrtjdrtjStjtjddkr8tjtjddkr8tj StjtjddkrQtjtjddkrQtj SdStjtjddkrltjtjddkrltj SdS)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) rrr@r=r>ospathexistsUPDATE_INST_SECUPDATE_DOWNLOAD UPDATE_NOTIFY UPDATE_MANUALr2r3r3r4get_update_automation_levels  z.SoftwareProperties.get_update_automation_levelcCs|tjkrtjtjdtdtjtjdtdn`|tjkrrCrMrNset_modified_config)r2stater3r3r4set_update_automation_levels    z.SoftwareProperties.set_update_automation_levelcCs>|tjtjdkstjtjdt||dSdS)z8Set the interval in which we check for available updatesrFN)rrr@r=r>rrCrR)r2daysr3r3r4set_update_intervals z&SoftwareProperties.set_update_intervalcCstjtjdS)z3 Returns the interval of the apt periodic cron job rF)rrr@r=r>rPr3r3r4get_update_intervalsz&SoftwareProperties.get_update_intervalcCsltj|js |jSt}||j|ddr3|dd }|j D] \}}||kr2|Sq&|jS)z return the release upgrade policy: RELEASE_UPGRADES_NORMAL, RELEASE_UPGRADES_LTS, RELEASE_UPGRADES_NEVER DEFAULTPrompt) rIrJrKRELEASE_UPGRADES_CONFRELEASE_UPGRADES_NORMALrread has_optiongetlowerrelease_upgrades_policy_mapitems)r2parsertypekvr3r3r4get_release_upgrades_policys  z.SoftwareProperties.get_release_upgrades_policyc Cs,tj|js*t|jd}|d|j|WddS1s#wYdSt|jd\}tdd>}|D]}|}| drQ|d |j|q9||d q9| t |j|jt |j|jWdn1swwYWddSWddS1swYdS) z set the release upgrade policy: RELEASE_UPGRADES_NORMAL, RELEASE_UPGRADES_LTS, RELEASE_UPGRADES_NEVER wz[DEFAULT] Prompt=%s NTrzw+)modepromptz Prompt=%s  )rIrJrKrZopenwriter`rstripr_ startswithflushshutilcopymodenamecopy)r2ifoutliner3r3r4set_release_upgrades_policys, (   z.SoftwareProperties.set_release_upgrades_policyc Cstj|jrKt|j}|d}Wdn1swY|D]%}z|d\}}|dkr@|ddkr@WdSWq%t yJYq%wdS) 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 rkN= PARTICIPATE"yesTF) rIrJrKrrlr\splitrnr_ ValueError)r2rvlinesrxkeyrBr3r3r4get_popcon_participations  z+SoftwareProperties.get_popcon_participationcs|dkrdndtj|jr0t|jd}fdd|D}Wdn1s*wYn;t}tdd }||d Wdn1sKwY|}g}| d || d t | d t|jd}| |WddS1swYdS)z? Enable or disable the participation in the popularity contest Tr}norhcsg|] }tdd|qS)z^(PARTICIPATE=)(".+?")z\1"%s")resub).0rxrBr3r4 sz@SoftwareProperties.set_popcon_pariticipation..Nz /dev/urandomrbizMY_HOSTID="%s" zPARTICIPATE="%s" zUSE_HTTP="yes" rg) rIrJrKrrlrupdater\ hexdigestappendrC writelines)r2 is_helpfulrrmrvidr3rr4set_popcon_pariticipations,    "z,SoftwareProperties.set_popcon_pariticipationcCst|jjdkrd|j_dSd|j_i}g}||jj||jj|D]}|j|vr<|jD] }||j |q0q&t |j||j<q&t|jj dkrU|jj ||jj <|jjD]0}|j|vs|j|vrtt ||jt |jAdkstt |j|jjAdksd|j_dSqYdS)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)r2 templatessourcessourcecompr3r3r4get_source_code_states2      z(SoftwareProperties.get_source_code_statecCsd|jfd|jfd|j fd|j ffD] \}}td||fq|jr=d|jjfd|jjffD] \}}td||fq0tdd S) z4Print the data of a source entry to the command linezURI:zComps:zEnabled:zValid:z %s %sz MatchURI:zBaseURI:rkN)urirdisabledinvalidprintr match_uribase_uri)r2rlabelrBr3r3r4print_source_entryFs       z%SoftwareProperties.print_source_entrycCs,td|jD]}t|qtddS)zPrint the complete sources.listzSTART SOURCES.LIST:zEND SOURCES.LIST N)rrrCr2rr3r3r4massive_debug_outputSs  z'SoftwareProperties.massive_debug_outputcCs ||j_|j|}||S)z! change the main download server )r!default_server change_serverset_modified_sourceslist)r2serverresr3r3r4change_main_download_serverZs z.SoftwareProperties.change_main_download_servercC|j||dS)z Enable a component of the distroN)r!enable_componentrr2rr3r3r4ra  z#SoftwareProperties.enable_componentcCr)z!Disable a component of the distroN)r!disable_componentrrr3r3r4rfrz$SoftwareProperties.disable_componentcCs&|jjjD] }|j|kr|SqdSN)r!rchildrenrs)r2rsrr3r3r4_find_template_from_stringks  z-SoftwareProperties._find_template_from_stringcCsht|tr ||}|jjD] }|j|kr|j|q|jjD] }|j|kr-|j|q | dS)7Enable a child repo of the distribution main repositoryN) isinstancerCrr!rrrremoverr)r2rrr3r3r4disable_child_sourceps         z'SoftwareProperties.disable_child_sourcecCsLt|tr ||}|jdkr|jj}n|j}|jj||jd|dS)rN)rdist) rrCrrr!r add_sourcersr)r2r child_urir3r3r4enable_child_source}s     z&SoftwareProperties.enable_child_sourcecCsFg}||jj||jj|jjD]}|j|q|dS)z%Remove all distro source code sourcesN)rr!rrrrrrr2rrr3r3r4disable_source_code_sourcess   z.SoftwareProperties.disable_source_code_sourcesc Csg}||jj||jj|jjD]}|j|q|D]}|jd|j|j |j d|jj |d|j q|jjD]}|jd|jjj|jjj|j d|jj |d|j q=|dS)z0Enable source code source for all distro sourcesdeb-srczAdded by software-propertiesr N)rr!rrrrrrrrrlistindexfilerrrrsrrr3r3r4enable_source_code_sourcess0   z-SoftwareProperties.enable_source_code_sourcescCs4g|_|jjD]}t|j|jd}|j|qdS)z+Store a backup of the source.list in memoryrxrN)sourceslist_backuprrr rxrr)r2r source_bkpr3r3r4r&s  z%SoftwareProperties.backup_sourceslistcCs.||jjD] }t||kr|SqdSr)r%rrrC)r2rxrr3r3r4_find_source_from_strings   z+SoftwareProperties._find_source_from_stringcCs*t|tr ||}|j |_|dS)z&Enable or disable the selected channelN)rrCrrrrr3r3r4toggle_source_uses    z$SoftwareProperties.toggle_source_usecCsTt|jjD]!\}}t||kr'|jj|j}t|||jj|<|dSqdS)NTF)r7rrrCrr r)r2 old_entry new_entryrentryrr3r3r4replace_source_entrys z'SoftwareProperties.replace_source_entrycCs||dS)zNRevert all settings to the state when software-properties was launchedN)rErevert_sourceslistrPr3r3r4reverts zSoftwareProperties.revertcCsFg|j_|jD]}t|j|jd}|jj|q||dS)z6Restore the source list from the startup of the dialogrN) rrrr rxrrsave_sourceslistr%)r2r source_resetr3r3r4rs   z%SoftwareProperties.revert_sourceslistcCs0d|_|jr|jjr|||dS)zCThe sources list was changed and now needs to be saved and reloadedTN)r$r massive_debugrrr%rPr3r3r4rs  z+SoftwareProperties.set_modified_sourceslistcCs |dS)z+Write the changed apt configuration to fileN)rDrPr3r3r4rRs z&SoftwareProperties.set_modified_configcCsV|jdkr`|jr=dt|j|jf}t|jdkr'|jD]}|d|7}q|jdvr4|dtd7}|d|j 7}|Sd|j |jf}|jD]}|d|7}qH|jdvr^|dtd7}|Sd |jj }|jdvrs|d td 7}|jr}|d|j7}|jj d kr|jD]"}|j |r|jj D]}|j|kr|d|j 7}qq|d|7}q|S) z5Render a nice output to show the source in a treeviewNz %s %sr z %s)rzrpm-srcz (Source Code)z %sz %s %sz %sz (%s)z Source CodeF)rcommentrrnrrrrc_r descriptionchild has_component componentsrs)r2rcontentscrr3r3r4 render_sourcesB            z SoftwareProperties.render_sourcecCsd}d}d}d}tdd}|jr d}|jj}|jj|jkrd}nd|j|j|jf}|jr/d}|j dr7d}||||| |fS)z&extract attributes to sort the sourcesr 0123456789 9876543210rz%s %s %ssrc) rrr distributionr!rrrrrcfind translate)r2rcur_sys has_template has_comment is_sourcerevert_numbersdescr3r3r4get_comparables&  z!SoftwareProperties.get_comparablecCsbg}|jjD](}|js.||jjvr.||jjvr.||jjvr.||jjvr.||jjvr.| |q|S)z>Return a list of sources that are not part of the distribution) rrrr!rrrdisabled_sourcesrr)r2 isv_sourcesrr3r3r4get_isv_sources,s       z"SoftwareProperties.get_isv_sourcescCs|jjS)z-Return the list of CDROM based distro sources)r!rrPr3r3r4get_cdrom_sources9sz$SoftwareProperties.get_cdrom_sourcescCs|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)rsr!download_compsrr3r3r4get_comp_download_state=sz*SoftwareProperties.get_comp_download_statecCs|g}|jjD] }|j|kr||jqt|dkr(t|jjt|Adkr(dSt|dkrs  z!SoftwareProperties.get_package_idc Csxt|}||}g}z"|jdD]}|D]\}}} ||dkr*|||qqW|Sttfy;gYSw)zF Get the package dependencies, which can be filtered out by a pattern Depends) rr>r?depends_list_strr^rrKeyError TypeError) r@packagepatternrDrE dependenciesdep_listdep_namedep_verdep_opr3r3r4get_dependenciesLs  z#SoftwareProperties.get_dependencies)NNr)F)Tr)A__name__ __module__ __qualname__r rZrranger[RELEASE_UPGRADES_LTSRELEASE_UPGRADES_NEVERr`r5r1r'rErQrTrVrWrfryrrrrrrrrrrrrrr&rrrrrrrRrrrrrrr%rDrrrrrr"r r.rr5r8r9rF staticmethodrSr3r3r3r4rEs  )'      ' .  &( r__main__)0 __future__rrrrthashlibrrrIr rqr6r/r1stringr ImportErrorrCrr)r*rxml.sax.saxutilsr configparserrr rr aptsources.distror=r aptsources.sourceslistr r "softwareproperties.shortcuthandlerrsoftwareproperties.shortcutsr gi.repositoryrobjectrrTsprrfryr3r3r3r4sd