
{_p                @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l m Z d  d l m Z d d l m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z d  d l m Z d d l m Z m Z m  Z  m! Z! m" Z" m# Z# d d	 l$ m% Z% d d
 l& m' Z' d d l( m( Z( d d l) m* Z* d d l+ m, Z, m- Z- d d l. m/ Z/ d d l. m0 Z0 e/ j1 e0 _1 d d l0 m2 Z2 m3 Z3 d d l4 m5 Z5 m6 Z6 d d l7 m8 Z9 d d l7 m: Z: d  d l8 Z8 d d l$ m; Z; m< Z< m= Z= d d l> m? Z? d Z@ d d   ZA Gd d   d eB  ZC Gd d   d eD  ZE eF d k rd d lG mG ZG e jH d e jI  eG   ZJ eE eJ  ZK eK jL   eK jM   d S)     N)NoOptionError)ConfigParser   )	country_mirrorurl_downloadablecheck_and_fix_xbitget_archiptables_activeinside_chroot)get_string_with_no_auth_from_source_entryis_child_of_process_nameinhibit_sleep)Template)urlsplit)STEP_PREPARESTEP_MODIFY_SOURCES
STEP_FETCHSTEP_INSTALLSTEP_CLEANUPSTEP_REBOOT)MyCache)DistUpgradeConfig)DistUpgradeQuirks)AptCdrom)	setupAufsaufsOptionsAndEnvironmentSetup)distinfo)sourceslist)SourcesList	is_mirror)
get_distroNoDistroTemplateException)gettext)ngettext)CacheExceptionDpkgInterruptedCacheExceptionLockingFailedNotEnoughFreeSpaceError)
run_apportz/var/run/reboot-requiredc             C   sJ   d d d d g } y | j  |   SWn  t k
 rE t |  d SYn Xd S)zB key() function for sorted to ensure "correct" component ordering main
restrictedZuniverseZ
multiverser   N)index
ValueErrorlen)aZordering r.   C/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeController.pycomponent_ordering_keyU   s
    r0   c               @   s   e  Z d  Z d S)NoBackportsFoundExceptionN)__name__
