+eTjC @sSddlmZmZddlmZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlmZmZddlmZy)e je jde j\ZZWne jd d ZYnXes5d Ze jd d e je jd ne jd e jddZGdddejj j!Z!Gdddejj j"Z"Gddde#Z$Gddde#Z%e&dd\Z'Z(Z)Z*Z+Z,Z-edededededfGddde#Z.e/d krOe!Z0e0j1ndS)!)absolute_importprint_function)gettext)ngettextN) doAufsChrootdoAufsChrootRsync)apport_pkgfailurezgetting the encoding failedzutf-8LC_CTYPEzC.UTF-8zlocale: '%s' '%s'cCst|}|d}|dd}|dd}|d}|dkrQd}nidd6dd6dd6dd 6}|dkrtd d |||d 60 secs <rrr Zstr_daysZ 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)sz%(str_hours)s %(str_minutes)siiQi)intr_)ZsecZdaysZhoursZminutesZsecondsmapr=/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeView.pyFuzzyTimeToStr8s>                rcseZdZfddZfddZfddZddZd fd d Zd d ZddZ S)AcquireProgresscs tt|jd|_dS)Ng)superr__init__ est_speed)self) __class__rrr~szAcquireProgress.__init__cs;tt|jd|_d|_d|_d|_dS)NgF)rrstartretapercentrelease_file_download_error)r)rrrrs    zAcquireProgress.startcstt|j|||||tjkrtjd||jds]|jdrx6dddgD]"}|j|rmd|_ PqmqmWqndS)Nz update_status: dlFailed on '%s' z Release.gpgZReleaseZhttpZftpZmirrorT) rr update_statusapt_pkgZ STAT_FAILEDloggingwarnendswith startswithr)rZuriZdescrZ shortDescrZstatusZnet)rrrrs zAcquireProgress.update_statuscCsdS)NTr)rargrrr pulse_itemsszAcquireProgress.pulse_itemsNcstt|j||j|jdt|j|j|_|j |j krm|j |j d|_ n|j dkr|j|jt|j |_ ndS)NgY@g@rT) rrpulseZ current_bytesZ current_itemsfloatZ total_bytesZ total_itemsrZ current_cpsrr)rowner)rrrr's zAcquireProgress.pulsecCs |jdkS)Nr)r)rrrrisDownloadSpeedEstimatedsz(AcquireProgress.isDownloadSpeedEstimatedcCsj|jdkrI|d}|d }tdt|t|f}|Stdt||j}|S) z! get the estimated download time r8iz[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. ig@igA)rrr)rZrequired_downloadZ timeModemZtimeDSLsrrrestimatedDownloadTimes   z%AcquireProgress.estimatedDownloadTime) __name__ __module__ __qualname__rrrr&r'r*r.rr)rrr|s   rc@sFeZdZdZddZddZddZdd Zd S) InstallProgressz_ Base class for InstallProgress that supports some fancy stuff like apport integration cCs#tjjjj|d|_dS)N)aptprogressbaser2rZ master_fd)rrrrrszInstallProgress.__init__cCs xy#tj|jggg|jWnDtjk rl}z!|jdtjkrZnWYdd}~XnX|jy5tj |j tj \}}||j krPnWqt k r}z3|jtjkrn|jtj krPnWYdd}~XqXqW|S)zWait for child progress to exit. The return values is the full status returned from os.waitpid() (not only the return code). rN)selectZstatusfdZselect_timeouterrorargserrnoZEINTRZupdate_interfaceoswaitpid child_pidWNOHANGOSErrorZECHILD)repidresrrr wait_childs"# zInstallProgress.wait_childcCs|j}|dkr dtjkrattjdtjdsatdtjdqantjtjtjy|j |j }Wnkt k r}zKtd|t j dtdd jt|tj|jWYdd}~XnXtj|n||_tj|j}|dkr{d tjkr{t jd ttjds{t jd |jSn|S) NrZRELEASE_UPGRADE_USE_AUFS_CHROOTZRELEASE_UPGRADE_AUFS_RWDIRz*ERROR: failed to setup aufs chroot overlayrz!Exception during pm.DoInstall(): zException during pm.DoInstall()z./var/run/ubuntu-release-upgrader-apt-exceptionwZ!RELEASE_UPGRADE_RSYNC_AUFS_CHROOTz doing rsync commit of the updatez/FATAL ERROR: doAufsChrootRsync() returned FALSE)forkr:environrprint_exitsignalSIGPIPESIG_IGNZ do_installZwritefd Exceptionr! exceptionopenwritestrZ ResultFailedr< WEXITSTATUSrBinforr7)rZpmr@rAr?rrrruns2      #     zInstallProgress.runcCstjjjj|||tjd||fd|krTtjj|}nd|krv|j dd}nt ||dS)z install error from a package z*got an error from dpkg for pkg: '%s': '%s'/rrN) r3r4r5r2r7r!r:pathbasenamesplitr )rpkgZerrormsgrrrr7s  zInstallProgress.errorN)r/r0r1__doc__rrBrRr7rrrrr2s    r2c@seZdZdddZdS) DumbTerminalFcCsddl}|j|dS)z7 expects a command in the subprocess style (as a list) rN) subprocesscall)rcmdZhiddenrZrrrr[s zDumbTerminal.callN)r/r0r1r[rrrrrYs rYc@s4eZdZddZddZddZdS) DummyHtmlViewcCsdS)Nr)rZurlrrrrMszDummyHtmlView.opencCsdS)Nr)rrrrshowszDummyHtmlView.showcCsdS)Nr)rrrrhideszDummyHtmlView.hideN)r/r0r1rMr^r_rrrrr]s   r]r,zPreparing to upgradezGetting new software channelszGetting new packageszInstalling the upgradesz Cleaning upc@seZdZdZddZddZddZdd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddddZdddZdd Zdd!d"Zdd#d$Zd%d&Zd'd(d)Zd*d+ZdS),DistUpgradeViewz" abstraction for the upgrade view cCs d|_dS)NF)Z needs_screen)rrrrrs zDistUpgradeView.__init__cCstjjjS)z5 return a OpProgress() subclass for the given graphic)r3r4r5Z OpProgress)rrrrgetOpCacheProgress!sz"DistUpgradeView.getOpCacheProgresscCstS)z# return an acquire progress object )r)rrrrgetAcquireProgress$sz"DistUpgradeView.getAcquireProgressNcCstS)z" return a install progress object )r2)rcacherrrgetInstallProgress'sz"DistUpgradeView.getInstallProgresscCstS)N)rY)rrrr getTerminal*szDistUpgradeView.getTerminalcCstS)N)r])rrrr getHtmlView,szDistUpgradeView.getHtmlViewcCsdS)z\ update the current status of the distUpgrade based on the current view Nr)rmsgrrr updateStatus.szDistUpgradeView.updateStatuscCsdS)z8 provide a visual feedback that the upgrade was aborted Nr)rrrrabort3szDistUpgradeView.abortcCsdS)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)rsteprrrsetStep6s zDistUpgradeView.setStepcCsdS)z" hide a certain step from the GUI Nr)rrjrrrhideStep@szDistUpgradeView.hideStepcCsdS)z" show a certain step from the GUI Nr)rrjrrrshowStepCszDistUpgradeView.showStepTc Csd|_||_g|_g|_g|_g|_g|_g|_x|D]}|jrq|jj |qO|j r|jj |qO|j r|jj |qO|j r|j jj|jr|jj |q |jj |qO|jrO|jj |qOqOW|j|j|_|jj|jj|jj|jj|jjd}t|jt|j} t|jt|j} t|j} t|jdkr|tddt|jit|jd67}|d7}n| dkr9|tdd | | 7}|d 7}n| dkrl|td d | | 7}|d 7}n| dkr|td d| | 7}|d 7}n|dkr tj|} t| tr| jt} n|td| 7}||jj|7}n| | dkro| | | dkro|jjrX|dtd7}q|dtd7}n#| dkr|dtd7}n| | | dkrtd}td}|j||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.Zamountz 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) ZconfirmChangesMessage demotionsZ toInstallZ toReinstallZ toUpgradeZtoRemoveZ toRemoveAutoZ toDowngradeZmarked_installappendZmarked_upgradeZmarked_reinstallZ marked_deleteZ_pcacheZ _depcacheZis_auto_installedZ_pkgZmarked_downgradesortlenrr Z size_to_str isinstancebytesdecodeENCODINGrrbr.r*r7) rsummaryZchangesrqZ downloadSizeZactionsZ removal_boldrWrgZ pkgs_removeZ pkgs_instZ pkgs_upgradeZdownloadSizeStrrrrconfirmChangesFs                   '            $    zDistUpgradeView.confirmChangesZNocCsdS)z0 ask a Yes/No question and return True on 'Yes' Nr)rryrgdefaultrrraskYesNoQuestionsz DistUpgradeView.askYesNoQuestioncCs(td}td}|j||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|)rryrgrrrconfirmRestarts  zDistUpgradeView.confirmRestartcCsdS)z display a error Nr)rryrg extended_msgrrrr7szDistUpgradeView.errorcCsdS)z display a information msgNr)rryrgr~rrr informationszDistUpgradeView.informationcCsdS)zQ process gui events (to keep the gui alive during a long computation Nr)rrrr processEventsszDistUpgradeView.processEventsFcCsdS)zX do a progress pulse (e.g. bounce a bar back and forth, show a spinner) Nr)rZfinishedrrr pulseProgressszDistUpgradeView.pulseProgresscCs |j||dj|dS)zr show demoted packages to the user, default implementation is to just show a information dialog rnN)rjoin)rryrgrqrrr showDemotionsszDistUpgradeView.showDemotions)r/r0r1rXrrarbrdrerfrhrirkrlrmrzr|r}r7rrrrrrrrr`s(          b  r`__main__)2Z __future__rrZDistUpgradeGettextrrrr3r9r:r Zlocaler!rHr6ZDistUpgradeAufsrrZDistUpgradeApportr setlocaleLC_ALLZgetdefaultlocalecoderxrLputenvr rQZ getlocalerr4r5rr2objectrYr]rangeZ STEP_PREPAREZSTEP_MODIFY_SOURCESZ STEP_FETCHZ STEP_INSTALLZ STEP_CLEANUPZ STEP_REBOOTZSTEP_Nr`r/fpr'rrrrsL           D6K$