+eT@sddlmZmZddlmZmZmZmZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl!Z!ddl"Z"ddl#Z#ddl$Z$ddl%m&Z&m'Z'ddl(m(Z(m)Z)m*Z*m+Z+ddl,Z,ddl-Z-dd l.m-Z/dd l.m0Z0d d d Z1ddZ2GdddeZ3Gddde j4j5j6Z7Gddde j4j5j8Z9Gddde+Z:Gddde*Z;GdddeZ<Gddde(Z=e>dkre=Z?e?j@dd ejAdd!kr e?jBjCZDeDdkrejEd"gejFnx(e?jBjGejHejId#qWnejAdd$kr}xHeJejAd%jKD]-ZLe?jBjMeLejHejId&q8WxejHqlWne jNZOx[ejAddD]FZPeOePjQoeOePjR reOePjSd'd(neOePjTqWeOjUe?jVe?jWxejHqWndS)))absolute_importprint_function)QUrlQtSIGNALQTimer)QDesktopServicesQDialogQPixmapQTreeWidgetItem QMessageBox QApplication QTextEdit QTextOption QTextCursor QPushButtonQWidgetQIcon QHBoxLayoutQLabel)uicN) run_apport apport_crash)DistUpgradeViewFuzzyTimeToStrInstallProgressAcquireProgress)gettext)unicode_gettextstrictcCs't|tr|jd|S|SdS)NzUTF-8) isinstancebytesdecode)serrorsr&@/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeViewKDE.pyutf88sr(cCs7tjj|r%tj||ntd|dS)Nzerror, can't find file: )ospathexistsrloadUiprint)fileparentr&r&r'r,>sr,c@s^eZdZdZddZddZddZdd Zd d Zd d Z dS) DumbTerminalz A very dumb terminal cCsmtj|d|||_|jd|jd|jtj|jd|j dd|_ dS)z2 really dumb terminal with simple editing support Z MonospaceFTN) r__init__installProgressZ setFontFamilyZsetFontPointSizeZsetWordWrapModerZNoWrapZsetUndoRedoEnabledZsetOverwriteMode_block)selfr4Z parent_framer&r&r'r3Gs     zDumbTerminal.__init__cCsAtj\|_|j_|jdkr:dtjdzAbout %s remainingzzFetching file %li of %liz T)rpulserlr_rhZ current_itemsZ total_items current_cpsapt_pkgZ size_to_strr!r"r#localegetpreferredencodingr[r^rmr/rYrsretar rC)r6ownerZ current_itemrvr&r&r'rus  &4# zKDEAcquireProgressAdapter.pulseN) rTrUrVrWr3rprqrtrur&r&r&r'rks     rkc@seZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZdS)KDEInstallProgressAdapterz?methods for updating the progress bar while installing packagescCstj|d|_|jj|_|jj|_|jj|_||_yt dd|_ Wnct k r}zCt j d|tjdkrtjj|_ n tj|_ WYdd}~XnXtjjdddS)Nz/var/log/dist-upgrade/term.logwbzCan not open terminal log: '%s'3zDPkg::StopOnErrorFalse)rr3_cacherYrZr\rlrsr/open _terminal_log Exceptionloggingerrorsysversionstdoutbufferrwconfigset)r6r/er&r&r'r3s   z"KDEInstallProgressAdapter.__init__cCstj|d|_|jjtd|jjd|jjdd|_ d|_ d|_ |j j jjddS)NFzApplying changesr gT)r start_updatefinishedrZr^rmrlr_rs start_timetime_ui last_activityr/rYshowTerminalButton setEnabled)r6r&r&r'rs     z&KDEInstallProgressAdapter.start_updatecCstj|||tjd||ftjdd|krFdStd|}td|}d||f}t|jj}t d||jj ||j j ||dkr|j j ||j jn |j j|j|jtd |jj|jdS) Nz*got an error from dpkg for pkg: '%s': '%s'Zdpkgz*dependency problems - leaving unconfiguredFzCould not install '%s'zThe upgrade will continue but the '%s' package may not be in a working state. Please consider submitting a bug report about it.z%s
%szdialog_error.uiz clicked())rrrrdgettextrmr r/rYr,translate_widget_children label_errorr^textview_errorrrhideconnectbutton_bugreportr reportBugexec_)r6pkgZerrormsgsummaryrodialoguer&r&r'rs$    "zKDEInstallProgressAdapter.errorc Cstjd|tj}td|}td}d||f}t|jj|_td|j|jj j ||jj j |jj |jjtd|jtjj|s|d}ntjjdrCdd ||g}tj|d tjjd }|jd d }|jj j |n|jj j td|jj} |jtj|7_| tjkrtj|jdntj|jddS)z6ask question in case conffile has been changed by userz.got a conffile-prompt from dpkg for file: '%s'z/Replace the customized configuration file '%s'?ztYou will lose any changes you have made to this configuration file if you choose to replace it with a newer version.z1%s %szdialog_conffile.uiz clicked()z .dpkg-distz /usr/bin/diffz-urrzUTF-8replacez The 'diff' command was not foundzy zn N)rdebugtimermr r/rY confDialoguer,Zlabel_conffiler^textview_conffilerrshow_difference_buttonr showConffiler)r*r+ subprocessPopenPIPEZ communicater#rrAcceptedrQr<) r6ZcurrentnewrqZprimZsecZmarkupcmdZdiffresultr&r&r'conffile+s.  % "z"KDEInstallProgressAdapter.conffilecCsk|jjjr>|jjj|jjjtdn)|jjj|jjjtddS)NzShow Difference >>>z<<< Hide Difference)rr isVisiblerrr^rmrr)r6r&r&r'rPs z&KDEInstallProgressAdapter.showConffilecCstj\|_|_|jdkrvdtjdr%rz&error reading from self.master_fd '%s'NzHgot ValueError from InstallProgress.update_interface. Line was '%s' (%s)r1z+no activity on terminal for %s seconds (%s)z&no activity on terminal for %s secondsTg{Gz?)!r?r<r@r)rArrQr/ terminal_textrBr(rr-rrrrH ValueErrorrrTIMEOUT_TERMINAL_ACTIVITYrrwarningrZrMUnicodeEncodeErrorrY konsole_framerrr rCsleep)r6rDrErFrGrr&r&r'rH~s:'   '   z*KDEInstallProgressAdapter.update_interfacecCsFx?|jtj|jtj\}}||jkrPqqW|S)N)rHr)waitpidr;WNOHANG)r6pidresr&r&r' wait_childs  z$KDEInstallProgressAdapter.wait_childN)rTrUrVrWrr3rrrrr:rrrHrr&r&r&r'r|s     %    *r|c@s4eZdZddZddZddZdS)UpgraderMainWindowcCstj|td|dS)Nzwindow_main.ui)rr3r,)r6r&r&r'r3s zUpgraderMainWindow.__init__cCs ||_dS)N)r/)r6Z parentRefr&r&r' setParentszUpgraderMainWindow.setParentcCs0|jj}|r"|jn |jdS)N)r/on_window_main_delete_eventZacceptignore)r6Zeventcloser&r&r' closeEvents zUpgraderMainWindow.closeEventN)rTrUrVr3rrr&r&r&r'rs   rc@s]eZdZdZddddZddZdddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zdd#d$Zdd%d&Zdd'd(d)Zd*d+Zd,d-d.Zd/d0Zd1d2Zd3d4d5Zd6d7ZdS)8DistUpgradeViewKDEz$KDE frontend of the distUpgrade toolNc Csdtj|tjd}|jtj| s?|dkr]tjjtj d}nd}y!t j d|t j dWn6t k r}ztjd|WYdd}~XnXdtjkrt dntdg|_tjjd rtd }n td }|jjt|t|_|jj||jjd |_t|jj|jj|_t||_ t!||_"t#||_$|j%t&_'|jj(j)d |jj*|jj(t+d |j,t-j.dd\}}dtjkrRtjd|krRt/j0tjd||tjd|j;j?|j>|j>jt@jAd|jB|jjCdS)NPyQt4.Zmoz)/usr/share/locale/ubuntu-release-upgraderzubuntu-release-upgraderzError setting locales (%s)ZDISPLAYzNo DISPLAY in os.environ foundz=/usr/share/icons/oxygen/48x48/apps/system-software-update.pngz5/usr/share/icons/hicolor/48x48/apps/adept_manager.pngrFz clicked()r1ZadeptZ XAUTHORITYZkillallZ adept_managerZ adept_updaterZUbuntuZKubuntuiXi )Drr3rZ getLoggerZsetLevelINFOr)r*joingetcwdrbindtextdomain textdomainrrr=r appr+r Z setWindowIconrrrYrrr prev_steprer\rs_opCacheProgressrk_acquireProgressrX_cdromProgressr|_installProgress_handleExceptionr excepthookrrrr showTerminaltempfileZmkstempshutilcopyrcallrZ label_titler^rMrrrrZkonsole_frame_layoutZsetMinimumSizer0rZ addWidgetrZ singleShot exitMainLoopr) r6ZdatadirZlogdirZloggerZ localedirr messageIconfdZ copyXauthr&r&r'r3s^ $      %"  + zDistUpgradeViewKDE.__init__cCstd|jjdS)Nr)r-rexit)r6r&r&r'r%s zDistUpgradeViewKDE.exitMainLoopcCs|dkr|j}nt|ts6t|trt|jdkrj|jtjddq|jt t|jn|j dkrx1|j D] }|j ||j |qWndS)NErrorkdelibs) rYr!r rstrZ windowTitlesetWindowTitlerrrmZchildrentranslate_widgetr)r6Z parentWidgetwidgetr&r&r'r)s  " z,DistUpgradeViewKDE.translate_widget_childrencCst|tst|tr t|jdkrptjdtjddd}|jt |dq t|jdkrtjdtjddd}|jt |dq t|jdkr |jt t|jj ddq ndS) Nz&CancelrZfallbackTz&Closer1rm&) r!rrrrMrZ translationrr^rrmr)r6rrr&r&r'r7sz#DistUpgradeViewKDE.translate_widgetcCst|tst|tr"dStj|||}tjddj|t|||t sdjtj|||}t |j }t d||j |j|jj||jntjddS)zCrash handler.Nz)not handled exception in KDE frontend: %s r1zdialog_error.uir) issubclassKeyboardInterrupt SystemExit tracebackformat_exceptionrrrrrr rYr,rdialogZ crash_detailr^rrr)r6exctypeZexcvalueexctblinestbtextrr&r&r'rDs   z#DistUpgradeViewKDE._handleExceptioncCstjt|dS)zstart konquerorN)ropenUrlr)r6Zurlr&r&r'openURL_szDistUpgradeViewKDE.openURLcCstjtddS)zstart konquerorzEhttps://launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+filebugN)rrr)r6r&r&r'reszDistUpgradeViewKDE.reportBugcCs|jjjr>|jjj|jjjtdn)|jjj|jjjtd|jj|jj dS)NzShow Terminal >>>z<<< Hide Terminal) rYrrrrr^rmrrresizesizeHint)r6r&r&r'rks zDistUpgradeViewKDE.showTerminalcCs|jS)N)r)r6r&r&r'getAcquireProgresstsz%DistUpgradeViewKDE.getAcquireProgresscCs||j_|jS)N)rr)r6cacher&r&r'getInstallProgressws z%DistUpgradeViewKDE.getInstallProgresscCs|jS)N)r)r6r&r&r'getOpCacheProgress{sz%DistUpgradeViewKDE.getOpCacheProgresscCs|jS)N)r)r6r&r&r'getCdromProgress~sz#DistUpgradeViewKDE.getCdromProgresscCs|jjj|dS)N)rYrZr^)r6ror&r&r' update_statussz DistUpgradeViewKDE.update_statuscCsDt|jd|}t|jd|}|j|jdS)Nz image_step%iz label_step%i)getattrrYr)r6raimagelabelr&r&r'hideSteps zDistUpgradeViewKDE.hideStepcCs|j}|dkrt|jd|}tjjdrLtd}n-tjjdrmtd}n td}|j||jndS)Nrz image_step%iz7/usr/share/icons/oxygen/16x16/actions/dialog-cancel.pngz@/usr/lib/kde4/share/icons/oxygen/16x16/actions/dialog-cancel.pngz4/usr/share/icons/crystalsvg/16x16/actions/cancel.png) rrrYr)r*r+r setPixmaprr)r6rarZ cancelIconr&r&r'aborts    zDistUpgradeViewKDE.abortcCs\tjjdr!td}n-tjjdrBtd}n td}tjjdrotd}n-tjjdrtd}n td}|jrt|jd|j}t|jd|j}|j||jn||_t|jd|}t|jd|}|j||j|j d |j d dS) Nz3/usr/share/icons/oxygen/16x16/actions/dialog-ok.pngz/usr/lib/kde4/share/icons/oxygen/16x16/actions/arrow-right.pngz9/usr/share/icons/crystalsvg/16x16/actions/1rightarrow.pngz image_step%iz label_step%izz) r)r*r+r rrrYrrrr^rM)r6raZokIconZ arrowIconrrr&r&r'setSteps*        zDistUpgradeViewKDE.setStepcCsd||f}t|j}td||j||jj||dkru|jj||jjn |jj|j j|j t dt j jdrtd}n-t j jdrtd}n td}|jj||jdS)Nz%s
%szdialog_error.uiZ Informationz;/usr/share/icons/oxygen/48x48/status/dialog-information.pngzD/usr/lib/kde4/share/icons/oxygen/48x48/status/dialog-information.pngz=/usr/share/icons/crystalsvg/32x32/actions/messagebox_info.png)r rYr,rrr^rrrrrrrmr)r*r+r rrr)r6rro extended_msgrrr&r&r' informations$      zDistUpgradeViewKDE.informationcCsd||f}t|j}td||j||jj||dkru|jj||jjn |jj|j j|j j |j t d|jtjjdrtd}n-tjjdrtd}n td}|jj||jdS)Nz%s
%szdialog_error.uiz clicked()z5/usr/share/icons/oxygen/48x48/status/dialog-error.pngz>/usr/lib/kde4/share/icons/oxygen/48x48/status/dialog-error.pngzA/usr/share/icons/crystalsvg/32x32/actions/messagebox_critical.pngF)r rYr,rrr^rrrrZ button_closerrrrrr)r*r+r rrr)r6rrorrrr&r&r'rs&     "  zDistUpgradeViewKDE.errorTcCsztj|||||t|j|_td|j|jjj|jj|jj t d|j |j |j|jj j tdd|jj|jjtjjdrtd}n-tjjdrtd}n td}|jjj||dkrx|d jd d }|jjj ||d jd d } |jjj | nd |} |jjj | |jjj |j|jjj|jjjdg|jjjjxF|j D];} |jjj!d t"|jjtd| j#gqWxF|j$D];} |jjj!d t"|jjtd| j#gq:WxF|j%D];} |jjj!d t"|jjtd| j#gqWxF|j&D];} |jjj!d t"|jjtd| j#gqWxF|j'D];}|jjj!d t"|jjtd|j#gqW|jj(}|tj)krvdSdS)zshow the changes dialoguezdialog_changes.uiz clicked()Detailsz >>>z7/usr/share/icons/oxygen/48x48/status/dialog-warning.pngz@/usr/lib/kde4/share/icons/oxygen/48x48/status/dialog-warning.pngz@/usr/share/icons/crystalsvg/32x32/actions/messagebox_warning.pngNrrmr1rz%sZPackageszNo longer supported %sz Remove %szRemove (was auto installed) %sz Install %sz Upgrade %sTF)*rconfirmChangesr rYchangesDialoguer,treeview_detailsrrshow_details_buttonrshowChangesDialogueDetailsrr^rmrrr)r*r+r Zquestion_pixmaprrZbutton_cancel_changesZbutton_confirm_changesZ label_summaryZ label_changesZconfirmChangesMessageclearZsetHeaderLabelsheader demotionsZinsertTopLevelItemr nameZtoRemoveZ toRemoveAutoZ toInstallZ toUpgraderr)r6rZchangesrZ downloadSizeZactionsZ removal_boldZ warningIconcancelZconfirmZ summaryTextZdemotedZrmZinstZuprr&r&r'r sP%   99999z!DistUpgradeViewKDE.confirmChangescCs|jjjrB|jjj|jjjtddn-|jjj|jjjdtd|jj|jj dS)Nr z >>>z<<< ) r r rrrr^rmrrrr)r6r&r&r'rs  z-DistUpgradeViewKDE.showChangesDialogueDetailsNocCsFtj|j|d|tjtjBtj}|tjkrBdSdS)NzTF)r rnrYYesr)r6rrodefaultanswerr&r&r'askYesNoQuestion&s/z#DistUpgradeViewKDE.askYesNoQuestioncCsttjtdtdtj|j}|jtj}|jtj}|jtdj dd|jt j dd|j }|tjkrdSd S) NzRestart requiredz<Restart the system to complete the upgradez _Restart Nowrmrrz&CloseTF) r ZQuestionrmZNoButtonrYZ addButtonrrr^rrrr)r6Z messageBoxZ yesButtonZnoButtonrr&r&r'confirmRestart,s- z!DistUpgradeViewKDE.confirmRestartcCstjdS)N)r rC)r6r&r&r'rC7sz DistUpgradeViewKDE.processEventsFcCsdS)Nr&)r6rr&r&r' pulseProgress:sz DistUpgradeViewKDE.pulseProgresscCs_td}|jdd}tj|jtd|tjtj}|tjkr[dSdS)NzCancel the running upgrade? The system could be in an unusable state if you cancel the upgrade. You are strongly advised to resume the upgrade.rz
zCancel Upgrade?TF)rmrr rrYrr)r6rMrr&r&r'r@s *z.DistUpgradeViewKDE.on_window_main_delete_event)rTrUrVrWr3rrrrrrrrrrrrrrrr rr rrrrCrrr&r&r&r'rs4 _           6  r__main__zinput box testzbar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar z --test-termZbashg{Gz?z--show-in-terminalrg?purgeT)XZ __future__rrZ PyQt4.QtCorerrrrZ PyQt4.QtGuirr r r r r rrrrrrrrrrrrxrrrrrZaptrwr)rr9ZDistUpgradeApportrrrrrrr?rZDistUpgradeGettextrmrr(r,r0rlbaseZ CdromProgressrXZ OpProgressrerkr|rrrTZviewrargvrr:rrrrHrCrrrArNrBZCacherrZ is_installedZ is_upgradableZ mark_deleteZ mark_installZcommitrrr&r&r&r'st"^            "   I4