__module____qualname__r.   r.   r.   r/   r1   `   s   r1   c               @   s  e  Z d  Z d Z d d d d  Z d d d d  Z d	 d
   Z d d   Z d d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d d  Z d d   Z d d   Z d d   Z d d d d   Z d! d"   Z d# d$   Z d% d&   Z d' d(   Z d) d*   Z d+ d,   Z d- d.   Z d/ d0   Z d1 d2   Z d3 d4   Z d5 d6   Z d7 d8   Z d9 d:   Z d; d<   Z d= d>   Z  d? d@   Z! dA dB   Z" d dC dD  Z# d dE dF  Z$ dG dH   Z% dI dJ   Z& dK dL   Z' dM dN   Z( dO dP   Z) d S)QDistUpgradeControllerz3 this is the controller that does most of the work Nc             C   s  d } | d  k s | d k r? t  j   } t  j j | d  } | |  _ | |  _ t j d |  t j d  t	 j
 d | j j  | |  _ |  j j t d   d  |  _ |  j s |  j j d  k r d |  _ n |  j j |  _ | r | j } n d  } t | |  |  _ t |  |  _ d |  j j d d	  |  _ |  j j d
  |  j j d
 d t |  j   t |  j |  j  |  j j d d  |  _ |  j j d d  |  _ |  j j d d  |  _  t!   |  _" d t  j# k rt	 j
 d  t$ j j d d  d |  _% t& |  |  j  |  _' t(   |  _) d t  j# d <d t  j# d <d t  j   d t  j# d f t  j# d <t* d  |  j j+ d d  } t$ j j d t |   t$ j j d t d0   t$ j j d" t d1   t$ j j d$ d%  t$ j j d& d%  t$ j j d' d(  |  j j, d) d*  |  _- |  j j. d d+  |  _/ g  |  _0 |  j j1 d,  rzd- d.   |  j j2 d,  D |  _0 d/ |  _3 d  S)2Nz/usr/share/locale/.Zmozubuntu-release-upgraderzUsing '%s' viewzReading cacheTZFilesZ	BackupExtOptionswithNetworkSourcesZFromZToZValidOriginZ"RELEASE_UPGRADE_NO_FORCE_OVERWRITEzenable dpkg --force-overwritezDPkg::Options::z--force-overwriteF1ZRELEASE_UPGRADE_IN_PROGRESSZPYCENTRAL_FORCE_OVERWRITEz%s:%sz	/importedPATHz./imported/invoke-rc.dNetwork
MaxRetrieszAcquire::RetrieszDpkg::MaxArgs@   i   zDpkg::MaxArgBytes   zAcquire::http::TimeoutZ20zAcquire::ftp::TimeoutzApt::Get::List-CleanupfalseDistroForcedObsoletesZValidMirrorsZThirdPartyMirrorsc             S   s   g  |  ] } | d   q S)r   r.   ).0Zpairr.   r.   r/   
<listcomp>   s   	 z2DistUpgradeController.__init__.<locals>.<listcomp>i  i   i   )4osgetcwdpathjoindatadiroptionsr"   bindtextdomain
textdomainloggingdebug	__class__r2   _viewupdateStatus_cacher8   
useNetworkZ	cdromPathr   aptcdromr   configgetsources_backup_extZadd_sectionsetstrr   fromDisttoDistoriginr   archenvironapt_pkg_partialUpgrader   quirksr   Zinhibitor_fdr   getintgetlistforced_obsoletesZgetListFromFilevalid_mirrorsvalid_3p_mirrorshas_sectionitems_aptCronJobPerms)selfZdistUpgradeViewrJ   rI   Z	localedir	cdrompath
maxRetriesr.   r.   r/   __init__g   sj    					
		zDistUpgradeController.__init__TFc             C   s*  t  j d  |  j d  k r/ |  j j d  n |  j j   |  j j   d } d } x y |  j |  SWqX t k
 r!} z | d 7} |  j	 j
   t j d  t  j d |  | | k rt  j d |  |  j	 j t d	  t d
   | r|  j   n t j d  WYd  d  } ~ XqX XqX Wd  S)NzopenCache()ZPreCacheOpen   r   r   g?z'failed to lock the cache, retrying (%i)zCache can not be locked (%s)zUnable to get exclusive lockzThis usually means that another package management application (like apt-get or aptitude) already running. Please close that application first.)rM   rN   rS   rb   runrelease_lockunlock_lists_dir
_openCacher%   rP   processEventstimesleeperrorrR   abortsysexit)rk   lockrestore_sources_list_on_failZMAX_LOCK_RETRIESZ
lock_retryer.   r.   r/   	openCache   s.    
zDistUpgradeController.openCachec             C   s   y= t  |  j |  j |  j |  j j   |  |  _ |  j |  _ Wn t k
 r t j	 d  d d d g } t
 j j d  d k r | j d  |  j j   j |  t  |  j |  j |  j |  j j    |  _ Yn X|  j |  j _ t j d t |  j   d  S)	Nz-dpkg interrupted, calling dpkg --configure -az/usr/bin/dpkgz--configurez-aDEBIAN_FRONTENDnoninteractivez--force-confoldz/openCache(), new cache size %i)r   rV   rP   rb   getOpCacheProgressrS   Z	apt_cacher$   rM   warningrE   r_   rW   appendgetTerminalcallra   ZpartialUpgraderN   r,   )rk   r{   cmdr.   r.   r/   rs      s&    		z DistUpgradeController._openCachec             C   s2   |  j  j d d  } |  j j j | k r. d Sd S)z
      Returns True if this view support upgrades over ssh.
      In theory all views should support it, but for savety
      we do only allow text ssh upgrades (see LP: #322482)
      ViewZ
SupportSSHTF)rV   rd   rP   rO   r2   )rk   Z	supportedr.   r.   r/   _viewSupportsSSH  s    z&DistUpgradeController._viewSupportsSSHc             C   s^  t  j j d  } t  j j |  rZt  j j d  rZt d  rZ|  j   s t j d  |  j	 j t
 d  t
 d   t j d  d Sd	 } |  j	 j t
 d
  t
 d  |  } | d k r t j d  t j d d d | d t |  g  } | d k rZt
 d  } t
 d  | } t   rGd | } | t
 d  | 7} |  j	 j | |  d S)z this will check for server mode and if we run over ssh.
            if this is the case, we will ask and spawn a additional
            daemon (to be sure we have a spare one around in case
            of trouble)
        z"/var/run/release-upgrader-sshd.pidz/procZsshdzupgrade over ssh not allowedz.Upgrading over remote connection not supportedzYou are running the upgrade over a remote ssh connection with a frontend that does not support this. Please try a text mode upgrade with 'do-release-upgrade'.

The upgrade will abort now. Please try without ssh.r   Fi  zContinue running under SSH?a  This session appears to be running under ssh. It is not recommended to perform a upgrade over ssh currently because in case of failure it is harder to recover.

If you continue, an additional ssh daemon will be started at port '%s'.
Do you want to continue?z/usr/sbin/sshdz-oz
PidFile=%sz-pr   zStarting additional sshdzTo make recovery in case of failure easier, an additional sshd will be started on port '%s'. If anything goes wrong with the running ssh you can still connect to the additional one.
z-iptables -I INPUT -p tcp --dport %s -j ACCEPTzIf you run a firewall, you may need to temporarily open this port. As this is potentially dangerous it's not done automatically. You can open the port with e.g.:
'%s'T)rE   rG   rH   existsisdirr   r   rM   rw   rP   rR   ry   rz   askYesNoQuestion
subprocessr   rZ   r	   information)rk   ZpidfileZportressummaryZdescrr   r.   r.   r/   	_sshMagic  s>    				
	
		
zDistUpgradeController._sshMagicc          	   C   s  d d l  m } d d l m } d } |  j d k sb |  j d k sb |  j d k sb |  j d k rh d	 } | d
 d d |  } |  j j   x# | j j d  s |  j j   q W| j d k r t	 j
 d  d S|  j j   } | d | j d | d |  j d |  j  } | j   d S)z this is a helper that is run if we are started from a CD
            and we have network - we will then try to fetch a update
            of ourself
        r   )MetaReleaseCore)DistUpgradeFetcherSelfFZdapperZhardyZlucidZpreciseTZuseDevelopmentReleaseforceLTSg?NzNo new dist foundnew_distprogressrJ   Zview)ZMetaReleaser   r   releaserP   rt   Z
downloadedwaitr   rM   rw   getAcquireProgressrJ   rp   )rk   r   r   r   mr   fetcherr.   r.   r/   _tryUpdateSelfK  s,    		z$DistUpgradeController._tryUpdateSelfc          $   C   s-  t  j d  t j j d  r)t   } t d   } | j |  Wd QRXy | j d d  } Wn' t	 k
 r t  j d |  d SYn Xy t j
 d  } Wn: t k
 r } z t  j d	 |  d SWYd d } ~ Xn X| | t j j d
 |  f k r)t  j d | | t j j d
 |  f  d Sd S)z sanity check that /usr/bin/python points to the default
            python version. Users tend to modify this symlink, which
            breaks stuff in obscure ways (Ubuntu #75557).
        z_pythonSymlinkCheck runz!/usr/share/python/debian_defaultsNZDEFAULTzdefault-versionz+no default version for python found in '%s'Fz/usr/bin/pythonzos.readlink failed (%s)z/usr/binz<python symlink points to: '%s', but expected is '%s' or '%s'T)rM   rN   rE   rG   r   SafeConfigParseropenZreadfprW   r   readlinkOSErrorrw   rH   )rk   rV   fZexpected_defaultZfs_default_versionr}   r.   r.   r/   _pythonSymlinkCheckj  s&    		!)z)DistUpgradeController._pythonSymlinkCheckc       	      C   so  t  j d d d g d t  j d d j   d j   |  _ } t j d |  | |  j k pj | |  j	 k s t j
 d	 | |  j f  |  j j
 t d
  t d | |  j	 f   t j d  |  j j d d d  rY|  j j d d  } t |  s)t j
 d  |  j j
 t d  t d   d St j d  |  j j t d  t d  |  |  j rG|  j j rGt j   d } t j d |  t j d t j | d   t j j | d  rt j j d | d  t j j | d  rt j j d | d  | d } t j j |  rGt j d  |  t j t j |  |  j   |  j    st j
 d!  |  j j
 t d
  t d"   t j d  y |  j!   Wn: t" k
 r} z t j
 d# |  d SWYd$ d$ } ~ Xn X|  j# j$ |  j  sd S|  j# j%   |  _& |  j& r%d% t j' d& <n d' t j' d& <|  j(   sOt j
 d(  d Sd d) l) m* } xx | D]p } t j j |  rft j+ | t j,  rft j
 d* |  |  j j
 t d+  | t d,  |  |  j-   qfW|  j. rk|  j rk|  j j/ d$ k rk|  j j0 t d-  t d.  d/  } | |  _1 |  j j d0 d1 t2 |  j1   t j d2 |  | rk|  j3   d S)3z: initial cache opening, sanity checking, network checking Zlsb_releasez-cz-sstdoutuniversal_newlinesTr   zlsb-release: '%s'zBad upgrade: '%s' != '%s' zCan not upgradez=An upgrade from '%s' to '%s' is not supported with this tool.r   ZAufsZEnableFullOverlayFZRWDirzaufs setup failedzSandbox setup failedz6It was not possible to create the sandbox environment.zrunning in aufs overlay modezSandbox modezThis upgrade is running in sandbox (test) mode. All changes are written to '%s' and will be lost on the next reboot.

*No* changes written to a system directory from now until the next reboot are permanent.z
/backportszusing backports in '%s' zhave: %sz/*.udebz/usr/bin/dpkgzDir::Bin::dpkgz/usr/lib/apt/methodszDir::Bin::methodsz/etc/apt/apt.conf.d/01ubuntuzadding config '%s'z%pythonSymlinkCheck() failed, abortingzKYour python install is corrupted. Please fix the '/usr/bin/python' symlink.zopenCache() failed: '%s'NZserverZRELEASE_UPGRADE_MODEZdesktopzcheckViewDepends() failed)SYSTEM_DIRSz%s not writablezCan not write to '%s'zIts not possible to write to the system directory '%s' on your system. The upgrade can not continue.
Please make sure that the system directory is writable.z)Include latest updates from the Internet?a  The upgrade system can use the internet to automatically download the latest updates and install them during the upgrade.  If you have a network connection this is highly recommended.

The upgrade will take longer, but when it is complete, your system will be fully up to date.  You can choose not to do this, but you should install the latest updates soon after upgrading.
If you answer 'no' here, the network is not used at all.ZYesr7   r8   z#useNetwork: '%s' (selected by user))4r   PopenPIPEcommunicatestripr   rM   rN   r[   r\   rw   rP   rR   ry   rz   rV   getWithDefaultrW   r   infor   rJ   havePrerequistsrE   rF   globrG   r   r`   rY   Zread_config_filer   r   r~   SystemErrorrS   Zsanity_checkneed_server_mode
serverModer_   checkViewDependsZDistUpgradeMainr   accessW_OKrx   rU   r8   r   rT   rZ   r   )	rk   r   Zaufs_rw_dirbackportsdirconfr}   r   Z	systemdirr   r.   r.   r/   prepare  s    	 	

	(		$			
zDistUpgradeController.preparec             C   sQ   t  j d |  |  j s+ t  j d  d Sd | j | j f } t | t  j  S)zf
        helper that checks if a sources.list entry points to 
        something downloadable
        zverifySourcesListEntry: %sz(skipping downloadable check (no network)Tz%s/dists/%s/Release)rM   rN   rT   uridistr   )rk   entryr   r.   r.   r/   _sourcesListEntryDownloadable  s    	z3DistUpgradeController._sourcesListEntryDownloadablec                s,  | r t  j d  n t  j d    j j d d  }   j j d d d  s_ d t j k rr t  j d  d } d } | d	 k rm  j rmt  j   j j d
 d   x  j j d
 d  D]} t  j d |  |   j	 k sd  j	 | j
 sdt   j	 | j
 j  d k sd  j	 | j
 r t   j	 | j
 j  d k r   j	 | j
 j d j d k r t  j d |  y0 t   } | j   j  | j d  d	 } Wn t k
 rg} z t  j d |  t  j d  d } d d g } d }	   j j d |	   j | |    j j d |	   j d | |    j j d d   j d | |  WYd  d  } ~ Xn XPq W  j j d d  }
   j g   f d d   |
 D }   j g   f d d   |
 D } d   _ g  } xg   j j d  d   D]O } d | j k rq| j j d   rq| j j d!  r0q| j |  qW|   j _ d } i    _ x  j j d  d   D]} | j ss| j rqs| j j d"  r| j    j k rt  j d# |  d	 | _ qsnu | j j d"  rGt! j j" d$  } t j# j$ d% | t! j% | j  d& | j  d' f  sst  j d( |  d	 | _ qsd)   j } | j r| j j d*  r| j  | k r  j | _  d+ g | _& t  j d, |  qs| j r| j j d-   j  rt  j d.  d	 | _ qs| j rg  j' rg  j' j( d	 k rgd/   j | j  k rgt  j d0  d/   j | _  | j) t* d1    j 7_) d	 | _ qs| j rd2 | j k rt  j d3  xi d4 t+   d g D]T }	 t, j, |  } |	 | _   j | _    j- |  rt  j. d5 |	  |	 | _ PqWt  j d6 t/ |     j0 | j  } | p8  j1 | j  } | sG| rxd	 } | j s| j2 d7 k sd8 | j k sd9   j | j  k sd:   j | j  k sd; | j k rd } | j  | k rt  j d< t/ |   | | O} n | j  | k r4| | O} | | j3 | j   | _  t  j d= t/ |   nD | j2 d7 k rIqsn/ | rxd	 | _ d	   _ t  j d> t/ |   | j2 d k rd? | j k r  j4 d@ k s  j4 dA k rt  j dB   j4  dC | _ xZdD   j dE   j d9   j g D]{ }   j j5 | t6    | j r| j  | k r| j2 d k rx4 | j& D]) } | | k rYqD  j | j |  qDWqWqs| j    j k r  j | _  dF t* dG    j } t7 | j) t8  r| j) | j9 dH  7_) n | j) | 7_) d	 | _ d	   _ t  j dI t/ |   | rs| j  | k r@	| | j3 | j   | _  x dD   j dE   j d9   j g D]q }   j j5 | t6    | j  | k re	| j2 d k re	x4 | j& D]) } | | k r	q	  j | j |  q	Wqe	Wt  j dJ | j2 | j  | j& f  d }	 d }   j j | j2 |	 | j  | j& |  qsWx   j j d  d   D] } | j sI
