xkd1dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z ddl Z gdZGddeZGdd eZGd d eZGd d eZdS)zBase classes for progress reporting. Custom progress classes should inherit from these classes. They can also be used as dummy progress classes which simply do nothing. )print_functionN)OptionalUnion)AcquireProgress CdromProgressInstallProgress OpProgresscbeZdZdZdxZxZxZxZZdxZ xZ Z dZ dZ dZdZdZd Zd Zd Zd S) rzMonitor object for downloads controlled by the Acquire class. This is an mostly abstract class. You should subclass it and implement the methods to get something useful. rcdS)z>>>>rrc(eZdZdZdZdZdZdZdS)ra Base class for reporting the progress of adding a cdrom. Can be used with apt_pkg.Cdrom to produce an utility like apt-cdrom. The attribute 'total_steps' defines the total number of steps and can be used in update() to display the current progress. rcdS)zAsk for the name of the cdrom. If a name has been provided, return it. Otherwise, return None to cancel the operation. Nr r+s rask_cdrom_namezCdromProgress.ask_cdrom_namerrcdS)zAsk for the CD-ROM to be changed. Return True once the cdrom has been changed or False to cancel the operation. Fr r+s r change_cdromzCdromProgress.change_cdroms urcdS)zPeriodically invoked to update the interface. The string 'text' defines the text which should be displayed. The integer 'current' defines the number of completed steps. Nr )rtextcurrents rupdatezCdromProgress.updaterrN)r/r0r1r2 total_stepsr5r7r;r rrrrvsRK        rrcteZdZdZd\ZZZZdZdZ dZ dZ dZ dZ d Zd Zd Zd Zd ZdZdZdZdS)rz4Class to report the progress of installing packages.)rr g?c tj\|_|_tj|jd|_tj|jd|_tj|jtjtj dS)Nwr) ospipestatusfdwritefdfdopen write_stream status_streamfcntlF_SETFL O_NONBLOCKr+s r__init__zInstallProgress.__init__sb(* % IdlC88Yt}c:: DM5="-@@@@@rcdS)z(Abstract) Start update.Nr r+s r start_updatezInstallProgress.start_updaterrcdS)z+(Abstract) Called when update has finished.Nr r+s r finish_updatezInstallProgress.finish_updaterrc|SNr r+s r __enter__zInstallProgress.__enter__s rcj|j|jdSrR)rGcloserH)rtypevalue tracebacks r__exit__zInstallProgress.__exit__s2 !!!   """""rcdS)z>(Abstract) Called when a error is detected during the install.Nr )rpkgerrormsgs rerrorzInstallProgress.errorrrcdS)zA(Abstract) Called when a conffile question from dpkg is detected.Nr )rr:news rconffilezInstallProgress.conffilerrcdS)z.(Abstract) Called when the APT status changed.Nr )rr[percentstatuss r status_changezInstallProgress.status_changerrcdS)z/(Abstract) Called when the dpkg status changed.Nr )rr[rcs rdpkg_status_changez"InstallProgress.dpkg_status_changerrcdS)z(Abstract) Sent just before a processing stage starts. The parameter 'stage' is one of "upgrade", "install" (both sent before unpacking), "configure", "trigproc", "remove", "purge". This method is used for dpkg only. Nr )rr[stages r processingzInstallProgress.processingrrc |}|dkr- tj|jdn#t$rYnwxYw tj||jn#t$r]tjtj tj dddt|jd|Yn[t$rO}tjd|ztjt jjYd}~nd}~wwxYw||_|}tj|S)aInstall using the object 'obj'. This functions runs install actions. The parameter 'obj' may either be a PackageManager object in which case its do_install() method is called or the path to a deb file. If the object is a PackageManager, the functions returns the result of calling its do_install() method. Otherwise, the function returns the exit status of dpkg. In both cases, 0 means that there were no problems. rTdpkgz --status-fdz-iz%s N)forkrBset_inheritablerEAttributeError_exit do_installrGfilenospawnlpP_WAITstr Exceptionsysstderrwriteapt_pkgPackageManager RESULT_FAILED child_pid wait_child WEXITSTATUS)robjpideress rrunzInstallProgress.runsiikk !88 "4<6666!     ?(9(@(@(B(BCCDDDD!   J %D-446677      ? ? ?   !,,,/=>>>>>>>> ?oo~c"""s/8 AA >BA$E. E7AEEc(tjS)zFork.)rBrlr+s rrlzInstallProgress.forkswyyrc |j}nV#t$rI}|jtjkr)|jtjkrt |jYd}~dSd}~wwxYwdx}x}x}x}}|dr. | dd\}}}}n#t$rYdSwxYw|drG | dd\}}}}n#t$r| dd\}}}YnmwxYw|drT| dd\}}}| | | | }| }| }|d ks|d kr| ||dS|d ks|d krWtjd |}|r>||d|ddSdS|dkrt%||jks ||jkre||t%|| t%||_| |_dSdS|dkr|||dSdS)zUpdate the interface.Nr>pm:rcripmerrorr]zconffile-prompt pmconffilez\s*'(.*)'\s*'(.*)'.*pmstatus)rHreadlineIOErrorerrnoEAGAIN EWOULDBLOCKprintstrerror startswithsplit ValueErrorristripr]rematchr`groupfloatrbrcrdrf) rlineerrpkgnamerc status_strrbbasers rupdate_interfacez InstallProgress.update_interfaces, %..00DD   yEL((SY%:K-K-Kcl### FFFFF   :<;;&;:;$ ??4 A 9=C9K9K6'::    __X & & A =6:jja6H6H3w  = = =*.**S!*<*<'w = __\ * * A,0JJsA,>,> )VZ OOGMMOOZ-=-=-?-? @ @ @--//%%''  Y  &G"3"3 JJw + + + + + ( ( (Fl,B,BH5zBBE > ekk!nnekk!nn===== > > z ! !W~~--t{1J1J""7E'NNJA**A/B.. B<;B<C11$DDcd\}} tj|jggg|jn7#tj$r%}|j\}}|t jkrYd}~nd}~wwxYw| tj |j tj \}}||j krnInG#t$r:}|jt j krYd}~n$|jt jkrYd}~nd}~wwxYw|S)aWait for child progress to exit. This method is responsible for calling update_interface() from time to time. It exits once the child has exited. The return values is the full status returned from os.waitpid() (not only the return code). )rrTN)selectrHselect_timeoutr]argsrEINTRrrBwaitpidr|WNOHANGOSErrorECHILD)rrrr]errno__errstrrs rr}zInstallProgress.wait_child7s6 c   t12BD>1@.IwAAA''':::### MMMPPP===>>>   /#/#/#b .5.5.5`rrc.eZdZdZd\ZZZZddZdZ dS)r zbMonitor objects for operations. Display the progress of operations such as opening the cache.)Fr>r r>Nc| ||_dSdS)zCalled periodically to update the user interface. You may use the optional argument 'percent' to set the attribute 'percent' in this call. N)rb)rrbs rr;zOpProgress.update]s  "DLLL  rcdS)z,Called once an operation has been completed.Nr r+s rrzOpProgress.donegrrrR) r/r0r1r2 major_changeoprbsubopr;rr rrr r VsSEE(:$L"gu####;;;;;rr )r2 __future__rrrIiorBrrrvtypingrrry__all__objectrrrr r rrrsS( &%%%%% """""""" O O OI>I>I>I>I>fI>I>I>X! ! ! ! ! F! ! ! Hyyyyyfyyyx;;;;;;;;;;r