+eTT|@s>ddlmZmZddlZejddejddddlmZddlmZdd lmZdd lm Z dd lm Z dd lm Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZd dlmZmZd dlmZmZmZmZd dlmZddlZd dlmZGdddej j!j"Z#Gdddej j!j$Z%GdddeZ&GdddeZ'Gddde(Z)Gddde(Z*GdddeeZ+e,d kr:e+Z-e&e-Z.e'e-Z/e-j0j1d!d"d#gej2e j3dej4Z5xGe j6d dD]2Z7e5e7j8re5e7j9ne5e7j:qWe5j;e.e/ej2e/j<d$d%e-j0j1d!d"d#ge-j=d&d'd(e-j>d)gd*ndS)+)absolute_importprint_functionNGtkz3.0Vtez2.90)r)Gdk)r)GLib)GObject)Pango) run_apport apport_crash)DistUpgradeViewFuzzyTimeToStrInstallProgressAcquireProgress)SimpleGtkbuilderApp)gettextc@sFeZdZdZddZddZddZdd Zd S) GtkCdromProgressAdapterzi Report the cdrom add progress Subclass this class to implement cdrom add progress reporting cCs%|j|_|j|_||_dS)N) label_statusstatusprogressbar_cacheprogressparent)selfrrA/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeViewGtk3.py__init__9s  z GtkCdromProgressAdapter.__init__cCsW|r|jj|n|jj|t|jxtjrRtjq9WdS)z; update is called regularly so that the gui can be redrawn N) rset_textr set_fractionfloatZ totalStepsrevents_pendingmain_iteration)rtextsteprrrupdate=s zGtkCdromProgressAdapter.updatecCsdS)NF)Fr%r)rrrrask_cdrom_nameDsz&GtkCdromProgressAdapter.ask_cdrom_namecCsdS)NFr)rrrr change_cdromFsz$GtkCdromProgressAdapter.change_cdromN)__name__ __module__ __qualname____doc__rr$r&r'rrrrr5s    rcs=eZdZddZdfddZddZS) GtkOpProgresscCs||_d|_dS)Ng) progressbarfraction)rr-rrrrJs zGtkOpProgress.__init__Ncs|tt|j||jd}t|j|dkr[||_|jj|jnxtj rwtj q^WdS)NgY@g?) superr,r$percentabsr.r-rrr r!)rr0Z new_fraction) __class__rrr$Ps  zGtkOpProgress.updatecCs|jjddS)N )r-r)rrrrdone]szGtkOpProgress.done)r(r)r*rr$r4rr)r2rr,Is   r,csjeZdZfddZddZddZfddZd d Zfd d ZS) GtkAcquireProgressAdaptercsctt|j|j|_|j|_||_d|_|j |_ |j j d|j dS)NFZclicked) r/r5rrrrrrcanceledZbutton_fetch_cancel button_cancelconnect cancelClicked)rr)r2rrres     z"GtkAcquireProgressAdapter.__init__cCstjdd|_dS)Nr9T)loggingdebugr6)rwidgetrrrr9ns z'GtkAcquireProgressAdapter.cancelClickedc Cstd||f}tjd|jjdtjjdtjjdtj j }|j ||j }|j d|j|tjjkrdSdS) Nz&Please insert '%s' into the drive '%s'rflagstypebuttonsr%TF)_r MessageDialogr window_main DialogFlagsMODAL MessageTypeQUESTION ButtonsTypeZ OK_CANCEL set_markuprun set_titledestroy ResponseTypeZOK)rZmediumZdrivemsgdialogresrrr media_changeqs      z&GtkAcquireProgressAdapter.media_changecsAtt|j|jjd|jj|jjdS)Nr)r/r5startrrrshowr7)r)r2rrrQs zGtkAcquireProgressAdapter.startcCs7|jjd|jjtd|jjdS)Nr3zFetching is complete)rrrr@r7hide)rrrrstopszGtkAcquireProgressAdapter.stopcsjtt|j|t|j|jjddkrE|jj|jd|jd}||j kr{|j }n|j dkrt j |j }t |tr|jtj}n|jjtd||j |f|jjtdt|jqE|jjtd||j f|jjdnxtjratjqHW|j S) NgY@g?r rz!Fetching file %li of %li at %sB/szAbout %s remainingzFetching file %li of %liz )r/r5pulser1r0r get_fractionrZ current_itemsZ total_items current_cpsapt_pkgZ size_to_str isinstancebytesdecodelocalegetpreferredencodingrrr@retarr r!r6)rownerZ currentItemrW)r2rrrUs*&  zGtkAcquireProgressAdapter.pulse) r(r)r*rr9rPrQrTrUrr)r2rr5as    r5c@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZdS)GtkInstallProgressAdapteri,cCs|tj|d|_|j|_|j|_|j|_|j|_ |j j d|j ||_ t jjdddS)Nz child-exitedzDPkg::StopOnErrorFalse)rr_cacherrrexpander_terminalexpander_termtermr8 child_exitedrrXconfigset)rrrrrrs       z"GtkInstallProgressAdapter.__init__cCsCtj|d|_|jjtd|jjd|jjd|jj d|j j |j j d|j tjjdpd}|dkr|jrd |jks|jd j rd }|jjdqnd |jd g|_dtjkr$|jjd |nd|_d|_d|_dS)NFzApplying changesgr3Tzcontents-changedZDEBIAN_FRONTENDZgnomez libgtk2-perlrNzVTE_PTY_KEEP_FD=%szAPT_LISTCHANGES_FRONTEND=nonezDEBIAN_FRONTEND=%s)r start_updatefinishedrrr@rrrd set_sensitiverfrRr8_on_term_content_changedosenvirongetrb is_installed set_expandedZwritefdenvappend start_timetime_ui last_activity)rZfrontendrrrrjs*       z&GtkInstallProgressAdapter.start_updatecCs1tj|||tjd||ftjdd|krFdS|jjj|jjt d|}t d|}d||f}|jjj |jjj d|jjj j tjj|jjj||jjjj||jjj|jjj|jjjdS) 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 %sr%)rerrorr:rdgettextr dialog_errorset_transient_forrBr@realizerJ get_window set_functionsr WMFunctionMOVE label_errorrHtextview_error get_bufferr scroll_errorrRrIrS)rpkgZerrormsgsummaryrMmarkuprrrrxs" zGtkInstallProgressAdapter.errorc Cstjd|tj}td|}td}d||f}|jjj||jjjd|jjj |jj t j j |s|d}nt j j drdd||g}tj|d tjjd }|jd d }|jjjj|n|jjjjtd |jjj} |jjj|jtj|7_| tjjkr|jjddn|jjdddS)Nz.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 %sr%z .dpkg-distz /usr/bin/diffz-ustdoutrzUTF-8replacez The 'diff' command was not foundzy r zn r)r:r;timer@rZlabel_conffilerHZdialog_conffilerJr{rBrnpathexists subprocessPopenPIPEZ communicater[Ztextview_conffilerrrIrSrvrrLYESrfZ feed_child) rZcurrentnewrQZprimZsecrcmdZdiffrOrrrconffiles.   z"GtkInstallProgressAdapter.conffilecCstjjtjj}tj}|dkrx3|jD](}|jd\}}|tj |sz&GtkInstallProgressAdapter.child_exitedcCs!x|js|jqW|jS)N)rkupdate_interfacer)rrrr wait_childCs z$GtkInstallProgressAdapter.wait_childcCs|jjddS)Nr%)rr)rrrr finish_updateHsz'GtkInstallProgressAdapter.finish_updatecCstj||jdkr9|jjtjdn|jdkr|j|jtjkr|j st j d|j|j j fd|_ n|jjjdnxtjrtjqWtjddS)Ngg?rz+no activity on terminal for %s seconds (%s)Tg{Gz?)rrrurrUrsleeprwTIMEOUT_TERMINAL_ACTIVITYrr:warningrZget_textrrcrrrr r!)rrrrrKs   # z*GtkInstallProgressAdapter.update_interfaceN)r(r)r*rrrjrxrrrmrrgrrrrrrrr`s    #      r`c@s+eZdZddZdddZdS)DistUpgradeVteTerminalcCs||_||_dS)N)rfr)rrrfrrrr^s zDistUpgradeVteTerminal.__init__Fcsfdd}jjjjd|jjjd|dkrgjjjdnd_jjt j j d|dddd\}}| s|dkrdSx7jsxt j rt jqWtjdqW`dS) Ncs d_dS)NT)rk)r<)rrrwait_for_childbsz3DistUpgradeVteTerminal.call..wait_for_childz child-exitedTF/rg?)rfrRr8rrcrlrrrkZfork_command_fullrrrrr r!rr)rrZhiddenrsuccessrr)rrcallas*    zDistUpgradeVteTerminal.callN)r(r)r*rrrrrrr]s  rc@sLeZdZddZddZddZddZd d Zd S) HtmlViewcCs ||_dS)N)r)rZ webkit_viewrrrr}szHtmlView.__init__cCs7|js dS|jj||jjd|jdS)Nz load-finished)ropenr8_on_load_finished)rZurlrrrrs z HtmlView.opencCs|jjdS)N)rrR)rrrrrRsz HtmlView.showcCs|jjdS)N)rrS)rrrrrSsz HtmlView.hidecCs|jdS)N)rR)rviewZframerrrrszHtmlView._on_load_finishedN)r(r)r*rrrRrSrrrrrr|s     rc@sBeZdZdZddddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zdd!d"Zdd#d$Zdd%d&d'Zd(d)d*Zd+d,Zd-d.Zd/d0d1Zd2d3ZdS)4DistUpgradeViewGtk3z& gtk frontend of the distUpgrade tool Nc stj|_| s)|dkrStjjtjd}tj}nd}tjj|d}tjt j y!t j d|t jdWn6tk r}ztjd|WYdd}~XnXtj|ddtjj}y#jj|jdd d Wn9tjk r\}ztjd |WYdd}~XnXjd _tjj_d_jjjj j!t"j#j$t%j&_'t(_)t*_+t,_-tj.tj/_0tj1d }tj2}|j3|d |j4|dd j5j6|j0j7d tj8j9j5j:j0j;j<dfdd} j=j>d| j?t _@dS)N.Zmoz/usr/share/locale/Z gtkbuilderzubuntu-release-upgraderzError setting locales (%s)z/DistUpgrade.uizsystem-software-update rz)error setting default icon, ignoring (%s)r%TrFcs$jj}jj| dS)N)expander_detailsZ get_expandeddialog_changes set_resizable)wZexpanded)rrr _activatedsz0DistUpgradeViewGtk3.__init__.._activatedZactivate)Ar rlogdirrnrjoingetcwdrZ init_checksysargvr\bindtextdomainr textdomain Exceptionr:rrZ IconThemeZ get_defaultrBZset_default_iconZ load_iconrZGErrorr;create_terminal prev_step iconthemerr|r}r~rrrr,r_opCacheProgressr5_acquireProgressr_cdromProgressr`_installProgressZ TreeStoreZ TYPE_STRING details_listZTreeViewColumnZCellRendererText pack_startZ add_attributeZtreeview_detailsZ append_columnZset_sort_column_idZSortTypeZ ASCENDINGZ set_modelrrrr8_handleException excepthook) rZdatadirrZ localedirZgladedireZiconscolumnZrenderrr)rrrsX  $ #      zDistUpgradeViewGtk3.__init__cCsddl}|j|||}tjddj|t|||ts|jtdtddj|ntj ddS)Nrznot handled expection: %s zA fatal error occurredzPlease report this as a bug (if you haven't already) and include the files /var/log/dist-upgrade/main.log and /var/log/dist-upgrade/apt.log in your report. The upgrade has aborted. Your original sources.list was saved in /etc/apt/sources.list.distUpgrade.r ) tracebackformat_exceptionr:rxrr r r@rexit)rr>rtbrlinesrrrrs   z$DistUpgradeViewGtk3._handleExceptioncCst||jS)N)rre)rrrr getTerminalszDistUpgradeViewGtk3.getTerminalc Cs|jdkry^ddlm}|j|_|jj}|jdd|jj|jdddWqtj dt j SYqXnt |jS)Nr)WebKitzenable-pluginsFTz html widget) r gi.repositoryrZWebViewZ get_settings set_propertyZ vbox_mainZpack_endr:Z exceptionr Z DummyHtmlViewr)rrZsettingsrrr getHtmlViews  zDistUpgradeViewGtk3.getHtmlViewcCsmt|jdkrit|jdkritd}td}|j||}tjd|| SdS)Nr zCtrl-c pressedzkThis will abort the operation and may leave the system in a broken state. Are you sure you want to do that?z5ctrl-c press detected, user decided to pass it on: %sF)lenstringordr@askYesNoQuestionr:r)rr<ZkeyevrrMrOrrr_key_press_handlers*   z&DistUpgradeViewGtk3._key_press_handlerc Cstj|_|jjd|j|jjdg|_|jj|jddd|jj t j |_ |j j |jj|j ddd|j j|jjy(ttjj|jdd|_Wntk rtj|_YnX|jS)z! helper to create a vte terminal zkey-press-eventz monospace 10Trzterm.logr)rZTerminalrer8rZset_font_from_stringZ_terminal_linesZ hbox_customrr|rZ VScrollbarZvscrollbar_terminalrRZset_adjustmentZget_vadjustmentrrnrrrZ _terminal_logrrr)rrrrrs   ( z#DistUpgradeViewGtk3.create_terminalcCs|jS)N)r)rrrrgetAcquireProgresssz&DistUpgradeViewGtk3.getAcquireProgresscCs||j_|jS)N)rrb)rcacherrrgetInstallProgresss z&DistUpgradeViewGtk3.getInstallProgresscCs|jS)N)r)rrrrgetOpCacheProgresssz&DistUpgradeViewGtk3.getOpCacheProgresscCs|jS)N)r)rrrrgetCdromProgresssz$DistUpgradeViewGtk3.getCdromProgresscCs|jjd|dS)Nz%s)rr)rrMrrr updateStatus!sz DistUpgradeViewGtk3.updateStatuscCs>t|d|}t|d|}|j|jdS)Nz image_step%iz label_step%i)getattrrS)rr#imagelabelrrrhideStep#s zDistUpgradeViewGtk3.hideStepcCs>t|d|}t|d|}|j|jdS)Nz image_step%iz label_step%i)rrR)rr#rrrrrshowStep)s zDistUpgradeViewGtk3.showStepcCsutjj}|j}|dkrqt|d|}t|d|}|jtj||j|jndS)Nrz image_step%iz arrow_step%i) rIconSizeMENUrrset_from_stockZ STOCK_CANCELrRrS)rsizer#rarrowrrrabort.s    zDistUpgradeViewGtk3.abortcCs)|jjrtjdntjj}tj}|j rt |d|j }t |d|j }t |d|j }|j d||j tj ||j|jn||_ t |d|}t |d|}t |d|}|jdsdS|j|jdS)Nzicon theme changed, re-readingz image_step%iz label_step%iz arrow_step%iZ attributesZvisible)rZrescan_if_neededr:r;rrrr ZAttrListrrrrZ STOCK_APPLYrRrSr)rr#rZattrlistrrrrrrsetStep7s(       zDistUpgradeViewGtk3.setStepcCs|jjd|jj|jd||f}|jj||dkr{|jj}|j||j j n |j j |jj |jj jtjj|jj|jj xtjrtjqWdS)Nr%z%s %s)Zdialog_informationrJr{rBZlabel_informationrHZtextview_informationrrZscroll_informationrRrSr|r}r~rrrrIrr r!)rrrM extended_msgbufferrrr informationTs      zDistUpgradeViewGtk3.informationcCs|jjd|jj|jd||f}|jj||dkr{|jj}|j||j j n |j j |jj |jj jtjj|jj|jj dS)Nr%z%s %sF)rzrJr{rBrrHrrrrrRrSr|r}r~rrrrI)rrrMrrrrrrxfs      zDistUpgradeViewGtk3.errorTc CsItj|||||sdS|jdtd7_|dkr|jjd|jjd|jj|d|jj|dn|j j d||j j |j|j j xtd|jftd |jftd |jftd |jftd |jftd |jffD]\}}|r6|j jd|t|g} xL|D]A} |j j| d| jtjt| jddfgqqWq6q6W|jj|jj|j|jjd|jj j!t"j#j$t"j#j%B|jj&} |jj'| t(j)j*krEdSdS)NFz %sz?To prevent data loss close all open applications and documents.Trr z%sz%No longer supported by Canonical (%s)zDowngrade (%s)z Remove (%s)zNo longer needed (%s)z Install (%s)z Upgrade (%s)z%s - %srr%)+r confirmChangesZconfirmChangesMessager@Zbutton_cancel_changesZ set_use_stockZset_use_underlineZ set_labelZbutton_confirm_changesZ label_summaryrHZ label_changesrclear demotionsZ toDowngradeZtoRemoveZ toRemoveAutoZ toInstallZ toUpgradertrnamerZmarkup_escape_textr candidaterr|r{rBrJr}r~rrrZRESIZErIrSrrLr) rrZchangesrZ downloadSizeZactionsZ removal_boldZ parent_textrZnoderrOrrrrxsH    "  7  z"DistUpgradeViewGtk3.confirmChangesNoc Csd||f}tjd|jdtjjdtjjdtjj}|j d|dkrx|j tj j n|j tj j |j||j}|j|tj j krdSd S) Nz%s %srr=r>r?r%rTF)rrArBrCrDrErFrGZYES_NOrJZset_default_responserLZNOrrHrIrK)rrrMdefaultrNrOrrrrs       z$DistUpgradeViewGtk3.askYesNoQuestioncCs|jj|j|jjd|jj|jjjtjj |jj }|jj |t j jkr~dSdS)Nr%TF)Zdialog_restartr{rBrJr|r}r~rrrrIrSrrLr)rrOrrrconfirmRestarts  z"DistUpgradeViewGtk3.confirmRestartcCs!xtjrtjqWdS)N)rr r!)rrrr processEventssz!DistUpgradeViewGtk3.processEventsFcCs*|jj|r&|jjdndS)Ng?)rrUr)rrkrrr pulseProgresss z!DistUpgradeViewGtk3.pulseProgresscCs|jj|j|jjd|jj|jjjtjj |jj }|jj |t j jkrtjdndS)Nr%r T)Z dialog_cancelr{rBrJr|r}r~rrrrIrSrrLZCANCELrr)rr<ZeventrOrrron_window_main_delete_events  z/DistUpgradeViewGtk3.on_window_main_delete_event)r(r)r*r+rrrrrrrrrrrrrrrrrxrrrrrrrrrrrs0 F           / r__main__z /usr/bin/dpkgz --configurez-aZTODOzTODO~ZshortZlongaasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended asfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended asfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended asfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended asfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended asfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended asfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended Zxxd)?Z __future__rrZgiZrequire_versionrrrrrrr rr\r:rrZaptrXrnZDistUpgradeApportr r r rrrZSimpleGtk3builderApprrZDistUpgradeGettextr@rbaseZ CdromProgressrZ OpProgressr,r5r`objectrrrr(rfpZiprrmainrZCacherrrrqZ mark_deleteZ mark_installZcommitrrxrrrrrsb         " BO