| j sI
| j2 d7 k sI
| j j d"  sI
| j    j k r
qI
| j    j k rI
  j   j   j | j  } | rI
t  j. dK t/ |   | j& j: t; | dL t<  t  j. dM t/ |     j | j  =qI
W| S)NNz&rewriteSourcesList() with mirror_checkzrewriteSourcesList()r9   Z
ComponentsZAllowThirdPartyFZ"RELEASE_UPGRADER_ALLOW_THIRD_PARTYz,mirror check skipped, *overriden* via configTrA   BaseMetaPkgszChecking pkg: %sr   r   Znowz)BaseMetaPkg '%s' has no candidate.originsr(   z$NoDistroTemplateException raised: %sz]get_distro().enable_component("main") failed, overwriting sources.list instead as last resortz* auto generated by ubuntu-release-upgraderr)   z http://archive.ubuntu.com/ubuntudebz-updatesz!http://security.ubuntu.com/ubuntuz	-securityZPocketsc                s#   g  |  ] } d    j  | f  q S)z%s-%s)r[   )rC   x)rk   r.   r/   rD   E  s   	z<DistUpgradeController.rewriteSourcesList.<locals>.<listcomp>c                s#   g  |  ] } d    j  | f  q S)z%s-%s)r\   )rC   r   )rk   r.   r/   rD   G  s   	z/extras.ubuntu.comzE## This software is not part of Ubuntu, but is offered by third-partyz5## developers who want to ship their latest software.zcdrom:z,disabled '%s' cdrom entry (dist == fromDist)zDir::State::listsz%s/%s%s_%s_%sZdistsZReleasez:disabling cdrom source '%s' because it has no Release filez%s-commercialzhttp://archive.canonical.comZpartnerz transitioned commercial to '%s' z*http://landscape.canonical.com/packages/%sz&commenting landscape.canonical.com outz%s-proposedz2upgrade to development release, disabling proposedz5Not for humans during development stage of release %szold-releases.ubuntu.com/z-upgrade from old-releases.ubuntu.com detectedz"http://%sarchive.ubuntu.com/ubuntuz%transition from old-release.u.c to %szexamining: '%s'zdeb-srcz/security.ubuntu.comz%s-securityz%s-backportsz/archive.canonical.comz%entry '%s' is already set to new distzentry '%s' updated to new distz&entry '%s' was disabled (unknown dist)zports.ubuntu.comZpowerpcZsparcz-moving %s source entry to 'ports.ubuntu.com' z%http://ports.ubuntu.com/ubuntu-ports/z%sz
%s-updates zdisabled on upgrade to %szUTF-8z(entry '%s' was disabled (unknown mirror)zAdding entry: %s %s %sz)fixing components inconsistency from '%s'keyzto new entry '%s')=rM   rN   rV   rd   r   rE   r_   r   rT   rS   	candidater,   originsarchiver    Zget_sourcessourcesZenable_componentr!   	exceptionaddr\   r[   sources_disabledlistr   line
startswithr   found_componentsinvaliddisabledr   r`   find_dirrG   r   Zuri_to_filenamecompsrJ   Zdevel_releasecommentrR   r   copyr   r   r   isMirrorisThirdPartyMirrortyper*   r^   
setdefaultrY   
isinstancebytesencodeextendsortedr0   )rk   mirror_checkZsync_componentsZmain_was_missingpkgnamedistror}   r   r   r   ZpocketsZ	fromDistsZtoDistsZnew_listr   ZfoundToDistlistdirZcdistZ
test_entryZvalidMirrorZthirdPartyMirrorZvalidTodcompZdisable_commentZcomponent_diffr.   )rk   r/   rewriteSourcesList  sz    	

						$		

		
			
			
		
#)!$	z(DistUpgradeController.rewriteSourcesListc             C   sq  t  j d  t d d  |  _ |  j j |  j  |  j d d  st  j d  |  j j	 t
 d  t
 d  |  j |  j f  } | r{t d d  |  _ |  j d d  r|  j rt
 d	  } t
 d
  |  j |  j f } |  j j	 | |  s |  j   t  j d  d } d d g } |  j j d | |  j |  |  j j d | |  j d |  |  j j d d |  j d |  n
 |  j   |  j j   y t j   } | j   Wn t k
 rDt  j d  t j j d  r|  j j t
 d  t
 d   t j d d g  n, |  j j t
 d  t
 d   t  j d  d SYn X|  j rm|  j j t
 d  t
 d   d S)NzupdateSourcesList()matcherPathr6   r   TzNo valid mirror foundaW  While scanning your repository information no mirror entry for the upgrade was found. This can happen if you run an internal mirror or if the mirror information is out of date.

Do you want to rewrite your 'sources.list' file anyway? If you choose 'Yes' here it will update all '%s' to '%s' entries.
If you select 'No' the upgrade will cancel.FzGenerate default sources?zAfter scanning your 'sources.list' no valid entry for '%s' was found.

Should default entries for '%s' be added? If you select 'No', the upgrade will cancel.z"Generated new default sources.listz http://archive.ubuntu.com/ubuntur(   r)   r   z-updatesz"http://security.ubuntu.com/ubuntu/z	-securityz<Repository information invalid after updating (we broke it!)z/usr/bin/apport-bugzRepository information invalidzlUpgrading the repository information resulted in a invalid file so a bug reporting process is being started.z
apport-bugzubuntu-release-upgrader-corezUpgrading the repository information resulted in a invalid file. To report a bug install apport and then execute 'apport-bug ubuntu-release-upgrader'.z.Missing apport-bug, bug report not autocreatedzThird party sources disabledzSome third party entries in your sources.list were disabled. You can re-enable them after the upgrade with the 'software-properties' tool or your package manager.)rM   rN   r   r   ZbackuprX   r   rw   rP   r   rR   r[   r\   rT   rx   r   r   Zsaver`   Z
SourceListread_main_listr   rE   rG   r   r   r   r   r   )rk   r   ZprimZseconr   r   r   r.   r.   r/   updateSourcesList  sX    			
 
		z'DistUpgradeController.updateSourcesListc             C   s`  t  j d  g  } g  } g  } g  } g  } x |  j D] } | j rW | j | j  q5 | j rs | j | j  q5 | j r | j | j  q5 | j r | j	 r | j | j  q5 | j r5 | j
 r5 | j | j  q5 Wt  j d d j |   t  j d d j |   t  j d d j |   t  j d d j |   t  j d d j |   d  S)Nz$About to apply the following changeszKeep at same version: %sr   zUpgradable, but held- back: %sz
