ó
Qº’Nc           @   s¸  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z  d  d l m Z m Z d  d l m Z m Z d  d l m Z m Z m Z d  d l m Z d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ e d k r´e ƒ  Z e ƒ  Z e ƒ  Z e j d d ƒ e  j ƒ  Z x# e j d D] Z  e e  j! ƒ  qoWe j" e e ƒ e j# d ƒ e j$ d ƒ n  d S(   iÿÿÿÿN(   t   NoSectionErrort   NoOptionError(   t   PIPEt   Popen(   t   DistUpgradeViewt   InstallProgresst   FetchProgress(   t   DistUpgradeConfigt   NonInteractiveFetchProgressc           B   s   e  Z d  „  Z RS(   c         C   su   t  j |  | | | | ƒ | t j k rq d | |  j t j t |  j ƒ ƒ f GHt j	 j
 ƒ  rq t j	 j ƒ  qq n  d  S(   Ns   fetched %s (%.2f/100) at %sb/s(   R   t   update_statust   apt_pkgt	   STAT_DONEt   percentt   size_to_strt   intt   current_cpst   syst   stdoutt   isattyt   flush(   t   selft   urit   descrt
   shortDescrt   status(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyR	   )   s    $(   t   __name__t
   __module__R	   (    (    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyR   (   s   t   NonInteractiveInstallProgressc           B   sV   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   sÂ    
    Non-interactive version of the install progress class
    
    This ensures that conffile prompts are handled and that
    hanging scripts are killed after a (long) timeout via ctrl-c
    c         C   së   t  j |  ƒ t j d ƒ d t j d <d t j d <d t j d <t d ƒ |  _ | |  _ d	 |  _	 y2 |  j j
 d
 d t ƒ r“ t j j d d ƒ n  Wn t t f k
 r­ n Xd |  _ y |  j j d
 d ƒ |  _ Wn t k
 ræ n Xd  S(   Ns*   setting up environ for non-interactive uset   noninteractivet   DEBIAN_FRONTENDt   nonet   APT_LISTCHANGES_FRONTENDt   1t   RELEASE_UPRADER_NO_APPORTt   .i    t   NonInteractivet   ForceOverwrites   DPkg::Options::s   --force-overwritei`	  t   TerminalTimeout(   R   t   __init__t   loggingt   debugt   ost   environR   t   configt   logdirt   install_run_numbert   getWithDefaultt   FalseR
   t   setR    R   t   timeoutt   getintt	   Exception(   R   R,   (    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyR&   ;   s$    			c         C   s|  t  j d | | f ƒ |  j j d d t ƒ s3 d  St j t j ƒ } d | d <g  } d | k r‰ d } d } d	 } d
 | | | f } n¬ d | k rº d } d } d } d | | f } n{ d | k rî d } d } d } d
 | | | f } nG d | k r"d } d } d } d
 | | | f } n d | | f GHd  St j j	 | ƒ s\t  j d | ƒ d  St
 | ƒ j ƒ  d j ƒ  j ƒ  d }	 d |	 k sšd |	 k r¦d g }
 n3 d |	 k rÈd g }
 d | d <n t  j d  |	 ƒ d! t
 | ƒ j ƒ  k rd" | d# <d$ | d% <d& }	 d' d g }
 n  | j |	 ƒ | j |
 ƒ | j | ƒ | j | ƒ | d k r¯t d( | d) t d* t ƒj ƒ  d } | r5| j | j d+ d, ƒ d, j ƒ  ƒ q5n† | d k r5t j j | ƒ } | j d- ƒ d } t d. | d) t d* t ƒj ƒ  d } | r5| j | j d+ d, ƒ d, j ƒ  ƒ q5n  t  j d/ | | f ƒ t j | d0 | ƒ} t  j d1 | | f ƒ d  S(2   Ns)   got a error from dpkg for pkg: '%s': '%s'R#   t   DebugBrokenScriptsR(   t	   PYCENTRALs   post-installations   /var/lib/dpkg/info/t   postinstt	   configures   %s/%s.%ss   pre-installations   /var/lib/dpkg/tmp.ci/t   preinstt   installs   %s/%ss   pre-removalt   prermt   removes   post-removalt   postrms3   UNKNOWN (trigger?) dpkg/script failure for %s (%s) s+   can not find failed maintainer script '%s' i   i    t   bashs   /bin/shs   -ext   perls   -ds   AutoTrace NonStopt   PERLDB_OPTSs   unknown interpreter: '%s's   . /usr/share/debconf/confmodulet	   developert   DEBCONF_DEBUGR    t   DEBIAN_HAS_FRONTENDs   /usr/share/debconf/frontendt   shs%   dpkg-query -s %s|grep ^Config-Versiont   shellR   t   :i   t   _s   dpkg-query -s %s|grep ^Versions   re-running '%s' (%s)t   envs   %s script returned: %s(   R'   t   errorR+   R.   R/   t   copyR)   R*   t   patht   existst   opent   readlinet   stript   splitt   warningt   readt   appendt   extendR   t   TrueR   t   communicatet   basenameR(   t
   subprocesst   call(   R   t   pkgt   errormsgR*   t   cmdt   prefixt   namet   argumentt   maintainer_scriptt   interpt
   debug_optst   versiont   ret(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyRH   S   sz    	
&	

&)&)c         C   s`   t  j d | ƒ t j d ƒ y t j |  j d ƒ Wn$ t k
 r[ } t  j d | ƒ n Xd  S(   Ns.   got a conffile-prompt from dpkg for file: '%s'i   s   n
s/   error '%s' when trying to write to the conffile(	   R'   RP   t   timet   sleepR)   t   writet	   master_fdR3   RH   (   R   t   currentt   newt   e(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyt   conffile¬   s    c         C   s²   t  j |  ƒ t j ƒ  |  _ |  j j d d t ƒ } | r t j j	 |  j
 d |  j ƒ } t j d | ƒ t | d ƒ |  _ n t t j d ƒ |  _ |  j j d t j ƒ  ƒ d  S(   NR#   t   DpkgProgressLogs   dpkg-progress.%s.logs!   writing dpkg progress log to '%s't   ws
   %s: Start
(   R   t   start_updateRd   t   last_activityR+   R.   R/   R)   RJ   t   joinR,   R-   R'   R(   RL   t   dpkg_progress_logt   devnullRf   (   R   t   progress_logt   fullpath(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyRn   ¶   s    c         C   sG   t  j |  ƒ |  j j d t j ƒ  ƒ |  j j ƒ  |  j d 7_ d  S(   Ns   %s: Finished
i   (   R   t   finish_updateRq   Rf   Rd   t   closeR-   (   R   (    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyRu   Á   s    c         C   s*   |  j  j d t j ƒ  | | | f ƒ d  S(   Ns   %s:%s:%s:%s
(   Rq   Rf   Rd   (   R   RY   R   t
   status_str(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyt   status_changeÆ   s    c         C   s0  t  j |  ƒ |  j d  k r  d  S|  j |  j t j ƒ  k  ru t j d |  j |  j	 f ƒ t
 j |  j t d ƒ ƒ n  t j |  j g g  g  d ƒ } x‰ t | d ƒ d k rt j ƒ  |  _ y- t
 j |  j d ƒ } t j j d | ƒ Wn t k
 rü d  SXt j |  j g g  g  d ƒ } q– Wt j j ƒ  d  S(   Ns,   no activity %s seconds (%s) - sending ctrl-ci   gš™™™™™¹?i    i   s   %s(   R   t   update_interfacet   statusfdt   NoneRo   R1   Rd   R'   RP   R   R)   Rf   Rg   t   chrt   selectt   lenRQ   R   R   t   OSErrorR   (   R   t   rest   s(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyRy   Ë   s"    	"c         C   sl   t  j d ƒ d t j d <d t j d <t j ƒ  \ |  _ |  _ |  j d k re t  j d |  j ƒ n  |  j S(   Ns   doing a pty.fork()t   dumbt   TERMt   truet   PAGERi    s
   pid is: %s(   R'   R(   R)   R*   t   ptyt   forkt   pidRg   (   R   (    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyR‡   ã   s    (   R   R   t   __doc__R&   RH   Rk   Rn   Ru   Rx   Ry   R‡   (    (    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyR   3   s   		Y	
				t   DistUpgradeViewNonInteractivec           B   s   e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d d „ Z d „  Z	 d „  Z
 d e d „ Z d	 d
 „ Z d „  Z d d „ Z d „  Z RS(   s-    non-interactive version of the upgrade view c         C   s\   t  j |  ƒ t d ƒ |  _ t ƒ  |  _ t | ƒ |  _ t j	 j
 j ƒ  |  _ |  j t _ d  S(   NR"   (   R   R&   R   R+   R   t   _fetchProgressR   t   _installProgresst   aptt   progresst   baset
   OpProgresst   _opProgresst
   excepthookR   t   __excepthook__(   R   t   datadirR,   (    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyR&   ð   s    c         C   s%   t  j d | | f ƒ |  j ƒ  d S(   s2    on uncaught exceptions -> print error and reboot s   got exception '%s': %s N(   R'   t	   exceptiont   confirmRestart(   R   t   typet   valuet	   traceback(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyR’   ÷   s    c         C   s   |  j  S(   s5    return a OpProgress() subclass for the given graphic(   R‘   (   R   (    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyt   getOpCacheProgressü   s    c         C   s   |  j  S(   s     return a fetch progress object (   R‹   (   R   (    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyt   getFetchProgressÿ   s    c         C   s   |  j  S(   s"    return a install progress object (   RŒ   (   R   t   cache(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyt   getInstallProgress  s    c         C   s   d S(   s\    update the current status of the distUpgrade based
            on the current view
        N(    (   R   t   msg(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyt   updateStatus  s    c         C   s   d S(   sÏ    we have 5 steps current for a upgrade:
        1. Analyzing the system
        2. Updating repository information
        3. Performing the upgrade
        4. Post upgrade stuff
        5. Complete
        N(    (   R   t   step(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyt   setStep
  s    c         C   sž   t  j |  | | | | | ƒ t j d g  |  j D] } | j ^ q/ ƒ t j d g  |  j D] } | j ^ qY ƒ t j d g  |  j D] } | j ^ qƒ ƒ t S(   Ns   toinstall: '%s's   toupgrade: '%s's   toremove: '%s'(	   R   t   confirmChangesR'   R(   t	   toInstallR]   t	   toUpgradet   toRemoveRT   (   R   t   summaryt   changest	   demotionst   downloadSizet   actionst   removal_boldt   p(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyR¢     s    
***t   Noc         C   s   t  S(   s0    ask a Yes/No question and return True on 'Yes' (   RT   (   R   R¦   Rž   t   default(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyt   askYesNoQuestion  s    c         C   s#   t  j d ƒ |  j j d d t ƒ S(   s2    generic ask about the restart, can be overridden s   confirmRestart() calledR#   t
   RealReboot(   R'   R(   R+   R.   R/   (   R   (    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyR–   "  s    c         C   s   t  j d | | | f ƒ d S(   s    display a error s
   %s %s (%s)N(   R'   RH   (   R   R¦   Rž   t   extended_msg(    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyRH   '  s    c         C   s   t  j d ƒ d  S(   Ns   view.abort called(   R'   RH   (   R   (    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyt   abort*  s    N(   R   R   R‰   R{   R&   R’   Rš   R›   R   RŸ   R¡   RT   R¢   R¯   R–   RH   R²   (    (    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyRŠ   î   s   					
	t   __main__s   xserver-xorgs   pre-installation script failedi   i   i    (%   R   R
   R'   Rd   R   R)   R†   R}   RW   RI   t   apt.progresst   ConfigParserR    R   R   R   R   R   R   t   DistUpgradeConfigParserR   R   R   RŠ   R   t   viewt   fpt   ipRH   t   CacheRœ   t   argvRY   t   mark_installt   commitRe   t   exit(    (    (    sM   /usr/lib/python2.7/dist-packages/DistUpgrade/DistUpgradeViewNonInteractive.pyt   <module>   s8   »@			