
    ZufC                     `   d dl mZ d dl mZ d dlmZ ddl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 	  ej        ej        d            ej                    \  ZZn#   ej        d	           d
ZY nxY wes;d
Z ej        dd           	  ej        ej        d           n# ej        $ r Y nw xY w ej        d ej                    z             d Z G d dej        j         j!                  Z! G d dej        j         j"                  Z" G d de#          Z$ G d de#          Z% G d de	          Z& ed           ed           ed           ed           ed          f  G d de#          Z'e(d k    r  e!            Z)e)*                                 dS dS )!   )gettext)ngettext)get    N)Enum)apport_pkgfailure zgetting the encoding failedzutf-8LC_CTYPEzC.UTF-8zlocale: '%s' '%s'c                 F   t          |           } | dz  }| dz  dz  }| dz  dz  }| dz  }|dk    rd}ddddd}|dk    rt          d	d
|          |z  |d<   |dk    rt          dd|          |z  |d<   |dk    rt          dd|          |z  |d<   t          dd|          |z  |d<   |dk    r&|d         dk    r|d         S t          d          |z  S |dk    r|d         S |dk    r&|d         dk    r|d         S t          d          |z  S |dk    r|d         S |d         S )z; return the time a bit fuzzy (no seconds if time > 60 secs iQ i     <   r   r   r	   )str_days	str_hoursstr_minutesstr_secondsz%li dayz%li daysr   z%li hourz	%li hoursr   z
%li minutez%li minutesr   z
%li secondz%li secondsr   z%(str_days)s %(str_hours)s   z%(str_hours)s %(str_minutes)s)intr   _)secdayshoursminutessecondsmaps         N/home/let_prod/public_html/lightetech2/upgrader/DistUpgrade/DistUpgradeView.pyFuzzyTimeToStrr   ;   s    	C#	x$
,
%"WN'"H'\\G 	
 	
# 
AXXyT::TAC
O
QYY
;>>FCq[[!,}gFFPC]GDDwN#m 
AXX
;2: )**S00qyy{qyy
=R; ,--33{{}	]	    c                   P     e Zd Z fdZ fdZ fdZd Zd	 fd	Zd Zd Z	 xZ
S )
AcquireProgressc                 d    t          t          |                                            d| _        d S )N        )superr   __init__	est_speedself	__class__s    r   r#   zAcquireProgress.__init__   s*    	/4  ))+++DNNNr   c                     t          t          |                                            d| _        d| _        d| _        d| _        d S )Nr!   F)r"   r   startr$   etapercentrelease_file_download_errorr%   s    r   r)   zAcquireProgress.start   sB    	/4  &&(((DNDHDL',D$$$r   c                 P   t          t          |                               ||||           |t          j        k    ret          j        d|z             |                    d          s|                    d          r&dD ]%}|                    |          r
d| _	         d S "d S d S d S )Nz update_status: dlFailed on '%s' zRelease.gpgRelease)httpftpmirrorT)
r"   r   update_statusapt_pkgSTAT_FAILEDloggingwarningendswith
startswithr,   )r&   uridescr
shortDescrstatusnetr'   s         r   r2   zAcquireProgress.update_status   s    	/4  ..sE:vNNN $$$o83>???	m	$	$ Y(?(?  + 	 	C^^C   /3D,EE %$ 	 	r   c                     dS NT )r&   args     r   pulse_itemszAcquireProgress.pulse_items   s    4r   Nc                 v   t          t          |                               |           | j        | j        z   dz  t          | j        | j        z             z  | _        | j	        | j
        k    r| j
        | j	        z   dz  | _
        | j	        dk    r)| j        | j        z
  t          | j	                  z  | _        dS )Ng      Y@g       @r   T)r"   r   pulsecurrent_bytescurrent_itemsfloattotal_bytestotal_itemsr+   current_cpsr$   r*   )r&   ownerr'   s     r   rD   zAcquireProgress.pulse   s    	/4  &&u---(4+==F$*T-==>>?DL$.((t'77<dn!#d&88())*dh4r   c                     | j         dk    S )Nr   )r$   r&   s    r   isDownloadSpeedEstimatedz(AcquireProgress.isDownloadSpeedEstimated   s    Na r   c                     | j         dk    r:|dz  }|dz  }t          d          t          |          t          |          fz  }|S t          d          t          || j         z            z  }|S )z! get the estimated download time r   g    #Ag    SAz_This download will take about %s with a 40Mbit connection and about %s with a 5Mbit connection.z7This download will take about %s with your connection. )r$   r   r   )r&   required_download	time5Mbit
time40Mbitss        r   estimatedDownloadTimez%AcquireProgress.estimatedDownloadTime   s    ~#]3i$n5j	
 3 
4 
47Ej7Q7QSabkSlSl6m
nah	
CDD~VghlhvVvGwGwwAHr   N)__name__
__module____qualname__r#   r)   r2   rB   rD   rN   rT   __classcell__)r'   s   @r   r   r      s            - - - - -      	 	 	 	 	 	! ! !
 
 
 
 
 
 
r   r   c                   *    e Zd ZdZd Zd Zd Zd ZdS )InstallProgressz_ Base class for InstallProgress that supports some fancy
      stuff like apport integration
  c                 f    t           j        j        j                            |            d | _        d S rU   )aptprogressbaser[   r#   	master_fdrM   s    r   r#   zInstallProgress.__init__   s)    L%..t444DNNNr   c                    	 	 t          j         | j        gg g | j                   n8# t           j        $ r&}|j        d         t
          j        k    r Y d}~nd}~ww xY w|                                  	 t          j	        | j
        t          j                  \  }}|| j
        k    rnInG# t          $ r:}|j        t
          j        k    r |j        t
          j        k    rY d}~nY d}~nd}~ww xY w|S )zWait for child progress to exit.

      The return values is the full status returned from os.waitpid()
      (not only the return code).
      Tr   N)selectstatusfdselect_timeouterrorargserrnoEINTRupdate_interfaceoswaitpid	child_pidWNOHANGOSErrorECHILD)r&   epidress       r   
wait_childzInstallProgress.wait_child   s#   mT]ORT5HIIII   ek)) *)))) 


!
!
!:dnbjAAjsC&& '   EK''EL((%%%% )((((  js,   "& AAA32B' '
C+1+C&&C+c                    |                                  }|dk    rt          j        t          j        t          j                   	 |                    | j                  }n# t          $ r}t          d|           t          j	        d           t          dd          5 }|                    t          |                     d d d            n# 1 swxY w Y   t          j        |j                   Y d }~nd }~ww xY wt          j        |           || _        t          j        |                                           }|S )Nr   z!Exception during pm.DoInstall(): zException during pm.DoInstall()z./var/run/ubuntu-release-upgrader-apt-exceptionw)forksignalSIGPIPESIG_IGN
do_installwritefd	Exceptionprintr5   	exceptionopenwritestrrj   _exitRESULT_FAILEDrl   WEXITSTATUSrs   )r&   pmrq   rr   rp   fs         r   runzInstallProgress.run   sZ   
))++C
axx mFN6>222#mmDL)) # # #11555;<<<B3GG 	1GGCFFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
!""""""""# 	hsmmmDN
.**
+
+CJs<   A   
C;*4C6#CC6C	C6C	C66C;c                    t           j        j        j                            | ||           t          j        d|d|d           d|v rt          j                            |          }|	                    d          d         
                                r0d                    |	                    d          dd                   }d	|v r|	                    d	          d         }t          ||           dS )
z install error from a package z!got an error from dpkg for pkg: 'z': ''/-r   r   Nr   )r]   r^   r_   r[   re   r5   rj   pathbasenamesplitisdigitjoinr   )r&   pkgerrormsgs      r   re   zInstallProgress.error   s    L%++D#x@@@MM###xxxPQQQ
czzGS!!c
yy~~a  "" +JJsyy~~abb)**c
czzIIcNN1cc8$$$$$r   N)rV   rW   rX   __doc__r#   rs   r   re   r@   r   r   r[   r[      sZ             0  &% % % % %r   r[   c                       e Zd ZddZdS )DumbTerminalFc                 8    ddl }|                    |           dS )z7 expects a command in the subprocess style (as a list) r   N)
subprocesscall)r&   cmdhiddenr   s       r   r   zDumbTerminal.call   s&    r   NF)rV   rW   rX   r   r@   r   r   r   r      s(             r   r   c                        e Zd Zd Zd Zd ZdS )SampleHtmlViewc                     d S rU   r@   )r&   urls     r   r   zSampleHtmlView.open   s    r   c                     d S rU   r@   rM   s    r   showzSampleHtmlView.show       
dr   c                     d S rU   r@   rM   s    r   hidezSampleHtmlView.hide   r   r   N)rV   rW   rX   r   r   r   r@   r   r   r   r      sA                r   r   c                   *    e Zd ZdZdZdZdZdZdZdZ	dS )	Stepr      r               N)
rV   rW   rX   PREPAREMODIFY_SOURCESFETCHINSTALLCLEANUPREBOOTNr@   r   r   r   r     s1        GNEGGF	AAAr   r   zPreparing to upgradezGetting new software channelszGetting new packageszInstalling the upgradeszCleaning upc                       e Zd 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dZddZd dZd Zd Zd ZddZddZd Zd!dZd ZdS )"DistUpgradeViewz" abstraction for the upgrade view c                     d| _         d S )NF)needs_screenrM   s    r   r#   zDistUpgradeView.__init__  s    !r   c                 H    t           j        j                                        S )z5 return a OpProgress() subclass for the given graphic)r]   r^   r_   
OpProgressrM   s    r   getOpCacheProgressz"DistUpgradeView.getOpCacheProgress  s    | ++---r   c                     t                      S )z# return an acquire progress object )r   rM   s    r   getAcquireProgressz"DistUpgradeView.getAcquireProgress         r   Nc                     t                      S )z" return a install progress object )r[   )r&   caches     r   getInstallProgressz"DistUpgradeView.getInstallProgress   r   r   c                     t                      S rU   )r   rM   s    r   getTerminalzDistUpgradeView.getTerminal#  s    ~~r   c                     t                      S rU   )r   rM   s    r   getHtmlViewzDistUpgradeView.getHtmlView%  s    r   c                     dS )z\ update the current status of the distUpgrade based
            on the current view
        Nr@   )r&   msgs     r   updateStatuszDistUpgradeView.updateStatus'  s	     	r   c                     dS )z8 provide a visual feedback that the upgrade was aborted Nr@   rM   s    r   abortzDistUpgradeView.abort,      r   c                 R    t                                          |j                   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
        N)get_telemetry	add_stagenamer&   steps     r   setStepzDistUpgradeView.setStep/  s#     	!!$),,,r   c                     dS )z" hide a certain step from the GUI Nr@   r   s     r   hideStepzDistUpgradeView.hideStep:  r   r   c                     dS )z" show a certain step from the GUI Nr@   r   s     r   showStepzDistUpgradeView.showStep=  r   r   Tc                 h   d| _         || _        g | _        g | _        g | _        g | _        g | _        g | _        |D ]}|j        r| j        	                    |           $|j
        r| j        	                    |           F|j        r| j        	                    |           h|j        rZ|j        j                            |j                  r| j        	                    |           | j        	                    |           |j        r| j        	                    |           | j        | j        z   | _        | j                                         | j                                         | j                                         | j                                         | j                                         d}t'          | j                  t'          | j                  z   }	t'          | j                  t'          | j                  z   }
t'          | j                  }t'          | j                  dk    rB|t)          ddt'          | j                            dt'          | j                  iz  z  }|dz  }|	dk    r|t)          dd	|	          |	z  z  }|d
z  }|
dk    r|t)          dd|
          |
z  z  }|d
z  }|dk    r|t)          dd|          |z  z  }|d
z  }|dk    rt+          j        |          }t/          |t0                    r|                    t4                    }|t7          d          |z  z  }||                                                     |          z  }||
z   dk    r^||
z   |	z   dk    rR|                                                                 r|dt7          d          z  z  }n1|dt7          d          z  z  }n|	dk    r|dt7          d          z  z  }||
z   |	z   dk     r6t7          d          }t7          d          }|                     ||           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.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) confirmChangesMessage	demotions	toInstalltoReinstall	toUpgradetoRemovetoRemoveAutotoDowngrademarked_installappendmarked_upgrademarked_reinstallmarked_delete_pcache	_depcacheis_auto_installed_pkgmarked_downgradesortlenr   r3   size_to_str
isinstancebytesdecodeENCODINGr   r   rT   rN   re   )r&   summarychangesr   downloadSizeactionsremoval_boldr   r   pkgs_remove	pkgs_instpkgs_upgradedownloadSizeStrs                r   confirmChangeszDistUpgradeView.confirmChanges@  s   
 &("" 	+ 	+C! +n##C((((# 
+n##C((((% +%%c****" +&88BB *!((----$$S))))% +%%c***$*::   $-((3t/@+A+AA''#d.>*?*??	4>**t~""
<G! !
 &.DN0C0C#EF F# -#?? >@%' ')45 5# *#q==
 '''02 2 5>> ># *#!
?A&( (*67 7# )#!#/==/// A / 6 6x @ @o
=>> #
((**@@NN
N#I%**,2J[2X\_1_1_$$&&??AA R8a "Q R R R RCC 8a "Q R R R RCC 38a "< = = = =C 9${2a77DEE' 6 7 7#
**Wc
"
"
"%("tr   Noc                     dS )z0 ask a Yes/No question and return True on 'Yes' Nr@   r&   r   r   defaults       r   askYesNoQuestionz DistUpgradeView.askYesNoQuestion  r   r   Cancelc                     dS )z= ask a Cancel/Continue question and return True on 'Continue'Nr@   r   s       r   askCancelContinueQuestionz)DistUpgradeView.askCancelContinueQuestion  r   r   c                 j    t          d          }t          d          }|                     ||          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   r  )r&   r   r   s      r   confirmRestartzDistUpgradeView.confirmRestart  s<    %&&    $$Wc222r   c                     t          d          }t          d          }t          d          }|                     |||          S )NzAction requiredz9Exit all other instances of Ubuntu WSL before continuing.z'Unsaved progress may otherwise be lost.r   informationr&   r   r   extendeds       r   adviseExitOtherWSLz"DistUpgradeView.adviseExitOtherWSL  sD    %&&KLL>??h777r   c                     t          d          }t          d          }t          d          }|                     |||          S )NzWSL restart requiredz!Exit this instance of Ubuntu WSL.z"The upgrade will then be complete.r  r
  s       r   adviseRestartWSLz DistUpgradeView.adviseRestartWSL  sD    *++3449::h777r   c                     dS )z display a error Nr@   r&   r   r   extended_msgs       r   re   zDistUpgradeView.error  r   r   c                     dS )z display a information msgNr@   r  s       r   r	  zDistUpgradeView.information  r   r   c                     dS )zQ process gui events (to keep the gui alive during a long
            computation Nr@   rM   s    r   processEventszDistUpgradeView.processEvents  s	     	r   Fc                     dS )zX do a progress pulse (e.g. bounce a bar back and forth, show
          a spinner)
      Nr@   )r&   finisheds     r   pulseProgresszDistUpgradeView.pulseProgress  s	     dr   c                 Z    |                      ||d                    |                     dS )zr
      show demoted packages to the user, default implementation
      is to just show a information dialog
      r   N)r	  r   )r&   r   r   r   s       r   showDemotionszDistUpgradeView.showDemotions  s.    
 wTYYy%9%9:::::r   rU   r?   )r   )r  r   )rV   rW   rX   r   r#   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  re   r	  r  r  r  r@   r   r   r   r     s       ((  . . .! ! !! ! ! !         
  
 
 
     37a a a aF      3 3 38 8 8
8 8 8
           
; ; ; ; ;r   r   __main__)+DistUpgradeGettextr   r   r   	telemetryr   r   r]   enumr   rg   rj   r3   localer5   rw   rb   DistUpgradeApportr   	setlocaleLC_ALLgetdefaultlocalecoder   r~   putenvr
   re   info	getlocaler   r^   r_   r   r[   objectr   r   r   r   rV   fprD   r@   r   r   <module>r)     s:  , - , , , , , ( ( ( ( ( ( + + + + + + 



        				      0 0 0 0 0 0FV]B'''.v.00T88G3444HHH  HBIj)$$$)4444<   
  #36#3#5#55 6 6 6A A AH2 2 2 2 2cl'7 2 2 2l>% >% >% >% >%cl'7 >% >% >%@    6       V   
 
 
 
 
4 
 
 
 !!#$$!!!M	 z; z; z; z; z;f z; z; z;x z"((***** s    (A) )A?B/ /
B<;B<