
TNc           @   sF  d  d l  Z  e  j d d e  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 Z d  d l m Z m Z d  d l m Z d  d l m Z d  d l m Z m Z d e f d	     YZ d
 e f d     YZ d e f d     YZ d   Z e   Z d e f d     YZ  d e f d     YZ! d e j" f d     YZ# e$ d k rBd  d l% Z% d  d l& Z& d  d l' Z' d GHe# e& j( d  e' j'   e)  Z* e* j+   GHe% j,   e* j-   e* j.   e* j/ e* j0 d g  e* j1   GHe* j2   n  d S(   iNt   ignores   apt API not stable yet(   t   Popent   PIPE(   t   gettext(   t   ngettext(   t   inside_chroott   estimate_kernel_size_in_boott   CacheExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR   +   s   t   CacheExceptionLockingFailedc           B   s   e  Z RS(    (   R   R	   (    (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR
   -   s   t   CacheExceptionDpkgInterruptedc           B   s   e  Z RS(    (   R   R	   (    (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR   /   s   c          C   s9   t    }  |  d k r+ t j d  d }  n  |  d	 7}  |  S(
   Ni    s,   estimate_kernel_size_in_boot() returned '0'?i   i   i   i p  i  i   i   (   R   t   loggingt   warn(   t   size(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   _set_kernel_initrd_size4   s    		
t   FreeSpaceRequiredc           B   s    e  Z d  Z d   Z d   Z RS(   s    FreeSpaceRequired object:
    
    This exposes:
    - the total size required (size_total)
    - the dir that requires the space (dir)
    - the additional space that is needed (size_needed)
    c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t
   size_totalt   dirt   size_needed(   t   selfR   R   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   __init__F   s    		c         C   s   d |  j  |  j |  j f S(   Ns@   FreeSpaceRequired Object: Dir: %s size_total: %s size_needed: %s(   R   R   R   (   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   __str__J   s    (   R   R	   t   __doc__R   R   (    (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR   >   s   	t   NotEnoughFreeSpaceErrorc           B   s   e  Z d  Z d   Z RS(   sO    
    Exception if there is not enough free space for this operation 
    
    c         C   s   | |  _  d  S(   N(   t   free_space_required_list(   R   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR   S   s    (   R   R	   R   R   (    (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR   N   s   t   MyCachec           B   s<  e  Z d  Z d Z d8 e d  Z e d    Z d   Z	 d   Z
 d   Z d   Z d   Z e d	    Z e d
    Z e d    Z d   Z d   Z d8 d  Z d   Z e d  Z e d  Z e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z d d  Z  d d  Z! d d  Z" d   Z# d    Z$ d!   Z% d"   Z& d#   Z' d$   Z( d%   Z) d&   Z* d'   Z+ d(   Z, e d)    Z- d*   Z. d+   Z/ e d,    Z0 d-   Z1 d.   Z2 d/   Z3 d0   Z4 e d1    Z5 d2   Z6 d3   Z7 d4   Z8 d5   Z9 d6   Z: e; d7  Z< RS(9   i   i   c         C   se  t  j j |  |  g  |  _ g  |  _ | |  _ | |  _ t |  _ t |  _	 | |  _
 |  j
 j d d  |  _ d |  _ | r y! t j   |  j   t |  _ Wq t k
 r } d t |  k r t |  n  t |  q Xn  | j d d  |  _ t d d g d t j   d	 j   |  _ |  j   | j d
 d  d k rad t j  k rat j! j" d d  n  d  S(   Nt   Distrot   MetaPkgsis   dpkg --configure -at   RemovalBlacklistFilet   unames   -rt   stdouti    t   Sourcest   Fromt   hardyt   RELEASE_UPGRADE_NO_RECOMMENDSs   APT::Install-Recommendst   true(#   t   aptt   CacheR   t
   to_installt	   to_removet   viewt   quirkst   Falset   lockt   partialUpgradet   configt   getlistt   metapkgst
   _listsLockt   apt_pkgt   PkgSystemLockt   lockListsDirt   Truet   SystemErrort   strR   R
   t   getListFromFilet   removal_blacklistR   R   t   communicatet   stripR   t   _initAptLogt   gett   ost   environt   Configt   set(   R   R.   R)   R*   t   progressR,   t   e(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR   [   s2    								

+
c         C   se   t    } xU |  D]M } | j r | j j |  j k sJ | j j |  j k r | j | j  q q W| S(   sB    return the packages not downloadable packages in reqreinst state (   RA   t   candidateDownloadablet   _pkgt
   inst_statet	   ReInstReqt   HoldReInstReqt   addt   name(   R   t	   reqreinstt   pkg(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   reqReinstallPkgs{   s    	
c         C   s   |  j  } t |  d k r t d d t |   } t d d t |   d j |  } | j | |  r |  j   d d d	 g t |  } | j   j |  |  j	   t
 Sn  t S(
   s/    check for reqreinst state and offer to fix it i    s   Remove package in bad states   Remove packages in bad states   The package '%s' is in an inconsistent state and needs to be reinstalled, but no archive can be found for it. Do you want to remove this package now to continue?s   The packages '%s' are in an inconsistent state and need to be reinstalled, but no archives can be found for them. Do you want to remove these packages now to continue?s   , t   dpkgs   --removes   --force-remove-reinstreq(   RM   t   lenR   t   joint   askYesNoQuestiont   releaseLockt   listt   getTerminalt   callt   getLockR5   R+   (   R   R)   RK   t   headert   summaryt   cmd(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   fixReqReinst   s    	

c         C   s   |  j  j d d d  } t j j |  s: t j |  n  t j j d |  t j j d d  t j	 t j j
 | d  t j t j Bt j Bd  |  _ t j |  j d	 t j j    t j j d
 d  t j j d d  d S(   s    init logging, create log filet   Filest   LogDirs   /var/log/dist-upgrades   Dir::Logs   Dir::Log::Terminals   apt-term.logs   apt.logi  s   Log time: %s
s   Debug::pkgProblemResolverR$   s   Debug::pkgDepCache::AutoInstallN(   R.   t   getWithDefaultR>   t   patht   existst   makedirsR2   R@   RA   t   openRP   t   O_RDWRt   O_CREATt   O_APPENDt   logfdt   writet   datetimet   now(   R   t   logdir(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR<      s    	  c         C   s   t  |  d  r2 t j |  j  t j |  j  n  t j d  |  _ t j d  |  _ t j |  j d  t j |  j d  d  S(   Nt
   old_stdouti   i   (   t   hasattrR>   t   closeRj   t
   old_stderrt   dupt   dup2Re   (   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   _startAptResolverLog   s    c         C   sD   t  j d  t  j d  t  j |  j d  t  j |  j d  d  S(   Ni   i   (   R>   t   fsyncRo   Rj   Rm   (   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   _stopAptResolverLog   s    c            s     f d   } | S(   s3    decorator to ensure that the apt output is logged c             s/   |  d j      |  |   } |  d j   | S(   Ni    (   Rp   Rr   (   t   argst   kwargst   res(   t   f(    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   wrapper   s    (    (   Rv   Rw   (    (   Rv   s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   withResolverLog   s    c         C   s>   t  j |  j  } t  j   } | j | |  j |  j  | j S(   s<    get the size of the packages that are required to download (   R2   t   PackageManagert	   _depcachet   Acquiret   get_archivest   _listt   _recordst   fetch_needed(   R   t   pmt   fetcher(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   requiredDownload   s    c         C   s
   |  j  j S(   s9    get the size of the additional required space on the fs (   Rz   t   usr_size(   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   additionalRequiredSpace   s    c         C   s   |  j  j d k S(   s    is the cache broken i    (   Rz   t   broken_count(   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   isBroken   s    c         C   sQ   t  j j d  d } t  j |  |  _ |  j d k  rM d | } t |  n  d  S(   Ns   Dir::State::ListsR,   i    s   Can not lock '%s' (   R2   R@   t   find_dirt   GetLockR1   R
   (   R   RJ   RC   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR4      s
    
c         C   s/   |  j  d k r+ t j |  j   d |  _  n  d  S(   Ni    i(   R1   R>   Rl   (   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   unlockListsDir   s    c         C   sl   |  j    t j j |  |  } |  j   | rM | j rM t t d    n  | t k rh t d   n  d S(   sf   
        our own update implementation is required because we keep the lists
        dir lock
        s   The server may be overloadedsA   apt.cache.update() returned False, but did not raise exception?!?N(	   R   R%   R&   t   updateR4   t   release_file_download_errort   IOErrort   _R+   (   R   t	   fprogressRu   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR      s    

c         C   s=   t  j d  |  j r# |  j   n  t j j |  | |  d  S(   Ns   cache.commit()(   R   t   infoR,   RR   R%   R&   t   commit(   R   R   t	   iprogress(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR      s    	c         C   sN   |  j  rJ y t j   t |  _  WqJ t k
 rF } t j d |  qJ Xn  d  S(   Ns   failed to SystemUnLock() (%s) (   R,   R2   t   PkgSystemUnLockR+   R6   R   t   debug(   R   t   pkgSystemOnlyRC   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyRR      s    	
c         C   sN   |  j  sJ y t j   t |  _  WqJ t k
 rF } t j d |  qJ Xn  d  S(   Ns   failed to SystemLock() (%s) (   R,   R2   R3   R5   R6   R   R   (   R   R   RC   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyRV     s    	
c         C   s[   | r |  j  j | j  } n | j j } | d k rT t j d | j | f  t S| j	 S(   s*    check if the given pkg can be downloaded s1   no version information for '%s' (useCandidate=%s)N(
   Rz   t   get_candidate_verRE   t
   CurrentVert   NoneR   t   warningRJ   R+   t   downloadable(   R   RL   t   useCandidatet   ver(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR   	  s    c         C   s   | j  o |  j j | j  S(   s$    check if the pkg is auto-removable (   t   is_installedRz   t
   is_garbageRE   (   R   RL   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   pkgAutoRemovable  s    	c         C   s   |  j  j   S(   s^    try to fix broken dependencies on the system, may throw
            SystemError when it can't(   Rz   t	   FixBroken(   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt	   fixBroken  s    c         C   st   g  |  _  g  |  _ x[ |  j   D]M } | j s7 | j rM |  j  j | j  n  | j r |  j j | j  q q Wd S(   s*    create a snapshot of the current changes N(   R'   R(   t   get_changest   marked_installt   marked_upgradet   appendRJ   t   marked_delete(   R   RL   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   create_snapshot  s    			c         C   s   |  j  j   d  S(   N(   Rz   t   Init(   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   clear(  s    c         C   s   t  j |  j  } | |  j   x% |  j D] } |  | } | j   q* Wx1 |  j D]& } |  | } | j d t d t  qR Wd S(   s    restore a snapshot t   auto_fixt	   auto_instN(	   R2   t   ActionGroupRz   R   R(   t   mark_deleteR'   t   mark_installR+   (   R   t   actiongroupRJ   RL   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   restore_snapshot+  s    


c         C   s   |  j  j d d  } x | D] } |  j |  rS |  | j rS t j d |  t St } x= |  j  j | d  D]& } | |  j |  o |  | j M} qo W| r t j d |  t Sq Wt j d  t S(   sm   
        This checks if we run on a desktop or a server install.
        
        A server install has more freedoms, for a desktop install
        we force a desktop meta package to be install on the upgrade.

        We look for a installed desktop meta pkg and for key 
        dependencies, if none of those are installed we assume
        server mode
        R   R   s>   needServerMode(): run in 'desktop' mode, (because of pkg '%s')t   KeyDependenciessG   needServerMode(): run in 'desktop' mode, (because of key deps for '%s')sY   needServerMode(): can not find a desktop meta package or key deps, running in server mode(   R.   R/   t   has_keyR   R   R   R+   R5   (   R   R0   t   keyt
   deps_foundRL   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   needServerMode9  s    $c         C   s\   |  j  rX y t j d  |  j   WqX t k
 rT | j t d  t d   t SXn  t S(   sY    check if the cache is ok and if the required metapkgs
            are installed
        s$   Have broken pkgs, trying to fix thems   Broken packagess   Your system contains broken packages that couldn't be fixed with this software. Please fix them first using synaptic or apt-get before proceeding.(	   R   R   R   R   R6   t   errorR   R+   R5   (   R   R)   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   sanityCheckW  s    	t    c         C   sj   t  j d | | f  |  j |  rf |  | j   |  | j pK |  | j sf t  j d |  t Sn  t S(   Ns   Installing '%s' (%s)s    Installing/upgrading '%s' failed(	   R   R   R   R   R   R   R   R+   R5   (   R   RL   t   reason(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR   i  s    c         C   sj   t  j d | | f  |  j |  rf |  | j rf |  | j   |  | j sf t  j d |  t Sn  t S(   Ns   Upgrading '%s' (%s)s   Upgrading '%s' failed(	   R   R   R   R   t   mark_upgradeR   R   R+   R5   (   R   RL   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR   r  s    c         C   s;   t  j d | | f  |  j |  r7 |  | j   n  d  S(   Ns   Removing '%s' (%s)(   R   R   R   R   (   R   RL   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   mark_removez  s    c         C   sG   t  j d | | f  |  j |  rC |  j j |  | j t  n  d  S(   Ns   Purging '%s' (%s)(   R   R   R   Rz   R   RE   R5   (   R   RL   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt
   mark_purge~  s    c         C   s@   |  j  |  r< |  | j r< |  | j r< |  j | |  n  d  S(   N(   R   R   R   R   (   R   t   pkgnameR   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   _keepInstalled  s    c         C   s  x- |  j  j d d  D] } |  j | d  q Wxq |  j D]f } |  j |  r: |  | j si |  | j r: x4 |  j  j | d  D] } |  j | d |  q Wq: q: W|  j  j d d  d k rt j	 d  xi |  j  j d d	  D]R } xI |  D]A } | j
 r | j r | j | k r |  j | j d
 |  q q Wq Wx |  j D] } |  j |  rB|  | j sq|  | j rBxr |  j  j | d	  D]X } xO |  D]G } | j
 r| j r| j | k r|  j | j d | | f  qqWqWqBqBWn  d S(   s[    run after the dist-upgrade to ensure that certain
            packages are kept installed R   t   KeepInstalledPkgss   Distro KeepInstalledPkgs rules   %s KeepInstalledPkgs rulet   Optionst   withNetworkR5   s"   Running KeepInstalledSection rulest   KeepInstalledSections$   Distro KeepInstalledSection rule: %ss    %s KeepInstalledSection rule: %sN(   R.   R/   R   R0   R   R   R   R=   R   R   RD   R   t   sectionRJ   (   R   R   R   R   RL   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   keepInstalledRule  s(    !"!c      
   C   s  x d |  j  f d |  j f d |  j f d |  j f g D] \ } } x2 |  j j d d |  D] } | | d |  q] Wxx |  j D]m } |  j |  r |  | j s |  | j	 r x; |  j j | d |  D] } | | d | | f  q Wq q Wq7 W|  j
 s|  j j d	  n  d
 S(   s-    run after the upgrade was done in the cache t   Installt   Upgradet   Removet   PurgeR   s   PostUpgrade%ss   Distro PostUpgrade%s rules   %s PostUpgrade%s rulet   PostDistUpgradeCacheN(   R   R   R   R   R.   R/   R0   R   R   R   R-   R*   t   run(   R   t   rulet   actionRL   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   postUpgradeRule  s      &	c   	   	   C   s7  t  j d  t   } |  j j d d  } |  j j d d  } |  j j d d  } x |  D] } x | D] } d | | f } x | D] } | j j |  r | j j |  r | j	 r | j d | |  j
 f k r t  j d | j  q n  t  j d	 | j  | j | j  q q Wqi Wq\ Wt  j d
 |  | S(   Ns   identifyObsoleteKernels()t   KernelRemovalt   Versiont	   BaseNamest   Typess   %s-%s-s   %s-%ss   skipping running kernel %ss   removing obsolete kernel '%s's"   identifyObsoleteKernels found '%s'(   R   R   RA   R.   R=   R/   RJ   t
   startswitht   endswithR   R   RI   (	   R   t   obsolete_kernelst   versiont	   basenamest   typesRL   t   baset   basenamet   type(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   identifyObsoleteKernels  s&    		c         C   s`  t  j d  y d d l m } Wn% t k
 rH } t  j d |  t SXy | d d d d  } xR | j D]6 } |  j |  rk |  | j	 rk |  j
 | d	  Pqk qk Wt  j d
  t S| j   } t  j d |  |  j |  s t  j d |  t S|  | j p|  | j s4|  | j   t  j d |  t SWn$ t k
 r[} t  j d |  n Xt S(   sS    
        this checks for nvidia hardware and checks what driver is needed
        s   nvidiaUpdate()i(   t   NvidiaDetections%   NvidiaDetector can not be imported %st   datadirs   ./modaliases/t   obsoletes   ./nvidia-obsolete.pkgss   old nvidia drivers1   no old nvidia driver installed, installing no news   nv.selectDriver() returned '%s's   no '%s' founds,   installing %s as suggested by NvidiaDetectors$   NvidiaDetection returned a error: %s(   R   R   t   NvidiaDetector.nvidiadetectorR   t   ImportErrorR   R+   t   oldPackagesR   R   R   R   t   selectDriverR   R   R   R   R5   t	   Exception(   R   R   RC   t   nvt	   oldDrivert   driver(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   checkForNvidia  s6    	c         C   s^   t  d d g d t j   d } t d   t t j | j d    } t j	 d |  | S(   s7   get the list of recommended kernels from base-installers   /bin/shs   ./get_kernel_list.shR   i    c         S   s   t  |   d k S(   Ni    (   RO   (   t   x(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   <lambda>  s    s   
s    ./get_kernel_list.sh returns: %s(
   R   R   R:   t   filtert   mapt   stringR;   t   splitR   R   (   R   t   kernels(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   getKernelsFromBaseInstaller  s    	c         C   s   |  j    } x | D] } |  j |  s? t j d |  q n  |  | j sc t j d |  q n  |  | j s} |  | j r t j d |  |  | j r |  | j r |  j	 | d  n  d Sq Wx$ | D] } |  j
 | d  r d Sq Wd S(   s    use the get_kernel_list.sh script (that uses base-installer)
            to figure out what kernel is most suitable for the system
        s   %s not available in caches   %s not downloadables   %s kernel already installeds$   Upgrading kernel from base-installerNs(   Selecting new kernel from base-installer(   R   R   R   R   RD   R   R   t   is_upgradableR   R   R   (   R   R   t   kernel(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   _selectKernelFromBaseInstaller  s     c         C   s   t  j d |  j  y |  j j d  \ } } } Wn% t k
 rZ } t  j d |  t SXt d g d t j	   d } d | k r t  j d  n  t
 j j d	  r |  j   n t  j d
  t S(   sd    check for the running kernel and try to ensure that we have
            an updated version
        s   Kernel uname: '%s' t   -s/   Can't parse kernel uname: '%s' (self compiled?)t   dmesgR   i    s   WARNING: NR_CPUS limits   UP kernel on SMP system!?!s   ./get_kernel_list.shs(   skipping ./get_kernel_list.sh: not found(   R   R   R   R   R   R   R+   R   R   R:   R>   R^   R_   R   R5   (   R   R   t   buildt   flavourRC   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   checkForKernel&  s    c         C   s   d } |  j  j d d  } x |  D] } | j j j | j  } | ro | j d k ro t j d | j	  q" n  | j
 r" | j p | j r" | j	 | k r" d | j	 k r" | j | k r" |  j | j	 d |  q" q" Wd  S(	   Nt   requiredR   t   RemoveEssentialOki    s   Package %s has no priority sett   :s;   priority in required set '%s' but not scheduled for install(   R   (   R.   R/   t   _pcacheRz   R   RE   t   PriorityR   R   RJ   RD   R   R   t   priorityR   (   R   t   needt   removeEssentialOkRL   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   checkPriority;  s    	c         C   su   d } xN | j    rV | d d k r2 | j   n  | j   t j d  | d 7} q	 W| j d t  | j   d  S(   Ni    i   g{Gz?i   t   finished(   t   lockedt   pulseProgresst   processEventst   timet   sleepR5   (   R   R)   R,   t   i(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt	   updateGUIP  s    
c         C   sT  t  j   } | j   t  j d |  j d |  j | f  } | j   y |  j t  |  j	   |  j
   t   r t j d  n
 |  j   |  j   |  j   |  j |  | s |  j |  n  |  j   Wn t k
 rj} | j   | j   t d |  } | r| t d  7} n | t d  7} |  j   | j t d  |  |  j   t j d |  t SX| j   | j   g  } x	|  j   D] }	 |	 j rqn  |	 j rDx |	 j j  D]} }
 t! j" |
 j# |	 j$ j%  d	 k  rxS |
 j& D]E \ } } |	 j' j( j) |  } | r| j* r| j+ |	 j,  PqqWqqWqn  |	 j- j. } t } x | D] } | | j/ O} q]W| s| j+ |	 j,  qqWy0 |  j0 j1 d
 d  } | rt j2 d  t SWn t3 j4 k
 r} n Xt5 |  d	 k rP| j6   t j d d j |   |  j   | j t d  t d  d j |   |  j   t St S(   Nt   targetRs   s5   skipping kernel checks because we run inside a chroots   An unresolvable problem occurred while calculating the upgrade:
%s

 This can be caused by:
 * Upgrading to a pre-release version of Ubuntu
 * Running the current pre-release version of Ubuntu
 * Unofficial software packages not provided by Ubuntu

s@   This is most likely a transient problem, please try again later.sq   If none of this applies, then please report this bug using the command 'ubuntu-bug update-manager' in a terminal.s   Could not calculate the upgrades   Dist-upgrade failed: '%s'i    R   t   AllowUnauthenticateds   AllowUnauthenticated set!s$   Unauthenticated packages found: '%s't    s"   Error authenticating some packagess   It was not possible to authenticate some packages. This may be a transient network problem. You may want to try again later. See below for a list of unauthenticated packages.s   
(7   t	   threadingt   Lockt   acquiret   ThreadR  R)   t   startt   upgradeR5   R   R   R   R   R   R   R   R   t   _keepBaseMetaPkgsInstalledt   _installMetaPkgst   _verifyChangesR6   t   releaseRP   R   Rr   R   Rp   R+   R   R   t   marked_downgradeRE   t   version_listR2   t   version_comparet   ver_strt	   installedR   t	   file_listR   R}   t
   find_indext
   is_trustedR   RJ   t	   candidatet   originst   trustedR.   t
   getbooleanR   t   ConfigParsert   NoOptionErrorRO   t   sort(   R   R)   t
   serverModeR-   R,   t   tRC   t   detailst	   untrustedRL   R   t   verFileItert   indext	   indexfileR  R  t   origint   b(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   distUpgrade[  s    
$


	









		
	
	
c         C   sZ  |  j  j d d  } x |  j   D] } | j ro |  j | j  ro t j d | j  t t	 d  | j  n  | j r" | j
 j t k r" | j | k r" t j d | j  t t	 d  | j  q" q" W|  j  j d d  } xu | D]m } | j d  \ } } |  j |  r |  | j | k r |  | j s<|  | j r t t	 d	  |  q q Wt S(
   sx    this function tests if the current changes don't violate
            our constrains (blacklisted removals etc)
        R   R   sH   The package '%s' is marked for removal but it's in the removal blacklistsJ   The package '%s' is marked for removal but it is in the removal blacklist.sC   The package '%s' is marked for removal but it's a ESSENTIAL packages1   The essential package '%s' is marked for removal.t   BadVersionsR   s*   Trying to install blacklisted version '%s'(   R.   R/   R   R   t   _inRemovalBlacklistRJ   R   R   R6   R   RE   t	   EssentialR5   R   R   t   candidateVersionR   R   (   R   R   RL   t   badVersionst   bvR   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR    s$    c         C   s   | j  j j | j  } | d k r4 d G| j GHt S| j d k rY d |  j j   GHt S| j j	 d  \ } } | j  j
 j | | f  t S(   s   
        helper to make sure that the pkg._records is pointing to the right
        location - needed because python-apt 0.7.9 dropped the python-apt
        version but we can not yet use the new version because on upgrade
        the old version is still installed
        s   No candidate ver: s   No FileList for: %s i    N(   R   Rz   R   RE   R   RJ   R+   R  t   Namet   popR~   t   lookupR5   (   R   RL   R   Rv   R)  (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   _lookupPkgRecord  s    c         C   s>  i  } t    } x |  D] } |  j |  sE t j d | j  q n  x | j j j j d  D]{ } | j	 d  r^ xc | t
 d  j d  D]E } | j   } | j |  s t    | | <n  | | j | j  q Wq^ q^ Wq WxV | D]N } t } x) | | D] } |  | j s t } Pq q W| r | j |  q q W| S(   Ns&   no PkgRecord found for '%s', skipping s   
s   Task:t   ,(   RA   R7  R   R   RJ   R   R~   t   recordR   R   RO   R;   R   RI   R5   R   R+   (   R   t   taskst   installed_tasksRL   t   linet   taskR  R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   installedTasks  s,    	 #c         C   s  t  j d  x |  D] } | j s | j r2 q n  |  j |  t | j j d  o` | j j j s} t  j	 d | j
  q n  x{ | j j j j d  D]a } | j d  r xI | t d  j d  D]+ } | j   } | | k r | j   q q Wq q Wq Wt S(   Ns   running installTasksR9  s   can not find Record for '%s's   
s   Task:R8  (   R   R   R   R   R7  Rk   R   R~   R9  R   RJ   R   R   RO   R;   R   R5   (   R   R:  RL   R<  R=  (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   installTasks  s    $ c         C   s4   x- |  j  j d d  D] } |  j | d  q Wd  S(   NR   t   BaseMetaPkgss%   base meta package keep installed rule(   R.   R/   R   (   R   R)   RL   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR  .  s    c            s"     f d   }   j  j d d   x+   j  j d d  D] }   | j   q= Wx  D] } yO   j |  r   | j r   | j r t j d |    | j   n  Wq\ t	 k
 r } t j
 d | | f  q\ Xq\ W|   st j d   x  D] } t } x=   j  j | d  D]& } |   j |  oG  | j M} q%W| rt j d	 |  y   | j   WnQ t	 t f k
 r} t j d
 | | f  | j t d  | t d   t SXt j d |   | j f  PqqWn  |   s| j t d  t d   t St S(   Nc             s~   xw   D]o }   j  |   r  |  } | j rO | j rO t j d | j  n  | j rb | j so  |  j rv t Sq q Wt S(   s{    
            internal helper that checks if at least one meta-pkg is 
            installed or marked install
            s(   metapkg '%s' installed but marked_delete(	   R   R   R   R   R   RJ   R   R5   R+   (   R   RL   (   R0   R   (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   metaPkgInstalled4  s    
R   R   R@  s   Marking '%s' for upgrades    Can't mark '%s' for upgrade (%s)s$   none of the '%s' meta-pkgs installedR   s!   guessing '%s' as missing meta-pkgs$   failed to mark '%s' for install (%s)s   Can't install '%s's}   It was impossible to install a required package. Please report this as a bug using 'ubuntu-bug update-manager' in a terminal.s   marked_install: '%s' -> '%s's   Can't guess meta-packages  Your system does not contain a ubuntu-desktop, kubuntu-desktop, xubuntu-desktop or edubuntu-desktop package and it was not possible to detect which version of Ubuntu you are running.
 Please install one of the packages above first using synaptic or apt-get before proceeding.(   R.   R/   R   R   R   R   R   R   R   R6   R   R5   t   KeyErrorR   R   R+   R   (   R   R)   RA  RL   R   RC   R   (    (   R   R0   s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR  2  sF    	$	c         C   sK   xD |  j  D]9 } t j |  j |  r
 t j d | | f  t Sq
 Wt S(   Ns    blacklist expr '%s' matches '%s'(   R9   t   ret   compilet   matchR   R   R5   R+   (   R   R   t   expr(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR/  }  s
    c   	      C   s  | j  |  j  r' t j d |  t S|  j |  rK t j d |  t SxT |  j j d d  D]= } |  j |  ra |  | j	 | k ra t j d |  t Sqa W|  j |  s t
 Sy |  j j d d  } Wn t j k
 r } t } n Xt j |  j  } | |  j   y |  | j d |  |  j j   xc |  j   D]U } | j | k st| j | k st|  j | j  r>t j d |  |  j   t Sq>WWnD t t f k
 r} t j d	 | t |  | f  |  j   t SXt
 S(
   Ns    skipping running kernel pkg '%s's#   skipping '%s' (in removalBlacklist)R   R   s'   skipping '%s' (in KeepInstalledSection)t   PurgeObsoletest   purges,   package '%s' has unwanted removals, skippings3   _tryMarkObsoleteForRemoval failed for '%s' (%s: %s)(   R   R   R   R   R+   R/  R.   R/   R   R   R5   R   R!  R"  R2   R   Rz   R   t
   markDeleteR)   R  R   RJ   R   R6   RB  R   t   repr(	   R   R   t   remove_candidatest   foreign_pkgsR   RH  RC   R   RL   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   tryMarkObsoleteForRemoval  sD    "


 
c         C   sL   t    } x< |  D]4 } | j r |  j |  sD | j | j  qD q q W| S(   s1    get all package names that are not downloadable (   RA   R   t   anyVersionDownloadableRI   RJ   (   R   t   obsolete_pkgsRL   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   _getObsoletesPkgs  s    		c         C   s(   x! | j  j D] } | j r t Sq Wt S(   sA    helper that checks if any of the version of pkg is downloadable (   RE   R  R   R5   R+   (   R   RL   R   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyRN    s    	c         C   sO   t    } x? |  D]7 } | j r |  j j | j  r | j | j  q q W| S(   s1    get all package names that are not downloadable (   RA   R   Rz   R   RE   RI   RJ   (   R   t   unused_dependenciesRL   (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   _getUnusedDependencies  s
    	c            s   t      |  j j d d  } t j j |  ra t   f d   t d   t |  j	     n  t    } xh   D]` } |  j
 |  s qq n  |  | } | j sq |  j j | j  sq | j r qq n  | j |  qq Wt |  S(   s    return list of installed and demoted packages 

            If a demoted package is a automatic install it will be skipped
        R   t	   Demotionsc            s     j  |  j    S(   N(   RI   R;   (   R   (   t	   demotions(    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR     s    c         S   s   |  j  d  S(   Nt   #(   R   (   R<  (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR     s    (   RA   R.   R=   R>   R^   R_   R   R   Ra   t	   readlinesR   R   Rz   t   is_auto_installedRE   R   RI   RS   (   R   t   demotions_filet   installed_demotionst   demoted_pkgnameRL   (    (   RT  s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   get_installed_demoted_packages  s"    			

	c         C   s   t    } x |  D] } | j r |  j |  r t } x_ | j D]T } | | j k rk | j | k rk t } n  | | j k r> | j | k r> t } q> q> W| r | j | j	  q q q W| S(   sm    get all packages that are installed from a foreign repo
            (and are actually downloadable)
        (
   RA   R   R   R5   t   candidateOrigint   archiveR+  R+   RI   RJ   (   R   t   allowed_origint   fromDistt   toDistRL  RL   t   foreignR+  (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   _getForeignPkgs  s    		c            s_  d t  f d     Y}   f d   } g    i  } i  } x t d  D]t } y" | j   \ } } }	 }
 } } Wn- t k
 r } t j d | | f  qD n X|   k rD   j |  qD qD W  j d d   d t  t	 j
 j d	  } d
 } t |  d  rN|  j j d d t  rN|  j j d d  } t j j |  sNt j |  qNn  t j d |  xd d d d | | d d
 g D] } t j j |  } | |  } t j j |  rt j |  } | t j | t j } n t j d |  d } | | k r1t j d | | | f  | | | | | <q~t j d | | f  | | | <| |  | | <q~W~ t j d |  d } xV |  D]N } t j d | j  r| j rt j d | j t f  | t 7} qqqWd } t |  d  ra|  j j d d t  rat j d  |  j j d d  } x6 |  D]+ } | j sG| j r/| | j  j! 7} q/q/Wn  d } | rx< |  D]4 } | j" rt| j s| j# rt| | j$ j! 7} qtqtWt j d |  n  x | |  j% f d |  j& f d d( f d | f d! d* f d d, f | | f d | f g D]l \ } } t j j |  } t j d$ | | | | | | j' f  | | j' | 8_' | | j( | 7_( qWi  } x| | D]t } | | j' d k  rt	 j) t* t+ | | j'  d%   } t, t	 j) | | j(  | |  |  | | |  <qqWt- |  d k r[t j. d& g  | D] } t/ |  ^ q, t0 | j1     n  t S(-   s   
        this checks if we have enough free space on /var, /boot and /usr
        with the given cache 

        Note: this can not be fully accurate if there are multiple 
              mountpoints for /usr, /var, /boot
        t	   FreeSpacec           B   s   e  Z d  Z d   Z RS(   s@    helper class that represents the free space on each mounted fs c         S   s   | |  _  d |  _ d  S(   Ni    (   t   freeR   (   R   t   initialFree(    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR     s    	(   R   R	   R   R   (    (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyRc  	  s   c            s(   x!   D] } |  j  |  r | Sq Wd S(   s    return 'id' of a directory so that directories on the
                same filesystem get the same id (simply the mount_point)
            t   /(   R   (   t   dt   mount_point(   t   mounted(    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt
   make_fs_id  s    s   /proc/mountss-   line '%s' in /proc/mounts not understood (%s)t   cmpc         S   s   t  t |   t |   S(   N(   Rk  RO   (   t   aR,  (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR   *  s    t   reverses   Dir::Cache::archivess   /tmp/R.   t   Aufst   Enabledt   RWDirs   cache aufs_rw_dir: %sRf  s   /usrs   /vars   /boots   /homes   directory '%s' does not existsi    s   Dir %s mounted on %ss   Free space on %s: %ss   fs_free contains: '%s's%   ^linux-(image|image-debug)-[0-9.]*-.*s,   %s (new-install) added with %s to boot spaceg        s*   taking aufs overlay into space calculations&   additional space for the snapshots: %si2   i   s   /tmpi   i
   s    dir '%s' needs '%s' of '%s' (%f)i   s   Not enough free space: %si   i   i   i  P i (  i   (2   t   objectRa   R   t
   ValueErrorR   R   R   R#  R5   R2   R@   R   Rk   R.   R]   R+   R=   R>   R^   R_   R`   t   realpatht   statvfst   F_BAVAILt   F_FRSIZER   RC  RE  RJ   R   t   KERNEL_INITRD_SIZER   R  t   installed_sizeR   R   R  R   R   Rd  R   t	   SizeToStrt   floatt   absR   RO   R   R7   R   t   values(   R   t   snapshots_in_useRc  Rj  t   mnt_mapt   fs_freeR<  t   whatt   wheret   fst   optionsRl  R,  RC   t
   archivedirt   aufs_rw_dirRg  t   fs_idt   stRd  t   space_in_bootRL   t   required_for_aufst   required_for_snapshotsR   R   t   required_listt   free_at_leastR  (    (   Ri  s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   checkFreeSpace   s    	"%
							(&9*N(=   R   R	   RG   RH   R   R5   R   t   propertyRM   RZ   R<   Rp   Rr   Rx   R   R   R   R4   R   R   R   RR   RV   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R-  R  R7  R>  R?  R  R  R/  RM  RP  RN  RR  R[  Rb  R+   R  (    (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyR   V   sn    					
						
										)						~					K	3					t   __main__t   foot   .s   ubuntu-desktop(3   t   warningst   filterwarningst   FutureWarningR%   R2   R>   t   os.pathRC  R   R   Rt  R  Rg   R  R!  t
   subprocessR   R   t   DistUpgradeGettextR   R   R   t   utilsR   R   R   R   R
   R   R   Rw  Rq  R   R   R&   R   R   t   syst   DistUpgradeConfigParsert   DistUpgradeViewt   DistUpgradeConfigR   t   cR  t   exitR   R   R>  R?  R   R   (    (    (    s@   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeCache.pyt   <module>   sX   		    @