Remove: %szInstall: %szUpgrade: %s)rM   rN   rS   Zmarked_installr   nameZmarked_upgradeZmarked_deleteis_installedZis_upgradableZmarked_keeprH   )rk   instZupZrmZheldZkeeppkgr.   r.   r/   _logChangess  s,    	 	 	   z!DistUpgradeController._logChangesc             C   s  t  j d  |  j j d  |  j s* d St |  j j  d k rl t  j d  |  j j |  j	  |  j
   t |  j j  d k r |  j j } t d d t |   } t d d	 t |   d
 j |  } |  j	 j | |  d Sg  } xI |  j j d d  D]2 } | |  j k r |  j | j r | j |  q Wt  j d d j t |    |  j j   |  _ |  j j |  j |  j |  j  |  _ |  j r|  j j |  _ t  j d d j t |  j    t  j d d j t |  j    d S)NdoPostInitialUpdateZPostInitialUpdateFr   z-packages in reqReinstall state, trying to fixzPackage in inconsistent statezPackages in inconsistent statezThe package '%s' is in an inconsistent state and needs to be reinstalled, but no archive can be found for it. Please reinstall the package manually or remove it from the system.zThe packages '%s' are in an inconsistent state and need to be reinstalled, but no archive can be found for them. Please reinstall the packages manually or remove them from the system.z, rA   MetaPkgszMetaPkgs: %sr   zForeign: %szObsolete: %sT)rM   rN   rb   rp   rS   r,   Zreq_reinstall_pkgsr   Zfix_req_reinstrP   r~   r#   rH   rw   rV   rd   r   r   r   _getObsoletesPkgsobsolete_pkgs_getForeignPkgsr]   r[   r\   foreign_pkgsr   ZinstalledTaskstasks)rk   Z	reqreinstheaderr   Z	meta_pkgsr   r.   r.   r/   r     s<    	
 $	##z)DistUpgradeController.doPostInitialUpdatec             C   sC  t  j d |  |  j s+ t  j d  d S|  j j j   |  j j   } d } | d  k	 re | } n |  j j	 d d  } d } x | | k  ry |  j j
 |  Wn[ t t f k
 r } z5 t |  } t  j d | | f  | d	 7} w WYd  d  } ~ Xn Xd SWt  j d
  | r?|  j j t d  t d  d |  d S)Nz"running doUpdate() (showErrors=%s)zBdoUpdate() will not use the network because self.useNetwork==falseTr   r<   r=    zHIOError/SystemError in cache.update(): '%s'. Retrying (currentRetry: %s)r   zdoUpdate() failed completelyzError during updatezA problem occurred during the update. This is usually some sort of network problem, please check your network connection and retry.z%sF)rM   rN   rT   rS   Z_listr   rP   r   rV   rc   updater   IOErrorrZ   rw   rR   )rk   
