
Y]C                 @   sS  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 Z d  d l m Z m Z d  d l m Z y) e j e j d  e j   \ Z Z Wn e	 j d  d	 Z Yn Xe s8d	 Z e j d
 d  y e j e j d  Wn e j k
 r7Yn Xe	 j d e j    d d   Z Gd d   d e j j j  Z Gd d   d e j j j   Z  Gd d   d e!  Z" Gd d   d e!  Z# e$ d  d  \ Z% Z& Z' Z( Z) Z* Z+ e d  e d  e d  e d  e d  f Gd d   d e!  Z, e- d k rOe   Z. e. j/   d S)    )gettext)ngettext    N)doAufsChrootdoAufsChrootRsync)apport_pkgfailure zgetting the encoding failedzutf-8LC_CTYPEzC.UTF-8zlocale: '%s' '%s'c             C   s  t  |   }  |  d } |  d d } |  d d } |  d } | d k rN d } d d d d d d d	 d i } | d k r t d
 d |  | | d <| d k r t d d |  | | d <| d k r t d d |  | | d <t d d |  | | d	 <| d k r*| d d k r| d St d  | S| d k r>| d S| d k rp| d d k rb| d St d  | S| d k r| d S| d	 S)z; return the time a bit fuzzy (no seconds if time > 60 secs <      r   r   Zstr_daysr   Z	str_hoursZstr_minutesZstr_secondsz%li dayz%li daysz%li hourz	%li hoursz
%li minutez%li minutesz
%li secondz%li secondsz%(str_days)s %(str_hours)s   z%(str_hours)s %(str_minutes)si  iQ i  )intr   _)ZsecZdaysZhoursZminutesZsecondsmap r   =/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeView.pyFuzzyTimeToStr:   s>    



r   c                   s   e  Z d  Z   f d d   Z   f d d   Z   f d d   Z d d   Z d	   f d
 d  Z d d   Z d d   Z	   S)AcquireProgressc                s    t  t |   j   d |  _ d  S)Ng        )superr   __init__	est_speed)self)	__class__r   r   r      s    zAcquireProgress.__init__c                s;   t  t |   j   d |  _ d |  _ d |  _ d |  _ d  S)Ng        F)r   r   startr   etapercentrelease_file_download_error)r   )r   r   r   r      s
    			zAcquireProgress.startc                s   t  t |   j | | | |  | t j k r t j d |  | j d  s] | j d  r x0 d d d g D] } | j |  rm d |  _	 Pqm Wd  S)Nz update_status: dlFailed on '%s' zRelease.gpgZReleaseZhttpZftpZmirrorT)
r   r   update_statusapt_pkgZSTAT_FAILEDloggingZwarningendswith
startswithr   )r   ZuriZdescrZ
shortDescrZstatusZnet)r   r   r   r      s    	zAcquireProgress.update_statusc             C   s   d S)NTr   )r   argr   r   r   pulse_items   s    zAcquireProgress.pulse_itemsNc                s   t  t |   j |  |  j |  j d t |  j |  j  |  _ |  j	 |  j
 k rj |  j
 |  j	 d |  _
 |  j	 d k r |  j |  j t |  j	  |  _ d S)Ng      Y@g       @r   T)r   r   pulseZcurrent_bytesZcurrent_itemsfloatZtotal_bytesZtotal_itemsr   Zcurrent_cpsr   r   )r   owner)r   r   r   r$      s    zAcquireProgress.pulsec             C   s   |  j  d k S)Nr   )r   )r   r   r   r   isDownloadSpeedEstimated   s    z(AcquireProgress.isDownloadSpeedEstimatedc             C   sj   |  j  d k rI | d } | d
 } t d  t |  t |  f } | St d  t | |  j   } | S)z! get the estimated download time r   8   i      z[This download will take about %s with a 1Mbit DSL connection and about %s with a 56k modem.z7This download will take about %s with your connection. i   g      @i   g       A)r   r   r   )r   Zrequired_downloadZ	timeModemZtimeDSLsr   r   r   estimatedDownloadTime   s    

	z%AcquireProgress.estimatedDownloadTime)
__name__
__module____qualname__r   r   r   r#   r$   r'   r+   r   r   )r   r   r   ~   s   
r   c               @   sF   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 S)InstallProgressz_ Base class for InstallProgress that supports some fancy
      stuff like apport integration
  c             C   s#   t  j j j j |   d  |  _ d  S)N)aptprogressbaser/   r   Z	master_fd)r   r   r   r   r      s    zInstallProgress.__init__c             C   s   x y# t  j  |  j g g  g  |  j  WnA t  j k
 ri } z | j d t j k rW   WYd d } ~ Xn X|  j   y2 t j	 |  j
 t j  \ } } | |  j
 k r PWq t k
 r } z- | j t j k r   | j t j k r PWYd d } ~ Xq Xq W| S)zWait for child progress to exit.

      The return values is the full status returned from os.waitpid()
      (not only the return code).
      r   N)selectZstatusfdZselect_timeouterrorargserrnoZEINTRZupdate_interfaceoswaitpid	child_pidWNOHANGOSErrorZECHILD)r   epidresr   r   r   
