o 4fW1@sdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z ddl Z gdZGdddeZGdd d eZGd d d eZGd d 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 OpProgressc@speZdZdZdZZZZZdZ Z Z ddZ ddZ dd Zd d Zd d ZddZddZddZdS)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. rcCdS)z(Abstract) Called when a error is detected during the install.Nr )r pkgerrormsgr r rerrorrzInstallProgress.errorcCr )zA(Abstract) Called when a conffile question from dpkg is detected.Nr )r r,newr r rconffilerzInstallProgress.conffilecCr )z.(Abstract) Called when the APT status changed.Nr )r rFpercentstatusr r r status_changerzInstallProgress.status_changecCr )z/(Abstract) Called when the dpkg status changed.Nr )r rFrLr r rdpkg_status_changerz"InstallProgress.dpkg_status_changecCr )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 )r rFstager r r processingrzInstallProgress.processingcCs|}|dkrfz t|jdWn tyYnwz t||jWn=tyEtt tj dddt |jd|Yn!t ye}zt jd|ttjjWYd}~nd}~ww||_|}t|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)forkr2set_inheritabler5AttributeError_exit do_installr7filenospawnlpP_WAITstr Exceptionsysstderrwriteapt_pkgPackageManager RESULT_FAILED child_pid wait_child WEXITSTATUS)r objpideresr r rruns,     zInstallProgress.runcCstS)zFork.)r2rRr"r r rrRszInstallProgress.forkc Csz|j}Wn$ty+}z|jtjkr |jtjkr t|jWYd}~dSd}~wwd}}}}}|drRz | dd\}}}}WnFt yQYdSw|drvz | dd\}}}}Wn*t yu| dd\}}}Ynw|dr| dd\}}}| | | | }| }| }|d ks|d kr| ||dS|d ks|d krtd |}|r||d|ddSdS|dkrt||jks||jkr||t|| t||_| |_dSdS|dkr|||dSdS)zUpdate the interface.Nr/pm:rLrPpmerrorrHzconffile-prompt pmconffilez\s*'(.*)'\s*'(.*)'.*pmstatus)r8readlineIOErrorerrnoEAGAIN EWOULDBLOCKprintstrerror startswithsplit ValueErrorrPstriprHrematchrJgroupfloatrKrLrMrN) r lineerrpkgnamerL status_strrKbaser~r r rupdate_interfacesV        z InstallProgress.update_interfacec Csd\}} z t|jggg|jWntjy0}z|j\}}|tjkr&WYd}~nd}~ww|zt |j tj \}}||j krHW|SWn&t yo}z|jtj kr^WYd}~|S|jtjkreWYd}~nd}~wwq)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)selectr8select_timeoutrHargsrtEINTRrr2waitpidrbWNOHANGOSErrorECHILD)r rfrhrHerrno__errstrrr r rrc/s<        zInstallProgress.wait_childN)r%r&r'r(rbrKrrLr<r=r>r@rErHrJrMrNrPrirRrrcr r r rrs"  ) 0rc@s.eZdZdZd\ZZZZdddZddZ dS) rzbMonitor objects for operations. Display the progress of operations such as opening the cache.)Fr/r r/NcCs|dur ||_dSdS)zCalled periodically to update the user interface. You may use the optional argument 'percent' to set the attribute 'percent' in this call. N)rK)r rKr r rr-Vs zOpProgress.updatecCr )z,Called once an operation has been completed.Nr r"r r rr`rzOpProgress.doner?) r%r&r'r( major_changeoprKsubopr-rr r r rrOs    r)r( __future__rrtr9ior2r}rr\typingrrr___all__objectrrrrr r r rs" M#6