showErrorsforceRetriesr   currentRetryrm   Z	error_msgr}   r.   r.   r/   doUpdate  s4    		
	zDistUpgradeController.doUpdatec             C   sF  t  d  } t  d  } t  d  } t  d  } t  d  } t  d  } t  d  } |  j j d d	 d
  r} t j d  d S|  j   } y |  j j |  Wnt k
 rA}	 zt	 j j
 d  }
 d } xK|	 j D]@} | d k r | d 7} | j |
 k r+| | | j | j | j | j | f 7} q | j d k rf| | | j | j | j | j | f 7} q | j d k r| | | j | j | j | j | f 7} q | j d k r| | | j | j | j | j | f 7} q | j d k r | | | j | j | j | j | f 7} q W|  j j | |  d
 SWYd d }	 ~	 Xn Xd S)z: this checks if we have enough free space on /var and /usrzNot enough free disk spacezThe upgrade has aborted. The upgrade needs a total of %s free space on disk '%s'. Please free at least an additional %s of disk space on '%s'. %szIRemove temporary packages of former installations using 'sudo apt clean'.zYou can remove old kernels using 'sudo apt autoremove' and you could also set COMPRESS=xz in /etc/initramfs-tools/initramfs.conf to reduce the size of your initramfs.zbEmpty your trash and remove temporary packages of former installations using 'sudo apt-get clean'.z!Reboot to clean up files in /tmp.r   Z	FreeSpaceZ	SkipCheckFz,free space check skipped via config overrideTzDir::Cache::archivesr   z/boot/z/tmpz/usrN)rR   rV   r   rM   r    _is_apt_btrfs_snapshot_supportedrS   ZcheckFreeSpacer&   r`   r   Zfree_space_required_listdirZ
size_totalZsize_neededrP   rw   )rk   Zerr_sumZerr_msgZremedy_archivedirZremedy_bootZremedy_rootZ
remedy_tmpZ
remedy_usrZwith_snapshotsr}   Z
archivedirZerr_longZreqr.   r.   r/   _checkFreeSpace  sT    
z%DistUpgradeController._checkFreeSpacec             C   sZ  |  j  j t d   |  j j |  j  |  j |  j  s; d S|  j r] |  j j |  j  s] d S|  j j	   } |  j  j
   |  j   |  j  j
   |  j   s d S|  j  j
   |  j j   |  _ t |  j  d k r|  j j   t j d d j d d   |  j D   t j d |  j  |  j  j
   |  j  j t d	  | |  j |  j j  } | S)
NzCalculating the changesFr   zdemoted: '%s'r   c             S   s   g  |  ] } | j   q Sr.   )r   )rC   r   r.   r.   r/   rD   0  s   	 z8DistUpgradeController.askDistUpgrade.<locals>.<listcomp>zfound components: %sz!Do you want to start the upgrade?)rP   rQ   rR   rS   ZdistUpgrader   ra   ZinstallTasksr   get_changesrt   r   r   Zget_installed_demoted_packagesinstalled_demotionsr,   sortrM   rN   rH   r   confirmChangesZrequired_download)rk   changesr   r.   r.   r/   askDistUpgrade  s0    !	
*z$DistUpgradeController.askDistUpgradec             C   s@   t  j j d  r< t j d t |  j   t  j d d  d  S)Nz/etc/cron.daily/aptzdisabling apt cron job (%s)i  )rE   rG   r   rM   rN   octrj   chmod)rk   r.   r.   r/   _disableAptCronJob=  s    z(DistUpgradeController._disableAptCronJobc             C   s6   t  j j d  r2 t j d  t  j d |  j  d  S)Nz/etc/cron.daily/aptzenabling apt cron job)rE   rG   r   rM   rN   r  rj   )rk   r.   r.   r/   _enableAptCronJobB  s    z'DistUpgradeController._enableAptCronJobc             C   s  |  j    d } |  j j   } |  j j d d d   } | r y! t j   d j d  d } Wn t j	 d  d } Yn X|  j j
   j d | | f  |  j j d d	  } d
 } d  } x | | k  ry; t j |  j j  } t j |  }	 |  j j |	 |  Wn t j j k
 rN}
 z t j d  d } |
 } PWYd  d  }
 ~
 XnO t k
 r}
 z/ t j d |
 | f  | d 7} |
 } w WYd  d  }
 ~
 Xn Xd SW| r|  j j t d  t d   n3 t j d  |  j j t d  t d  d |  |  j   |  j   d  S)Nr   rA   ZSlideshowUrlrR   getdefaultlocaleZenz%s#locale=%sr<   r=   Fzuser canceledTz:IOError in cache.commit(): '%s'. Retrying (currentTry: %s)r   zUpgrade canceledzwThe upgrade will cancel now and the original system state will be restored. You can resume the upgrade at a later time.z+giving up on fetching after maximum retrieszCould not download the upgradeszThe upgrade has aborted. Please check your Internet connection or installation media and try again. All files downloaded so far have been kept.z%s)r  rP   r   rV   r   localer  splitrM   r   ZgetHtmlViewr   rc   r`   ZPackageManagerrS   	_depcacheZAcquireZ_fetch_archivesaptZFetchCancelledExceptionr   r   rw   r   rR   r  rx   )rk   r   	fprogressZurlZlangrm   Zuser_canceledr   Zpmr   r}   r.   r.   r/   doDistUpgradeFetchingG  sN    
! 
	
z+DistUpgradeController.doDistUpgradeFetchingc             C   sv   y d d l  } Wn t k
 r( d SYn Xy | j   } | j   } Wn t j d  d SYn Xt j d |  | S)z' check if apt-btrfs-snapshot is usable r   Nzfailed to check btrfs supportFz!apt btrfs snapshots supported: %s)apt_btrfs_snapshotImportErrorAptBtrfsSnapshotZsnapshots_supportedrM   r   rN   )rk   r  	apt_btrfsr   r.   r.   r/   r     s    		z6DistUpgradeController._is_apt_btrfs_snapshot_supportedc             C   s_   |  j    s d Sd d l } | j   } d |  j } | j |  } t j d | | f  d S)z2 create btrfs snapshot (if btrfs layout is there) Nr   zrelease-upgrade-%s-z#creating snapshot '%s' (success=%s))r   r  r  r\   Zcreate_btrfs_root_snapshotrM   r   )rk   r  r  prefixr   r.   r.   r/    _maybe_create_apt_btrfs_snapshot  s    z6DistUpgradeController._maybe_create_apt_btrfs_snapshotc             C   s  d } |  j  j   } |  j  j |  j  } |  j j d d  } |  j sb |  j j d  |  j	   d } x| | k  rQy* |  j j
 | |  } t j d |  Wnt k
 r]} zt j d |  t j j d  rt d   } | j   } Wd  QRXt j d	 |  d
 d g } x | D] }	 t |  j |	  rt j d  |  j   t d  }
 |
 d t |  7}
 |
 t d  7}
 |  j  j t d  |
  |  j   qWt d  }
 |  j st   s|
 t d |  7}
 |  j  j t d  |
  d d d g } t j j d  d k r'| j d  |  j  j   j |  |  j   d SWYd  d  } ~ Xn t k
 r} z) t j d | | f  | d 7} wk WYd  d  } ~ Xn t  k
 rB} z~ t j! d  | j" d k r0|  j   t d  }
 |
 d t |  7}
 |
 t d  7}
 |  j  j t d  |
  |  j   WYd  d  } ~ Xn X|  j   d SWt j d  |  j  j t d  t d   d! |  |  j   d  S)"Nr   r<   r=   ZStartUpgradeFzcache.commit() returned %sz#SystemError from cache.commit(): %sz./var/run/ubuntu-release-upgrader-apt-exceptionzfound exception: '%s'z;E:Internal Error, Could not perform immediate configurationz E:Couldn't configure pre-depend z-detected preconfigure error, restorting statezError during commitz
