
QNc           @   s  d  d l  m Z d  d l  m 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   Z d e j j j f d     YZ d	 e j j j f d
     YZ d e f d     YZ d e f d     YZ e d d  \ Z Z Z Z Z Z Z  e d  e d  e d  e d  e d  f d e f d     YZ! e" d k re   Z# e# j$   n  d S(   i(   t   gettext(   t   ngettextN(   t   doAufsChroott   doAufsChrootRsync(   t   apport_pkgfailurec         C   s  t  |   }  |  d } |  d d } |  d d } |  d } | d k rQ d } n  i d d 6d d 6d d 6d d	 6} | d k r t d
 d |  | | d <n  | d k r t d d |  | | d <n  | d k r t d d |  | | d <n  t d d |  | | d	 <| d k r:| d d k r,| d St d  | S| d k rN| d S| d k r| d d k rr| d St d  | S| d k r| d S| d	 S(   s;    return the time a bit fuzzy (no seconds if time > 60 secs i<   i   i    i   t    t   str_dayst	   str_hourst   str_minutest   str_secondss   %li days   %li dayss   %li hours	   %li hourss
   %li minutes   %li minutess
   %li seconds   %li secondss   %(str_days)s %(str_hours)si   s   %(str_hours)s %(str_minutes)si  iQ i  (   t   intR   t   _(   t   sect   dayst   hourst   minutest   secondst   map(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   FuzzyTimeToStr$   s>    

	



t   FetchProgressc           B   sA   e  Z d    Z d   Z d   Z d   Z d d  Z d   Z RS(   c         C   s    t  t |   j   d |  _ d  S(   Ng        (   t   superR   t   __init__t	   est_speed(   t   self(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyR   j   s    c         C   s;   t  t |   j   d |  _ d |  _ d |  _ t |  _ d  S(   Ng        (   R   R   t   startR   t   etat   percentt   Falset   release_file_download_error(   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyR   m   s
    			c         C   s   t  t |   j | | | |  | t j k r t j d |  | j d  s] | j d  r x6 d d d g D]" } | j |  rm t	 |  _
 Pqm qm Wq n  d  S(   Ns    update_status: dlFailed on '%s' s   Release.gpgt   Releaset   httpt   ftpt   mirror(   R   R   t   update_statust   apt_pkgt   STAT_FAILEDt   loggingt   warnt   endswitht
   startswitht   TrueR   (   R   t   urit   descrt
   shortDescrt   statust   net(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyR!   s   s    	c         C   s   t  S(   N(   R(   (   R   t   arg(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   pulse_items   s    c         C   s   t  t |   j |  |  j |  j d t |  j |  j  |  _ |  j	 |  j
 k rm |  j
 |  j	 d |  _
 n  |  j	 d k r |  j |  j t |  j	  |  _ n  t S(   Ng      Y@g       @i    (   R   R   t   pulset   current_bytest   current_itemst   floatt   total_bytest   total_itemsR   t   current_cpsR   R   R(   (   R   t   owner(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyR0      s    c         C   sr   |  j  d k rQ | d d } | d d } t d  t |  t |  f } | St d  t | |  j   } | S(	   s!    get the estimated download time i    i8   i   i   s[   This download will take about %s with a 1Mbit DSL connection and about %s with a 56k modem.s7   This download will take about %s with your connection. i   i   (   R   R   R   (   R   t   requiredDownloadt	   timeModemt   timeDSLt   s(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   estimatedDownloadTime   s    	N(	   t   __name__t
   __module__R   R   R!   R/   t   NoneR0   R<   (    (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyR   h   s   				
t   InstallProgressc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s_    Base class for InstallProgress that supports some fancy
      stuff like apport integration
  c         C   s#   t  j j j j |   d  |  _ d  S(   N(   t   aptt   progresst   baseR@   R   R?   t	   master_fd(   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyR      s    c         C   s   x t  r y# t j |  j g g  g  |  j  Wn1 t j k
 r_ \ } } | t j k r`   q` n X|  j   y5 t j	 |  j
 t j  \ } } | |  j
 k r Pn  Wq t k
 r \ } } | t j k r   n  | t j k r Pq q Xq W| S(   s   Wait for child progress to exit.

      The return values is the full status returned from os.waitpid()
      (not only the return code).
      (   R(   t   selectt   statusfdt   select_timeoutt   errort   errnot   EINTRt   update_interfacet   ost   waitpidt	   child_pidt   WNOHANGt   OSErrort   ECHILD(   R   t   errno_t   errstrt   pidt   res(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt
   wait_child   s"    	#

c         C   sd  |  j    } | d k r d t j k r\ t t j d t j d  s\ d GHt j d  q\ n  t j t j t j  y | j |  j	  } WnU t
 k
 r } d G| GHt j d  t d d	  j t |   t j | j  n Xt j |  n  | |  _ t j |  j    } | d k r`d
 t j k r`t j d  t t j d  s`t j d  | j Sn  | S(   Ni    t   RELEASE_UPGRADE_USE_AUFS_CHROOTt   RELEASE_UPGRADE_AUFS_RWDIRs*   ERROR: failed to setup aufs chroot overlayi   s!   Exception during pm.DoInstall(): s   Exception during pm.DoInstall()s%   /var/run/update-manager-apt-exceptiont   wt!   RELEASE_UPGRADE_RSYNC_AUFS_CHROOTs    doing rsync commit of the updates/   FATAL ERROR: doAufsChrootRsync() returned FALSE(   t   forkRL   t   environR   t   _exitt   signalt   SIGPIPEt   SIG_IGNt
   do_installt   writefdt	   ExceptionR$   t	   exceptiont   opent   writet   strt   ResultFailedRN   t   WEXITSTATUSRV   t   infoR   RH   (   R   t   pmRT   RU   t   e(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   run   s2    		
c         C   s   t  j j j j |  | |  t j d | | f  d | k rT t j j |  } n  d | k rv | j	 d  d } n  t
 | |  d S(   s    install error from a package s*   got an error from dpkg for pkg: '%s': '%s't   /R   i    N(   RA   RB   RC   R@   RH   R$   RL   t   patht   basenamet   splitR   (   R   t   pkgt   errormsg(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyRH      s    (   R=   R>   t   __doc__R   RV   Rm   RH   (    (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyR@      s
   			 t   DumbTerminalc           B   s   e  Z e d   Z RS(   c         C   s   d d l  } | j |  d S(   s7    expects a command in the subprocess style (as a list) iN(   t
   subprocesst   call(   R   t   cmdt   hiddenRv   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyRw      s    (   R=   R>   R   Rw   (    (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyRu      s   t   DummyHtmlViewc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   d  S(   N(    (   R   t   url(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyRe      s    c         C   s   d  S(   N(    (   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   show   s    c         C   s   d  S(   N(    (   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   hide   s    (   R=   R>   Re   R|   R}   (    (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyRz      s   		i   i   s   Preparing to upgrades   Getting new software channelss   Getting new packagess   Installing the upgradess   Cleaning upt   DistUpgradeViewc           B   s   e  Z d  Z d   Z d   Z d   Z d d  Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d e d  Z d d  Z d   Z d d  Z d d  Z d   Z e d  Z d   Z RS(   s"    abstraction for the upgrade view c         C   s   t  |  _ d  S(   N(   R   t   needs_screen(   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyR     s    	c         C   s   t  j j j   S(   s5    return a OpProgress() subclass for the given graphic(   RA   RB   RC   t
   OpProgress(   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   getOpCacheProgress	  s    c         C   s   t    S(   s     return a fetch progress object (   R   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   getFetchProgress  s    c         C   s   t    S(   s"    return a install progress object (   R@   (   R   t   cache(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   getInstallProgress  s    c         C   s   t    S(   N(   Ru   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   getTerminal  s    c         C   s   t    S(   N(   Rz   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   getHtmlView  s    c         C   s   d S(   s\    update the current status of the distUpgrade based
            on the current view
        N(    (   R   t   msg(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   updateStatus  s    c         C   s   d S(   s8    provide a visual feedback that the upgrade was aborted N(    (   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   abort  s    c         C   s   d S(   s    we have 6 steps current for a upgrade:
        1. Analyzing the system
        2. Updating repository information
        3. fetch packages
        3. Performing the upgrade
        4. Post upgrade stuff
        5. Complete
        N(    (   R   t   step(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   setStep  s    	c         C   s   d S(   s"    hide a certain step from the GUI N(    (   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   hideStep(  s    c         C   s   d S(   s"    show a certain step from the GUI N(    (   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   showStep+  s    c         C   sl  d |  _  | |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ x | D] } | j rh |  j j |  qF | j	 r |  j j |  qF | j
 r | j j j | j  r |  j j |  q |  j j |  qF | j rF |  j j |  qF qF W|  j j   |  j j   |  j j   |  j j   |  j j   t |  j  t |  j  t |  j  t |  j  t |  j  t |  k st  d } t |  j  t |  j  }	 t |  j  }
 t |  j  } t |  j  d k r| t d d t |  j   i t |  j  d 67} | d 7} n  |	 d k rI| t d d	 |	  |	 7} | d
 7} n  |
 d k r|| t d d |
  |
 7} | d
 7} n  | d k r| t d d |  | 7} | d
 7} n  | d k r| t d  t j |  7} | |  j   j |  7} n  | |
 |	 d k r| d t d  7} n  | |
 |	 d k  r_t d  } t d  } |  j | |  t S| |  _  t S(   sm    display the list of changed packages (apt.Package) and
            return if the user confirms them
        R   s   
i    so   %(amount)d installed package is no longer supported by Canonical. You can still get support from the community.sq   %(amount)d installed packages are no longer supported by Canonical. You can still get support from the community.t   amounts   

s"   %d package is going to be removed.s$   %d packages are going to be removed.t    s(   %d new package is going to be installed.s*   %d new packages are going to be installed.s#   %d package is going to be upgraded.s%   %d packages are going to be upgraded.s&   

You have to download a total of %s. id   s   

%ss|   Fetching and installing the upgrade can take several hours. Once the download has finished, the process cannot be cancelled.i   s   Your system is up-to-datesR   There are no upgrades available for your system. The upgrade will now be canceled.(   t   confirmChangesMessaget	   demotionst	   toInstallt	   toUpgradet   toRemovet   toRemoveAutot   toDowngradet   marked_installt   appendt   marked_upgradet   marked_deletet   _pcachet	   _depcachet   is_auto_installedt   _pkgt   marked_downgradet   sortt   lent   AssertionErrorR   R   R"   t	   SizeToStrR   R<   RH   R   R(   (   R   t   summaryt   changesR   t   downloadSizet   actionst   removal_boldRr   R   t   pkgs_removet	   pkgs_instt   pkgs_upgrade(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   confirmChanges.  s|    											U'				t   Noc         C   s   d S(   s0    ask a Yes/No question and return True on 'Yes' N(    (   R   R   R   t   default(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   askYesNoQuestion  s    c         C   s(   t  d  } t  d  } |  j | |  S(   s2    generic ask about the restart, can be overridden s   Reboot requiredsM   The upgrade is finished and a reboot is required. Do you want to do this now?(   R   R   (   R   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   confirmRestart  s    c         C   s   d S(   s    display a error N(    (   R   R   R   t   extended_msg(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyRH     s    c         C   s   d S(   s    display a information msgN(    (   R   R   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   information  s    c         C   s   d S(   sQ    process gui events (to keep the gui alive during a long
            computation N(    (   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   processEvents  s    c         C   s   d S(   sX    do a progress pulse (e.g. bounce a bar back and forth, show
          a spinner)
      N(    (   R   t   finished(    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   pulseProgress  s    c         C   s    |  j  | | d j |   d S(   sr   
      show demoted packages to the user, default implementation
      is to just show a information dialog
      s   
N(   R   t   join(   R   R   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   showDemotions  s    N(   R=   R>   Rt   R   R   R   R?   R   R   R   R   R   R   R   R   R(   R   R   R   RH   R   R   R   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyR~     s(   								
		S		t   __main__(%   t   DistUpgradeGettextR    R   R   RA   RI   RL   R"   R$   R^   RE   t   DistUpgradeAufsR   R   t   DistUpgradeApportR   R   RB   RC   t   AcquireProgressR   R@   t   objectRu   Rz   t   ranget   STEP_PREPAREt   STEP_MODIFY_SOURCESt
   STEP_FETCHt   STEP_INSTALLt   STEP_CLEANUPt   STEP_REBOOTt   STEP_NR~   R=   t   fpR0   (    (    (    s?   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeView.pyt   <module>   s2   	D4K$					