wait_child   s"    #
zInstallProgress.wait_childc             C   s  |  j    } | d k rd t j k r[ t t j d t j d  s[ t d  t j d  t j t j t j  y | j	 |  j
  } Wn{ t k
 r} z[ t d |  t j d  t d d	   } | j t |   Wd  QRXt j | j  WYd  d  } ~ Xn Xt j |  | |  _ t j |  j    } | d k rd
 t j k rt j d  t t j d  st j d  | j S| S)Nr   ZRELEASE_UPGRADE_USE_AUFS_CHROOTZRELEASE_UPGRADE_AUFS_RWDIRz*ERROR: failed to setup aufs chroot overlayr   z!Exception during pm.DoInstall(): zException during pm.DoInstall()z./var/run/ubuntu-release-upgrader-apt-exceptionwZ!RELEASE_UPGRADE_RSYNC_AUFS_CHROOTz doing rsync commit of the updatez/FATAL ERROR: doAufsChrootRsync() returned FALSE)forkr7   environr   print_exitsignalSIGPIPESIG_IGNZ
do_installZwritefd	Exceptionr   	exceptionopenwritestrZRESULT_FAILEDr9   WEXITSTATUSr?   infor   r4   )r   Zpmr=   r>   r<   fr   r   r   run   s4    
#	zInstallProgress.runc             C   s   t  j j j j |  | |  t j d | | f  d | k rQ t j j |  } d | k rp | j	 d  d } t
 | |  d S)z install error from a package z*got an error from dpkg for pkg: '%s': '%s'/r   r   N)r0   r1   r2   r/   r4   r   r7   pathbasenamesplitr   )r   pkgZerrormsgr   r   r   r4      s    zInstallProgress.errorN)r,   r-   r.   __doc__r   r?   rP   r4   r   r   r   r   r/      s
   !r/   c               @   s   e  Z d  Z d d d  Z d S)DumbTerminalFc             C   s   d d l  } | j |  d S)z7 expects a command in the subprocess style (as a list) r   N)
subprocesscall)r   cmdZhiddenrX   r   r   r   rY     s    zDumbTerminal.callN)r,   r-   r.   rY   r   r   r   r   rW      s   rW   c               @   s4   e  Z d  Z d d   Z d d   Z d d   Z d S)DummyHtmlViewc             C   s   d  S)Nr   )r   Zurlr   r   r   rJ     s    zDummyHtmlView.openc             C   s   d  S)Nr   )r   r   r   r   show	  s    zDummyHtmlView.showc             C   s   d  S)Nr   )r   r   r   r   hide  s    zDummyHtmlView.hideN)r,   r-   r.   rJ   r\   r]   r   r   r   r   r[     s   r[   r)   zPreparing to upgradezGetting new software channelszGetting new packageszInstalling the upgradeszCleaning upc               @   s  e  Z d  Z 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   Z d d   Z d d   Z d d   Z d d d d  Z d d d  Z d d    Z d d! d"  Z d d# d$  Z d% d&   Z d' d( d)  Z d* d+   Z d S),DistUpgradeViewz" abstraction for the upgrade view c             C   s   d |  _  d  S)NF)Zneeds_screen)r   r   r   r   r   !  s    	zDistUpgradeView.__init__c             C   s   t  j j j   S)z5 return a OpProgress() subclass for the given graphic)r0   r1   r2   Z
OpProgress)r   r   r   r   getOpCacheProgress$  s    z"DistUpgradeView.getOpCacheProgressc             C   s   t    S)z# return an acquire progress object )r   )r   r   r   r   getAcquireProgress'  s    z"DistUpgradeView.getAcquireProgressNc             C   s   t    S)z" return a install progress object )r/   )r   cacher   r   r   getInstallProgress*  s    z"DistUpgradeView.getInstallProgressc             C   s   t    S)N)rW   )r   r   r   r   getTerminal-  s    zDistUpgradeView.getTerminalc             C   s   t    S)N)r[   )r   r   r   r   getHtmlView/  s    zDistUpgradeView.getHtmlViewc             C   s   d S)z\ update the current status of the distUpgrade based
            on the current view
        Nr   )r   msgr   r   r   updateStatus1  s    zDistUpgradeView.updateStatusc             C   s   d S)z8 provide a visual feedback that the upgrade was aborted Nr   )r   r   r   r   abort6  s    zDistUpgradeView.abortc             C   s   d S)z 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
        Nr   )r   stepr   r   r   setStep9  s    	zDistUpgradeView.setStepc             C   s   d S)z" hide a certain step from the GUI Nr   )r   rh   r   r   r   hideStepC  s    zDistUpgradeView.hideStepc             C   s   d S)z" show a certain step from the GUI Nr   )r   rh   r   r   r   showStepF  s    zDistUpgradeView.showStepTc             C   s  d |  _  | |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ x | D] } | j rq |  j j	 |  qO | j
 r |  j j	 |  qO | j r |  j j	 |  qO | j r | j j j | j  r |  j j	 |  q	|  j j	 |  qO | j rO |  j j	 |  qO W|  j |  j |  _ |  j j   |  j j   |  j j   |  j j   |  j j   d } t |  j  t |  j  }	 t |  j  t |  j  }
 t |  j  } t |  j  d k r| t d d t |  j   d t |  j  i 7} | d 7} |	 d k r/| t d d	 |	  |	 7} | d
 7} |
 d k r_| t d d |
  |
 7} | d
 7} | d k r| t d d |  | 7} | d
 7} | d k rt j |  } t | t  r| j t  } | t d  | 7} | |  j   j |  7} | |
 d k rY| |
 |	 d k rY|  j   j   rB| d t d  7} qy| d t d  7} n  |	 d k ry| d t d  7} | |
 |	 d k  rt d  } t d  } |  j | |  d S| |  _  d S)zm display the list of changed packages (apt.Package) and
            return if the user confirms them
        r   