'%s'
zRestoring original system statezCould not install the upgradeszrThe upgrade has aborted. Your system could be in an unusable state. A recovery will run now (dpkg --configure -a).z

Please report this bug in a browser at http://bugs.launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+filebug and attach the files in /var/log/dist-upgrade/ to the bug report.
%sz/usr/bin/dpkgz--configurez-ar   r   z--force-confoldz:IOError in cache.commit(): '%s'. Retrying (currentTry: %s)r   zcache.commit()   Tz+giving up on fetching after maximum retrieszCould not download the upgradeszdThe upgrade has aborted. Please check your Internet connection or installation media and try again. z%s)#rP   r   getInstallProgressrS   rV   rc   ra   rb   rp   r  commitrM   rN   r   rw   rE   rG   r   r   readrZ   r   r  rR   rx   r'   r_   rW   r   r   r   r   r   r   errno)rk   r   r
  	iprogressrm   r   r}   r   Zpre_configure_errorsZpreconf_errormsgr   r.   r.   r/   doDistUpgrade  sz    	
	
			



	z#DistUpgradeController.doDistUpgradec             C   sQ  |  j    |  j j d  |  j j   } |  j j |  j |  j |  j  } t	 j
 d d j t |    t	 j
 d d j t |    xD |  j j d d  D]- } | | k r t	 j d |  t   } Pq W|  j j d d d	  s t	 j
 d
  d	 Sx[ |  j j d d  D]D } | |  j k r|  j | j r|  j j |  j j | d   qW|  j j |  j j    t	 j
 d |  j  |  j r| |  j } n t d d   |  j D  } | t |  j  O} |  j j   } t	 j
 d d j |   | t |  O} |  j j d d d	  s4t	 j
 d  t   } t	 j
 d |  t	 j
 d  |  j j   } x t |  D]t \ } } | j | t t |   d  | |  j  k rn|  j j!   |  j j" | | |  j   snt	 j
 d |  qnWt	 j
 d  | j#   |  j j$   }	 t	 j
 d d j d d   |	 D   t% d  }
 t% d  t% d  g } t |	  d k r*|  j j& |
 |	 g  d | d  r*|  j j'   } |  j j( |  j  } y |  j j) | |  Wnb t* t+ f k
 r)} z< t	 j d |  |  j j t% d  t% d   d! |  WYd  d  } ~ Xn X|  j j d"  |  j, sM|  j-   d	 S)#NZPostUpgradezObsolete: %sr   zForeign: %srA   r   zXthe BaseMetaPkg '%s' is in the obsolete list, something is wrong, ignoring the obsoletesZRemoveObsoletesTzSkipping obsolete Removalr   rB   zforced_obsoletes: %sc             S   s   g  |  ] } | j   q Sr.   )r   )rC   pr.   r.   r/   rD   :  s   	 z7DistUpgradeController.doPostUpgrade.<locals>.<listcomp>zUnused dependencies: %sz0Skipping RemoveObsoletes as stated in the configzremove_candidates: '%s'z Start checking for obsolete pkgsg      Y@z:'%s' scheduled for remove but not safe to remove, skippingz!Finish checking for obsolete pkgsz1The following packages are marked for removal: %sc             S   s   g  |  ] } | j   q Sr.   )r   )rC   r   r.   r.   r/   rD   T  s   	 zRemove obsolete packages?Z_KeepZ_Remover   Fz,cache.commit() in doPostUpgrade() failed: %szError during commitz[A problem occurred during the clean-up. Please see the below message for more information. z%sZPostCleanup).r~   rb   rp   rS   r   r   r]   r[   r\   rM   rN   rH   r   rV   rd   rw   rY   r   r   re   r   ZidentifyObsoleteKernelsrT   r   r   Z_getUnusedDependenciesrP   r   	enumerater   floatr,   r   rt   ZtryMarkObsoleteForRemovaldoner   rR   r   r   r  r  r   r   ra   runPostInstallScripts)rk   Znow_obsoleteZnow_foreignr   Zremove_candidatesZunused_dependenciesr   ir   r   r   Zactionsr
  r  r}   r.   r.   r/   doPostUpgrade  sv    
!  	#		!
'!		
z#DistUpgradeController.doPostUpgradec             C   s   |  j  r# |  j  j   |  j  j   x |  j j d d  D] } t j j |  se t j	 d |  q9 t j
 d |  y- t |  |  j j   j | g d d Wq9 t k
 r } z t j d | | f  WYd d } ~ Xq9 Xq9 W|  j  r |  j  j   d S)	z 
        scripts that are run in any case after the distupgrade finished 
        whether or not it was successful

        Cache lock is released during script runs in the event that the
        PostInstallScripts require apt or dpkg changes.
        rA   ZPostInstallScriptsz!PostInstallScript: '%s' not foundzRunning PostInstallScript: '%s'ZhiddenTz(got error from PostInstallScript %s (%s)N)rS   rq   rr   rV   rd   rE   rG   r   rM   r   rN   r   rP   r   r   	Exceptionrw   get_lock)rk   Zscriptr}   r.   r.   r/   r  n  s    	
#.	z+DistUpgradeController.runPostInstallScriptsc             C   s   t  j d  t |  d  r/ |  j j |  j  t |  d  rQ |  j j |  j  |  j j t	 d   |  j j
   |  j   t j d  d S)z2 abort the upgrade, cleanup (as much as possible) zabort calledr   rU   zRestoring original system stater   N)rM   rN   hasattrr   Zrestore_backuprX   rU   rP   rQ   rR   rx   r~   ry   rz   )rk   r.   r.   r/   rx     s    
