o *dC@sddlmZddlmZddlmZddlZddlm Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZze e jde \ZZWn ed d ZYeswd Ze d d z e e jd Wn e jyvYnwed e ddZGdddejj j!Z!Gdddejj j"Z"Gddde#Z$Gddde#Z%Gddde Z&edededededfGdd d e#Z'e(d!kre!Z)e)*dSdS)")gettext)ngettext)getN)Enum)apport_pkgfailurezgetting the encoding failedzutf-8LC_CTYPEzC.UTF-8zlocale: '%s' '%s'cCs*t|}|d}|dd}|dd}|d}|dkrd}ddddd}|dkr3td d |||d <|dkrAtd d |||d<|dkrOtdd|||d<tdd|||d<|dkrm|ddkrg|d Std|S|dkru|dS|dkr|ddkr|dStd|S|dkr|dS|dS)z; return the time a bit fuzzy (no seconds if time > 60 secs iQi<rrr)str_days str_hours str_minutes str_secondsz%li dayz%li daysr z%li hourz %li hoursr z %li minutez %li minutesrz %li secondz %li secondsrz%(str_days)s %(str_hours)sz%(str_hours)s %(str_minutes)s)intr_)secdayshoursminutessecondsmapr=/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeView.pyFuzzyTimeToStr;s@      rcsZeZdZfddZfddZfddZddZdfd d Zd d ZddZ Z S)AcquireProgresscstt|d|_dS)N)superr__init__ est_speedself __class__rrrs zAcquireProgress.__init__cs*tt|d|_d|_d|_d|_dS)NrF)rrstartr etapercentrelease_file_download_errorr!r#rrr%s  zAcquireProgress.startcsntt||||||tjkr1td||ds!|dr3dD]}||r0d|_ dSq#dSdSdS)Nz update_status: dlFailed on '%s' z Release.gpgRelease)httpftpmirrorT) rr update_statusapt_pkg STAT_FAILEDloggingwarningendswith startswithr()r"uridescr shortDescrstatusnetr#rrr-s  zAcquireProgress.update_statuscCdSNTr)r"argrrr pulse_itemszAcquireProgress.pulse_itemsNcsvtt|||j|jdt|j|j|_|j |j kr(|j |j d|_ |j dkr9|j|jt|j |_ dS)NgY@g@rT) rrpulse current_bytes current_itemsfloat total_bytes total_itemsr' current_cpsr r&)r"ownerr#rrr>s   zAcquireProgress.pulsecCs |jdkS)Nr)r r!rrrisDownloadSpeedEstimateds z(AcquireProgress.isDownloadSpeedEstimatedcCsP|jdkr|d}|d}tdt|t|f}|Stdt||j}|S)z! get the estimated download time rg#AgSAz_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 rr)r"required_download time5Mbit time40MbitsrrrestimatedDownloadTimes z%AcquireProgress.estimatedDownloadTimeN) __name__ __module__ __qualname__rr%r-r<r>rFrK __classcell__rrr#rrs    rc@s0eZdZdZddZddZddZdd Zd S) InstallProgressz_ Base class for InstallProgress that supports some fancy stuff like apport integration cCstjjj|d|_dSrL)aptprogressbaserQr master_fdr!rrrrs zInstallProgress.__init__c Cs z t|jggg|jWntjy*}z|jdtjkr WYd}~nd}~ww|zt |j tj \}}||j krBW|SWn&t yi}z|jtjkrR|jtj kr_WYd}~|SWYd}~nd}~wwq)zWait for child progress to exit. The return values is the full status returned from os.waitpid() (not only the return code). TrN)selectstatusfdselect_timeouterrorargserrnoEINTRupdate_interfaceoswaitpid child_pidWNOHANGOSErrorECHILD)r"epidresrrr wait_childs4      zInstallProgress.wait_childc Cs|}|dkr\ttjtjz||j}Wn>tyV}z2td|t dt dd}| t |Wdn1sAwYt |jWYd}~nd}~wwt |||_t |}|S)Nrz!Exception during pm.DoInstall(): zException during pm.DoInstall()z./var/run/ubuntu-release-upgrader-apt-exceptionw)forksignalSIGPIPESIG_IGN do_installwritefd Exceptionprintr0 exceptionopenwritestrr^_exit RESULT_FAILEDr` WEXITSTATUSrg)r"pmrerfrdfrrrruns$    zInstallProgress.runcCstjjj|||td||fd|vrtj|}| dd r2d | ddd}d|vr=| dd}t ||dS)z install error from a package z*got an error from dpkg for pkg: '%s': '%s'/-rrNr) rRrSrTrQrYr0r^pathbasenamesplitisdigitjoinr)r"pkgerrormsgrrrrYs zInstallProgress.errorN)rMrNrO__doc__rrgrzrYrrrrrQs  rQc@seZdZdddZdS) DumbTerminalFcCsddl}||dS)z7 expects a command in the subprocess style (as a list) rN) subprocesscall)r"cmdhiddenrrrrrszDumbTerminal.callNF)rMrNrOrrrrrrsrc@s$eZdZddZddZddZdS)SampleHtmlViewcCdSrLr)r"urlrrrrrr=zSampleHtmlView.opencCrrLrr!rrrshowr=zSampleHtmlView.showcCrrLrr!rrrhider=zSampleHtmlView.hideN)rMrNrOrrrrrrrrrs rc@s(eZdZdZdZdZdZdZdZdZ dS) SteprrN) rMrNrOPREPAREMODIFY_SOURCESFETCHINSTALLCLEANUPREBOOTNrrrrrsrzPreparing to upgradezGetting new software channelszGetting new packageszInstalling the upgradesz Cleaning upc@seZdZdZddZddZddZd3d d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZ d4ddZd5ddZd6d d!Zd"d#Zd$d%Zd&d'Zd3d(d)Zd3d*d+Zd,d-Zd7d/d0Zd1d2ZdS)8DistUpgradeViewz" abstraction for the upgrade view cCs d|_dS)NF) needs_screenr!rrrrszDistUpgradeView.__init__cCs tjjS)z5 return a OpProgress() subclass for the given graphic)rRrSrT OpProgressr!rrrgetOpCacheProgresss z"DistUpgradeView.getOpCacheProgresscCtS)z# return an acquire progress object )rr!rrrgetAcquireProgressz"DistUpgradeView.getAcquireProgressNcCr)z" return a install progress object )rQ)r"cacherrrgetInstallProgress rz"DistUpgradeView.getInstallProgresscCrrL)rr!rrr getTerminal#zDistUpgradeView.getTerminalcCrrL)rr!rrr getHtmlView%rzDistUpgradeView.getHtmlViewcCr9)z\ update the current status of the distUpgrade based on the current view Nr)r"msgrrr updateStatus'zDistUpgradeView.updateStatuscCr9)z8 provide a visual feedback that the upgrade was aborted Nrr!rrrabort,zDistUpgradeView.abortcCst|jdS)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_stagenamer"steprrrsetStep/s zDistUpgradeView.setStepcCr9)z" hide a certain step from the GUI NrrrrrhideStep:rzDistUpgradeView.hideStepcCr9)z" show a certain step from the GUI NrrrrrshowStep=rzDistUpgradeView.showStepTc Csd|_||_g|_g|_g|_g|_g|_g|_|D]B}|jr&|j |q|j r0|j |q|j r:|j |q|j rS|j j|jrL|j |q|j |q|jr\|j |q|j|j|_|j|j|j|j|jd}t|jt|j} t|jt|j} t|j} t|jdkr|tddt|jdt|ji7}|d7}| dkr|tdd | | 7}|d 7}| dkr|td d | | 7}|d 7}| dkr|td d| | 7}|d 7}|dkrt|} t| tr| t} |td| 7}|||7}| | dkr9| | | dkr9|r0|dtd7}n|dtd7}n | dkrF|dtd7}| | | dkr_td}td}|||dS||_dS)zm display the list of changed packages (apt.Package) and return if the user confirms them r rzo%(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. dz %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. rz,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 toUpgradetoRemove toRemoveAuto toDowngrademarked_installappendmarked_upgrademarked_reinstall marked_delete_pcache _depcacheis_auto_installed_pkgmarked_downgradesortlenrr. size_to_str isinstancebytesdecodeENCODINGrrrKrFrY) r"summarychangesr downloadSizeactions removal_boldrr pkgs_remove pkgs_inst pkgs_upgradedownloadSizeStrrrrconfirmChanges@s               zDistUpgradeView.confirmChangesNocCr9)z0 ask a Yes/No question and return True on 'Yes' Nrr"rrdefaultrrraskYesNoQuestionrz DistUpgradeView.askYesNoQuestionCancelcCr9)z= ask a Cancel/Continue question and return True on 'Continue'NrrrrraskCancelContinueQuestionrz)DistUpgradeView.askCancelContinueQuestioncCstd}td}|||S)z2 generic ask about the restart, can be overridden zReboot requiredzMThe upgrade is finished and a reboot is required. Do you want to do this now?)rr)r"rrrrrconfirmRestarts zDistUpgradeView.confirmRestartcC&td}td}td}||||S)NzAction requiredz9Exit all other instances of Ubuntu WSL before continuing.z'Unsaved progress may otherwise be lost.r informationr"rrextendedrrradviseExitOtherWSLz"DistUpgradeView.adviseExitOtherWSLcCr)NzWSL restart requiredz!Exit this instance of Ubuntu WSL.z"The upgrade will then be complete.rrrrradviseRestartWSLrz DistUpgradeView.adviseRestartWSLcCr9)z display a error Nrr"rr extended_msgrrrrYrzDistUpgradeView.errorcCr9)z display a information msgNrrrrrrrzDistUpgradeView.informationcCr9)zQ process gui events (to keep the gui alive during a long computation Nrr!rrr processEventsszDistUpgradeView.processEventsFcCr9)zX do a progress pulse (e.g. bounce a bar back and forth, show a spinner) Nr)r"finishedrrr pulseProgressrzDistUpgradeView.pulseProgresscCs|||d|dS)zr show demoted packages to the user, default implementation is to just show a information dialog rN)rr)r"rrrrrr showDemotionsszDistUpgradeView.showDemotionsrLr:)r)rr)rMrNrOrrrrrrrrrrrrrrrrrrrYrrrrrrrrrs2   c     r__main__)+DistUpgradeGettextrrr telemetryrrrRenumrr[r^r.localer0rjrVDistUpgradeApportr setlocaleLC_ALLgetdefaultlocalecoderrqputenvr rYinfo getlocalerrSrTrrQobjectrrrrrMfpr>rrrrs\       D6@ =