r   zo%(amount)d installed package is no longer supported by Canonical. You can still get support from the community.zq%(amount)d installed packages are no longer supported by Canonical. You can still get support from the community.Zamountz

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

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

%sznInstalling the upgrade can take several hours. Once the download has finished, the process cannot be canceled.z{Fetching and installing the upgrade can take several hours. Once the download has finished, the process cannot be canceled.z.Removing the packages can take several hours. r   z,The software on this computer is up to date.zRThere are no upgrades available for your system. The upgrade will now be canceled.FT) ZconfirmChangesMessage	demotionsZ	toInstallZtoReinstallZ	toUpgradeZtoRemoveZtoRemoveAutoZtoDowngradeZmarked_installappendZmarked_upgradeZmarked_reinstallZmarked_deleteZ_pcacheZ	_depcacheZis_auto_installedZ_pkgZmarked_downgradesortlenr   r   Zsize_to_str
isinstancebytesdecodeENCODINGr   r`   r+   r'   r4   )r   summaryZchangesro   ZdownloadSizeZactionsZremoval_boldrU   re   Zpkgs_removeZ	pkgs_instZpkgs_upgradeZdownloadSizeStrr   r   r   confirmChangesI  s    													&
	
	
	
$	zDistUpgradeView.confirmChangesZNoc             C   s   d S)z0 ask a Yes/No question and return True on 'Yes' Nr   )r   rw   re   defaultr   r   r   askYesNoQuestion  s    z DistUpgradeView.askYesNoQuestionc             C   s(   t  d  } t  d  } |  j | |  S)z2 generic ask about the restart, can be overridden zReboot requiredzMThe upgrade is finished and a reboot is required. Do you want to do this now?)r   rz   )r   rw   re   r   r   r   confirmRestart  s    zDistUpgradeView.confirmRestartc             C   s   d S)z display a error Nr   )r   rw   re   extended_msgr   r   r   r4     s    zDistUpgradeView.errorc             C   s   d S)z display a information msgNr   )r   rw   re   r|   r   r   r   information  s    zDistUpgradeView.informationc             C   s   d S)zQ process gui events (to keep the gui alive during a long
            computation Nr   )r   r   r   r   processEvents  s    zDistUpgradeView.processEventsFc             C   s   d S)zX do a progress pulse (e.g. bounce a bar back and forth, show
          a spinner)
      Nr   )r   Zfinishedr   r   r   pulseProgress  s    zDistUpgradeView.pulseProgressc             C   s    |  j  | | d j |   d S)zr
      show demoted packages to the user, default implementation
      is to just show a information dialog
      rl   N)r}   join)r   rw   re   ro   r   r   r   showDemotions  s    zDistUpgradeView.showDemotions)r,   r-   r.   rV   r   r_   r`   rb   rc   rd   rf   rg   ri   rj   rk   rx   rz   r{   r4   r}   r~   r   r   r   r   r   r   r^     s(   
br^   __main__)0ZDistUpgradeGettextr   r   r   r0   r6   r7   r   Zlocaler   rE   r3   ZDistUpgradeAufsr   r   ZDistUpgradeApportr   	setlocaleLC_ALLZgetdefaultlocalecoderv   rI   putenvr	   r4   rN   Z	getlocaler   r1   r2   r   r/   objectrW   r[   rangeZSTEP_PREPAREZSTEP_MODIFY_SOURCESZ
STEP_FETCHZSTEP_INSTALLZSTEP_CLEANUPZSTEP_REBOOTZSTEP_Nr^   r,   fpr$   r   r   r   r   <module>   sP   D6L$					