zDistUpgradeController.abortc       	      C   s   x t  j |  D] } t j d |  x | D] } | d } | d } | d } | |  j k rv t j d |  d S|  j | } t | j d d  } | d k r. t  j | | |  d	 k r. d	 Sq. Wq Wt j d
 |  d S)z+ check if a given depends can be satisfied zchecking: '%s' r   r      z_checkDep: '%s' not in cacheFversionNTzdepends '%s' is not satisfied)	r`   Zparse_dependsrM   rN   rS   rw   getattrZ	installedZ	check_dep)	rk   ZdepstrZor_groupdepZdepnameverZoperr   Zinstverr.   r.   r/   	_checkDep  s     


zDistUpgradeController._checkDepc             C   s   t  j d  d } |  j j d d  } | j |  j j |  j j j d   xg | D]_ } t  j d |  | |  j |  M} | sT |  j j	 t
 d  t
 d |   t j d  qT W| S)	z  check if depends are satisfied zcheckViewDepends()Tr   ZDependszdepends: '%s'z!Required depends is not installedz/The required dependency '%s' is not installed. r   )rM   rN   rV   rd   r   rP   rO   r2   r)  rw   rR   ry   rz   )rk   r   Zdependsr'  r.   r.   r/   r     s    
z&DistUpgradeController.checkViewDependsc             C   s  |  j  j d d  } d } t j  j d d  } |  j  j d d  } x | | k  r |  j d d	  |  j   x: | D]2 } | |  j k ru t j	 d
 |  t
 |   qu W|  j |  r Pt j d  t j  j d d  | d 7} qH W| | k rt j	 d  d	 St j  j d |  d S)NPreRequistsPackagesr   zAcquire::http::No-Cacher@   r<   r=   r   FzCan not find backport '%s'z>setting a cache control header to turn off caching temporarilytruer   z+pre-requists item is NOT trusted, giving upT)rV   rd   r`   findrc   r   r~   rS   rM   rw   r1   _allBackportsAuthenticatedrN   rY   )rk   backportslistr  ZnoCacherm   r   r.   r.   r/   _verifyBackports  s*    
z&DistUpgradeController._verifyBackportsc             C   s   t  j j d d  d k r, t j d  d Sy# |  j j d d  } | rN d SWn t k
 rc Yn XxM | D]E } |  j | } | j s d Sx" | j j	 D] } | j
 r Pq Wd Sqk Wd S)NzAPT::Get::AllowUnauthenticatedFTzIskip authentication check because of APT::Get::AllowUnauthenticated==truerA   ZAllowUnauthenticated)r`   rV   Zfind_brM   r   Z
getbooleanr   rS   r   r   Ztrusted)rk   r/  br   r   Zcandr.   r.   r/   r.    s$    		z0DistUpgradeController._allBackportsAuthenticatedc       
      C   s   | j  d  } t |  \ } } } } } d | k rI | j d  d } d | | | f } xj |  j D]_ } | j  d  } t | |  r d S| j d  d }	 | j |	  rf t j d |  d Sqf Wd S)	z  check if uri is a known mirror r   @r   z	%s://%s%sTz//z)found apt-cacher/apt-torrent style uri %sF)rstripr   r  rf   r   endswithrM   rN   )
rk   r   Zraw_urischemeZnetlocrG   ZqueryZfragmentmirrorZmirror_host_partr.   r.   r/   r     s    zDistUpgradeController.isMirrorc             C   sI   | j  d  } x3 |  j D]( } | j  d  } t | |  r d Sq Wd S)z2 check if uri is a whitelisted third-party mirror r   TF)r3  rg   r   )rk   r   r6  r.   r.   r/   r     s    z(DistUpgradeController.isThirdPartyMirrorc             C   s   d } t  d d  } x | j D] } | j s | j r: q | j d k r | j d k r |  j | j  r d | j k r d |  j | j	 k r | j j
 d  r | j j
 d	  r d
 | j |  j f } | | k r | | 7} q W| S)z7 get sources.list snippet lines for the current mirror r   r   r6   r   Fr(   z
%s-updateszhttp://security.ubuntu.comzhttp://archive.ubuntu.comzdeb %s %s-updates main
)r   r   r   r   r   r   r   r   r[   r   r   )rk   dumblinesr   r   Znew_liner.   r.   r/   _getPreReqMirrorLines  s     z+DistUpgradeController._getPreReqMirrorLinesc       	      C   s   t  j d |  |  j |  } t | d  j } t |  T } xJ | D]B } t |  } | j d |  } | j |  t  j d |  qH WWd QRXWd QRXd S)z9 add prerequists based on template into the path outfile z*writing prerequists sources.list at: '%s' wr6  zadding '%s' prerequistsNT)rM   rN   r9  r   r   Zsafe_substitutewrite)	rk   templateoutr7  ZmirrorlinesoutfileZinfiler   Zoutliner.   r.   r/   _addPreRequistsSourcesList#  s    !#z0DistUpgradeController._addPreRequistsSourcesListc          8   C   sg  t  j d  d } t j j t j   d  } t j j |  sM t j |  |  j j	 d d  } |  j
 r7|  j r7t  j d  t j j |  j
 j d t j j d   } t   } xX t j | d	  D]C } t  j d
 | | f  | j t j j |  j d  d  q Wt |  j |  sGt  j d t |  | f  d S|  j j   t j d d g t j | d	  d t j d t j d d } d } x6 | d k r| j   } |  j j   t j  d  qW|  j j d d  |  j j!   t  j" d |  t  j d | j#   d  | d k r-d S|  j$   Sd } |  j j% d | d |  j&  rn| d |  j& } |  j j' d |  } t j j |  st  j d |  d St j j t j j( d  |  }	 t j j t j j( d  |  }
 |  j) | |
  y |  j*   Wn t+ k
 r} zf |  j) | |
 d d y |  j*   Wn6 t+ k
 r{} z t  j, d |  WYd d } ~ Xn Xd SWYd d } ~ Xn Xx | D] } |  j | } |  j j- j. | j/  } | st  j d |  t j0 |	  d S| j1 d k rt  j d  |  t j0 |	  d St  j d! |  | j2 d" d d# d  qWd } y1 |  j j3 |  j j4   |  j j5 |  j   } Wnw t6 k
 r} z t  j d$ |  d } WYd d } ~ Xn< t7 k
 r} z t  j d% |  d } WYd d } ~ Xn X| d k rt  j, d&  y t j0 |
  Wn6 t8 k
 r\} z t  j d' |  WYd d } ~ Xn X|  j$   S)(z5 download the backports specified in DistUpgrade.cfg zgetRequiredBackports()TZ	backportsr*  r+  z#Searching for pre-requists on CDROMz*dists/stable/main/dist-upgrader/binary-%s/zAPT::Architecturez*_*.debzfound pre-req '%s' to '%s'rR   r   z%Expected backports: '%s' but got '%s'Fz/usr/bin/dpkgz-ir   stderrr   Ng{Gz?Zfinishedz'installing backport debs exit code '%s'zdpkg output:
%sr   z-%szsourceslist not found '%s'zDir::Etc::sourcepartsr7  zno backport for '%s' foundzNo candidate for '%s'zNo ver.file_list for '%s'zmarking '%s' for installZ	auto_instZauto_fixzfetch_archives returned '%s'zinstall_archives returned '%s'z,_fetch_archives for backports returned Falsez(failed to unlink pre-requists file: '%s')9rM   rN   rE   rG   rH   rF   r   mkdirrV   rd   rU   rT   rl   r`   r-  rY   r   r   basenamer  issubsetrw   rS   rq   r   r   r   ZSTDOUTZpollrP   ZpulseProgressru   rv   r"  r   r   setupRequiredBackportsZ
has_optionr^   rW   r   r?  r0  r1   r   r  Zget_candidate_verZ_pkgunlinkZ	file_listZmark_installr  r   r  r   r   r!  )rk   r   r   r/  r  Z
found_pkgsr   Zconf_optionZprereq_templateZoutpathr>  r}   r   r   r(  r.   r.   r/   getRequiredBackports1  s    	*	
 !!$$z*DistUpgradeController.getRequiredBackportsc             C   s   d t  j d <t j   t j d d  t j d g } |  j rP | j	 d  n | j	 d  t j
 d  t t j d	  t  j t j d	 | t  j  d  S)
