+eTw@sddlmZmZddlZejdddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlmZmZddlmZmZmZmZddlmZddlZddlmZe jGd d d ejj j!Z"Gd d d ejj j#Z$Gd ddeZ%GdddeZ&Gddde'Z(Gddde'Z)GdddeeZ*e+dkre*Z,e%e,Z-e&e,Z.ej/Z0xGe j1ddD]2Z2e0e2j3ree0e2j4ne0e2j5qAWe0j6e-e.ej7e j8de.j9dde,j:j;dddge,j<ddde,j=d gd!ndS)")absolute_importprint_functionNz2.0) 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)selfrr@/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeViewGtk.py__init__8s  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 totalStepsgtkevents_pendingmain_iteration)rtextsteprrrupdate<s zGtkCdromProgressAdapter.updatecCsdS)NF)Fr r)rrrrask_cdrom_nameCsz&GtkCdromProgressAdapter.ask_cdrom_namecCsdS)NFr)rrrr change_cdromEsz$GtkCdromProgressAdapter.change_cdromN)__name__ __module__ __qualname____doc__rrr!r"rrrrr 4s    r cs=eZdZddZdfddZddZS) GtkOpProgresscCs||_d|_dS)Ng) progressbarfraction)rr(rrrrIs zGtkOpProgress.__init__Ncs|tt|j||jd}t|j|dkr[||_|jj|jnxtj rwtj q^WdS)NgY@g?) superr'rpercentabsr)r(rrrr)rr+Z new_fraction) __class__rrrOs  zGtkOpProgress.updatecCs|jjddS)N )r(r)rrrrdone\szGtkOpProgress.done)r#r$r%rrr/rr)r-rr'Hs   r'csjeZdZfddZddZddZfddZd d Zfd d ZS) GtkAcquireProgressAdaptercsctt|j|j|_|j|_||_d|_|j |_ |j j d|j dS)NFZclicked) r*r0rrrrrrcanceledZbutton_fetch_cancel button_cancelconnect cancelClicked)rr)r-rrrds     z"GtkAcquireProgressAdapter.__init__cCstjdd|_dS)Nr4T)loggingdebugr1)rwidgetrrrr4ms z'GtkAcquireProgressAdapter.cancelClickedc Cstd||f}tjd|jjdtjdtjdtj}|j||j }|j d|j |tj krdSdS) Nz&Please insert '%s' into the drive '%s'rflagstypebuttonsr TF) _r MessageDialogr window_main DIALOG_MODALMESSAGE_QUESTIONZBUTTONS_OK_CANCEL set_markuprun set_titledestroyZ RESPONSE_OK)rZmediumZdrivemsgdialogresrrr media_changeps       z&GtkAcquireProgressAdapter.media_changecsAtt|j|jjd|jj|jjdS)Nr)r*r0startrrrshowr2)r)r-rrrH~s zGtkAcquireProgressAdapter.startcCs7|jjd|jjtd|jjdS)Nr.zFetching is complete)rrrr;r2hide)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?rrz!Fetching file %li of %li at %sB/szAbout %s remainingzFetching file %li of %liz )r*r0pulser,r+r get_fractionrZ current_itemsZ total_items current_cpsapt_pkgZ size_to_str isinstancebytesdecodelocalegetpreferredencodingrrr;retarrrr1)rownerZ currentItemrN)r-rrrLs(&  zGtkAcquireProgressAdapter.pulse) r#r$r%rr4rGrHrKrLrr)r-rr0`s    r0c@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ dS)GtkInstallProgressAdaptercCs|tj|d|_|j|_|j|_|j|_|j|_ |j j d|j ||_ t jjdddS)Nz child-exitedzDPkg::StopOnErrorFalse)r r_cacherrrexpander_terminalexpander_termtermr3 child_exitedrrOconfigset)rrrrrrs       z"GtkInstallProgressAdapter.__init__cCs-tj|d|_|jjtd|jjd|jjd|jj d|j j t j jdp~d}|dkr|jrd|jks|jdj rd }|jjdqnd |jd g|_dt j kr|jjd |nd|_d|_d|_dS) NFzApplying changesgr.TZDEBIAN_FRONTENDZgnomez libgtk2-perlrEzVTE_PTY_KEEP_FD=%szAPT_LISTCHANGES_FRONTEND=nonezDEBIAN_FRONTEND=%s)r start_updatefinishedrrr;rrr\ set_sensitiver^rIosenvirongetrZ is_installed set_expandedZwritefdenvappend start_timetime_ui last_activity)rZfrontendrrrrbs(       z&GtkInstallProgressAdapter.start_updatecCs.tj|||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 )r errorr5r dgettextr dialog_errorset_transient_forr=r;realizerBwindow set_functionsrgdk FUNC_MOVE label_errorr@textview_error get_bufferr scroll_errorrIrArJ)rpkgZerrormsgsummaryrDmarkuprrrros" 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_| tjkr|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 rzn r)r5r6timer;rZlabel_conffiler@Zdialog_conffilerBrrr=repathexists subprocessPopenPIPEZ communicaterRZtextview_conffilerzrrArJrmr RESPONSE_YESr^Z feed_child) rZcurrentnewrHZprimZsecr~cmdZdiffrFrrrconffiles,   "z"GtkInstallProgressAdapter.conffilecCs}|jjd|j}|dkryx@|jD]5}|jd\}}|tj|sz0GtkInstallProgressAdapter.fork..)r^forkptyrjsplitrerfsysZexitfunc)rpidrjkeyvaluerrrforks  zGtkInstallProgressAdapter.forkcCsi|jdkr!tj|_nt||jjddkrw|jjt|d|jj|j n|dkretj|_ d|_ |j |j}||j 8}t||}d||}|dkr|dkr|jjt d t|n|jjd |jjre|jjjd d kre|jjjd |qendS)NggY@g?g?FgN@<zAbout %s remainingr.z load-statuszprogress("%s")iiQi)rlrr,rrMrrrrstriprnactivity_timeout_reportedrmr;rr _webkit_view get_propertyZexecute_script)rr|r+rZdeltaZtime_per_percentrUrrr status_changes$#   # z'GtkInstallProgressAdapter.status_changecCs|j|_d|_dS)NT)Zget_child_exit_status apt_statusrc)rr^rrrr_2sz&GtkInstallProgressAdapter.child_exitedcCs!x|js|jqW|jS)N)rcupdate_interfacer)rrrr wait_child7s z$GtkInstallProgressAdapter.wait_childcCs|jjddS)Nr )rr)rrrr finish_update<sz'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?)r rrlrrLrsleeprnTIMEOUT_TERMINAL_ACTIVITYrr5warningrget_textrr[rirrr)rrrrr?s   # z*GtkInstallProgressAdapter.update_interfaceN)r#r$r%rrrbrorrrr_rrrrrrrrWs    "     rWc@s+eZdZddZdddZdS)DistUpgradeVteTerminalcCs||_||_dS)N)r^r)rrr^rrrrRs zDistUpgradeVteTerminal.__init__Fcsfdd}jjjjd|jjjd|dkrgjjjdnd_jjd|dd|}|dkrdSx7jsxt j rt j qWt j d qW`dS) Ncs d_dS)NT)rc)r7)rrrwait_for_childVsz3DistUpgradeVteTerminal.call..wait_for_childz child-exitedTFZcommandrargvg?)r^rIr3rr[rdrircZ fork_commandrrrrr)rrZhiddenrrr)rrcallUs     zDistUpgradeVteTerminal.callN)r#r$r%rrrrrrrQs  rc@sLeZdZddZddZddZddZd d Zd S) HtmlViewcCs ||_dS)N)r)rZ webkit_viewrrrrjszHtmlView.__init__cCs7|js dS|jj||jjd|jdS)Nz load-finished)ropenr3_on_load_finished)rZurlrrrrls z HtmlView.opencCs|jjdS)N)rrI)rrrrrIqsz HtmlView.showcCs|jjdS)N)rrJ)rrrrrJssz HtmlView.hidecCs|jdS)N)rI)rviewZframerrrruszHtmlView._on_load_finishedN)r#r$r%rrrIrJrrrrrris     rc@sNeZdZdZddddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zdd#d$Zdd%d&Zdd'd(d)Zd*d+d,Zd-d.Zd/d0Zd1d2d3Zd4d5ZdS)6DistUpgradeViewGtkz& gtk frontend of the distUpgrade tool Nc 4Cstj|||_| s)|dkrStjjtjd}tj}nd}tjj|d}tjy!t j d|t j dWn6t k r}ztjd|WYdd}~XnXtj}y tj|jddd Wn9tjk r9}ztjd |WYdd}~XnXtj||d d|jd |_tj|_tjjd |_y&tjjd |_|jjWn9tjk r}ztjd|WYdd}~XnXy2d dl}|j |_!|j"j#|j!Wntj$dd|_!YnX|j%j&|j%j'j(tjj)t*|j+|_,t-||_.t/||_0t1||_2tj3tj4|_5tj6d}tj7} |j8| d|j9| dd |j:j;||j5j<d tj=|j:j>|j5t?j@} t?jAt?jBd d} | jC| |jDjEd| |jFtG_HdS)N.Zmoz/usr/share/locale/Z gtkbuilderzubuntu-release-upgraderzError setting locales (%s)zsystem-software-update rz)error setting default icon, ignoring (%s)z/DistUpgrade.uiZpngZsvgzsvg pixbuf loader failed (%s)z html widgetr Tr~r attributesr)IrrlogdirrerjoingetcwdrZ init_checkrSbindtextdomainr textdomain Exceptionr5rZicon_theme_get_defaultZwindow_set_default_iconZ load_icongobjectZGErrorr6r create_terminal prev_step iconthemervZ PixbufLoaderZ pngloaderZ svgloaderclosewebkitZWebViewrZ vbox_mainZpack_end exceptionr=rsrtrurwr'r_opCacheProgressr0_acquireProgressr _cdromProgressrW_installProgressZ TreeStoreZ TYPE_STRING details_listZTreeViewColumnZCellRendererText pack_startZ add_attributeZtreeview_detailsZ append_columnZset_sort_column_idZSORT_ASCENDINGZ set_modelpangoAttrListZ AttrScaleZ SCALE_SMALLinsertr set_property_handleExceptionr excepthook) rZdatadirrZ localedirZgladedireZiconsrcolumnZrenderattrlistattrrrrrzst   $           zDistUpgradeViewGtk.__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_exceptionr5rorrrr;rexit)rr9rtbrlinesrrrrs   z#DistUpgradeViewGtk._handleExceptioncCst||jS)N)rr])rrrr getTerminalszDistUpgradeViewGtk.getTerminalcCs t|jS)N)rr)rrrr getHtmlViewszDistUpgradeViewGtk.getHtmlViewcCsmt|jdkrit|jdkritd}td}|j||}tjd|| SdS)NrzCtrl-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;askYesNoQuestionr5r)rr7Zkeyevr}rDrFrrr_key_press_handlers*   z%DistUpgradeViewGtk._key_press_handlerc Cs tj|_|jjd|j|jjd|jjd|jg|_|jj |j|jj t j |_ |j j|jj |j |j j|jjy(ttjj|jdd|_Wntk rtj|_YnX|jS)z! helper to create a vte terminal zkey-press-eventz monospace 10zcontents-changedzterm.logw)vteZTerminalr]r3rZset_font_from_string_term_content_changed_terminal_linesZ hbox_customrrsrZ VScrollbarZvscrollbar_terminalrIZset_adjustmentZget_adjustmentrrerrr _terminal_logrrr)rrrrrs    ( z"DistUpgradeViewGtk.create_terminalc Cs|jjdd}g}x}|jdD]l}|j|||jkr.|jj|dy|jjWqtk rt j dYqXq.q.W||_dS)z8 called when the *visible* part of the terminal changes cSsdS)NTr)abcdrrrrsz:DistUpgradeViewGtk._term_content_changed..rzflush()N) r]rrrkrrwriteflushIOErrorr5r)rr^Z current_textZ new_lineslinerrrrs  z(DistUpgradeViewGtk._term_content_changedcCs|jS)N)r)rrrrgetAcquireProgresssz%DistUpgradeViewGtk.getAcquireProgresscCs||j_|jS)N)rrZ)rcacherrrgetInstallProgresss z%DistUpgradeViewGtk.getInstallProgresscCs|jS)N)r)rrrrgetOpCacheProgresssz%DistUpgradeViewGtk.getOpCacheProgresscCs|jS)N)r)rrrrgetCdromProgresssz#DistUpgradeViewGtk.getCdromProgresscCs|jjd|dS)Nz%s)rr)rrDrrr updateStatusszDistUpgradeViewGtk.updateStatuscCs>t|d|}t|d|}|j|jdS)Nz image_step%iz label_step%i)getattrrJ)rrimagelabelrrrhideSteps zDistUpgradeViewGtk.hideStepcCs>t|d|}t|d|}|j|jdS)Nz image_step%iz label_step%i)rrI)rrrrrrrshowStep"s zDistUpgradeViewGtk.showStepcCsrtj}|j}|dkrnt|d|}t|d|}|jtj||j|jndS)Nrz image_step%iz arrow_step%i)rICON_SIZE_MENUrrset_from_stockZ STOCK_CANCELrIrJ)rsizerrarrowrrrabort's    zDistUpgradeViewGtk.abortcCs[|jjrtjdntj}tj}|jrt |d|j}t |d|j}t |d|j}|j d||j tj ||j |jn||_t |d|}t |d|}t |d|}|jdsdS|j |jtjtjdd }|j||j d|dS) Nzicon theme changed, re-readingz image_step%iz label_step%iz arrow_step%irZvisiblerrr)rZrescan_if_neededr5r6rrrrrrrrZ STOCK_APPLYrIrJrZ AttrWeightZ WEIGHT_BOLDr)rrrrrrrrrrrsetStep0s.         zDistUpgradeViewGtk.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_informationrBrrr=Zlabel_informationr@Ztextview_informationrzrZscroll_informationrIrJrsrtrurrvrwrArr)rr}rD extended_msgbufferrrr informationLs      zDistUpgradeViewGtk.informationcCs|jjd|jj|jd||f}|jj||dkr{|jj}|j||j j n |j j |jj |jj jtjj|jj|jj dS)Nr z%s %sF)rqrBrrr=rxr@ryrzrr{rIrJrsrtrurrvrwrA)rr}rDrrrrrro^s      zDistUpgradeViewGtk.errorTc CsCtj|||||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(kr?dSdS)NFz %sz?To prevent data loss close all open applications and documents.Trrz%sz%No longer supported by Canonical (%s)zDowngrade (%s)z Remove (%s)zNo longer needed (%s)z Install (%s)z Upgrade (%s)z%s - %sr}r ))rconfirmChangesZconfirmChangesMessager;Zbutton_cancel_changesZ set_use_stockZset_use_underlineZ set_labelZbutton_confirm_changesZ label_summaryr@Z label_changesrclear demotionsZ toDowngradeZtoRemoveZ toRemoveAutoZ toInstallZ toUpgraderkrnameglibZmarkup_escape_textr candidateZdialog_changesrsrrr=rBrtrurrvrwZ FUNC_RESIZErArJr) rr}ZchangesrZ downloadSizeZactionsZ removal_boldZ parent_textrZnoder|rFrrrrpsH    "  7  z!DistUpgradeViewGtk.confirmChangesNoc Csd||f}tjd|jdtjdtjdtj}|jd|dkrl|jtjn|jtj |j ||j }|j |tj krdSd S) Nz%s %srr8r9r:r rTF) rr<r=r>r?ZBUTTONS_YES_NOrBZset_default_responseZ RESPONSE_NOrr@rArC)rr}rDdefaultrErFrrrrs        z#DistUpgradeViewGtk.askYesNoQuestioncCs||jj|j|jjd|jj|jjjtjj |jj }|jj |tj krxdSdS)Nr TF) Zdialog_restartrrr=rBrsrtrurrvrwrArJr)rrFrrrconfirmRestarts  z!DistUpgradeViewGtk.confirmRestartcCs!xtjrtjqWdS)N)rrr)rrrr processEventssz DistUpgradeViewGtk.processEventsFcCs*|jj|r&|jjdndS)Ng?)rrLr)rrcrrr pulseProgresss z DistUpgradeViewGtk.pulseProgresscCs|jj|j|jjd|jj|jjjtjj |jj }|jj |tj krt jdndS)Nr rT)Z dialog_cancelrrr=rBrsrtrurrvrwrArJZRESPONSE_CANCELrr)rr7ZeventrFrrron_window_main_delete_events  z.DistUpgradeViewGtk.on_window_main_delete_event)r#r$r%r&rrrrrrrrrrrrrrrrrrorrrrrr rrrrrxs2 L             / r__main__ZTODOzTODO~z /usr/bin/dpkgz --configurez-aZshortZlongaasfds 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__rrZpygtkZrequirerrZgtk.gdkrrrrrSr5rrZaptrOreZDistUpgradeApportrrrrr r r r ZDistUpgradeGettextr;Z threads_initrbaseZ CdromProgressr Z OpProgressr'r0rWobjectrrrr#rfpZipZCacherrr|rhZ mark_deleteZ mark_installZcommitmainrrrrrorrrrrs^                "  AZ