Nz$/usr/lib/release-upgrader-python-apt
PYTHONPATHz/var/log/dist-upgrade/main.logz&/var/log/dist-upgrade/main_pre_req.logz--have-prerequistsz--with-networkz--without-networkzrestarting upgraderr   )rE   r_   rM   Zshutdownshutilr   ry   argvrT   r   r   r   execve)rk   argsr.   r.   r/   rD    s    
		z,DistUpgradeController.setupRequiredBackportsc             C   s2  |  j  j t d   |  j  j t  |  j   s t j d  t j	 j
 d  r |  j  j t d  t d   t j d d g  n, |  j  j t d  t d   t j d	  t j d
  |  j j d  r|  j r|  j j d k rt j d  |  j   st j	 j
 d  rL|  j  j t d  t d   t j d d g  n, |  j  j t d  t d   t j d	  |  j   |  j d d d d
  |  j   |  j   s|  j   |  j  j t  |  j  j t d   |  j   s|  j   |  j r?|  j j |  j  r?|  j  j t d  t d   t j d
  |  j   sU|  j   |  j  j t d   |  j d d  |  j j   |  _  |  j! j"   x|  j j# d d  D] } | |  j k s|  j j$ |  j |  rt j d |  | |  j k rt j d |  |  j j$ |  j |  s:t j d |  |  j  j t d  t d  |  t j	 j
 d  rt j d d g  n t j d	  |  j   qW|  j  j t d   |  j%   s|  j   |  j  j t&  |  j  j t d    |  j'   s|  j   |  j  j t(  |  j  j t d!   |  j)   sp|  j*   |  j  j+ t d"  t d#   t j d
  |  j  j t,  |  j  j t d$   |  j-   |  j r|  j j.   t j	 j
 d%  rt j/ d%  |  j  j t0  |  j  j t d&   t1   r.|  j  j2   r.t j d'  t j d(  d S))NzChecking package managerzself.prepared() failedz/usr/bin/apport-bugzPreparing the upgrade failedzXPreparing the system for the upgrade failed so a bug reporting process is being started.z
apport-bugzubuntu-release-upgrader-corezPreparing the system for the upgrade failed. To report a bug install apport and then execute 'apport-bug ubuntu-release-upgrader'.z.Missing apport-bug, bug report not autocreatedr   r*  Fzneed backportsz$Getting upgrade prerequisites failedzThe system was unable to get the prerequisites for the upgrade. The upgrade will abort now and restore the original system state.

Additionally, a bug reporting process is being started.zThe system was unable to get the prerequisites for the upgrade. The upgrade will abort now and restore the original system state.

To report a bug install apport and then execute 'apport-bug ubuntu-release-upgrader'.r   r   zUpdating repository informationzFailed to add the cdromz+Sorry, adding the cdrom was not successful.r|   TrA   r   z@No '%s' available/downloadable after sources.list rewrite+updatez'%s' was not in the cachez'%s' was not downloadablezInvalid package informationa  After updating your package information, the essential package '%s' could not be located. This may be because you have no official mirrors listed in your software sources, or because of excessive load on the mirror you are using. See /etc/apt/sources.list for the current list of configured software sources.
In the case of an overloaded mirror, you may want to try the upgrade again later.zCalculating the changesFetching	UpgradingzUpgrade completezKThe upgrade has completed but there were errors during the upgrade process.zSearching for obsolete softwarez:/var/lib/ubuntu-release-upgrader/release-upgrade-availablezSystem upgrade is complete.z/sbin/rebootr   )3rP   rQ   rR   setStepr   r   rM   rw   rE   rG   r   r   r   ry   rz   rV   rh   rJ   r   rN   rF  rx   r   r~   r   r   r   rU   r   rX   rS   r   r   rb   Z+ensure_recommends_are_installed_on_desktopsrd   ZanyVersionDownloadabler   r   r  r   r  r  r   r   r   Zcomment_out_cdrom_entryrE  r   r
   confirmRestart)rk   r   r.   r.   r/   fullUpgrade  s    	



	
	



	
z!DistUpgradeController.fullUpgradec             C   s   |  j  j   |  j   S)N)rP   rt   rP  )rk   r.   r.   r/   rp   y  s    zDistUpgradeController.runc             C   s  |  j  j t  |  j  j t  |  j  j t  d |  _ |  j   |  j   sS d S|  j	   sc d S|  j  j t
  |  j  j t d   |  j   s d S|  j  j t  |  j  j t d   |  j   s |  j  j t d  t d   d S|  j  j t  |  j   s-|  j  j t d  t d   d St j j t  r^|  j  j   r}t j d  n |  j  j t d  t d   d S)	z, partial upgrade mode, useful for repairing TFrL  rM  zUpgrade completezKThe upgrade has completed but there were errors during the upgrade process.z/sbin/rebootz"The partial upgrade was completed.)rP   rN  r   ZhideStepr   r   ra   r   r   r   r   rQ   rR   r  r   r  r   r   r   rE   rG   r   REBOOT_REQUIRED_FILErO  r   r   )rk   r.   r.   r/   doPartialUpgrade}  s<    	
z&DistUpgradeController.doPartialUpgrade)*r2   r3   r4   __doc__rn   r~   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r  r  r   r  rx   r)  r   r0  r.  r   r   r9  r?  rF  rD  rP  rp   rR  r.   r.   r.   r/   r5   d   sP   c#;u Y-$>'J
bb	zr5   __main__)DistUpgradeViewTextlevel)Nr	  r`   ry   rE   r   r  rM   rH  r   ru   r   configparserr   r   r   Zutilsr   r   r   r   r	   r
   r   r   r   stringr   Zurllib.parser   ZDistUpgradeViewr   r   r   r   r   r   ZDistUpgradeCacher   ZDistUpgradeConfigParserr   r   ZDistUpgradeAptCdromr   ZDistUpgradeAufsr   r   r   r   r   ZDistInfor   r   r   r    r!   ZDistUpgradeGettextr"   rR   r#   r$   r%   r&   ZDistUpgradeApportr'   rQ  r0   r!  r1   objectr5   r2   rU  ZbasicConfigDEBUGvZdcr  r  r.   r.   r.   r/   <module>   sb   @	.       I	
