
0Zc           @   s  d  d l  Z  e  j e  _ d e  j d d e  j d g e  j d *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 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 m Z y d  d l Z Wn e k
 rdd  d l Z n Xe  j d d d d	 d f k rd  d l Z n d  d l  Z y e! Wn! e" k
 rd  d
 l# m$ Z! n Xd  d l% Z% y e% j& Wn& e' k
 r	e( d  Z) e) e% _& n Xd  d l* Z* y e* j+ Wn= d e* _+ d e* _, d e* _- d e* _. d e* _/ d e* _0 n Xd Z1 yp d  d l2 Z2 d  d l3 Z2 d  d l4 Z2 e2 j5 d d d f k rd  d l4 m6 Z6 e6 d e7  n  e2 j8   d Z1 Wn e9 k
 rn Xd  d l: Z: d  d l; Z; e: j< Z< d Z= d Z> d Z? d Z@ d ZA d ZB d ZC d ZD d ZE d ZF e	 j jG e: jH d  ZI d ZJ d ZK d  ZL eK d ZM d! ZN d" ZO d# ZP d$ ZQ d% ZR d& ZS d' ZT d( ZU d) ZV d* ZW e( aX eY aZ e( a[ e( a\ e( a] e( a^ e( a_ d+ d, g Z` d-   Za d.   Zb d/   Zc e7 d0  Zd d1   Ze d2   Zf d3 eg f d4     YZh d5   Zi d6   Zj d7 eg f d8     YZk d9 e9 f d:     YZl d;   Zm d<   Zn d=   Zo d> e: jp f d?     YZq d@ e jr js f dA     YZt dB eg f dC     YZu dD   Zv dE   Zw dF   Zx dG   Zy eY dH  Zz dI   Z{ dJ   Z| dK   Z} dL   Z~ dM   Z dN   Z dO   Z dP   Z dQ   Z e1 rdR e2 j j f dS     YZ n  dT eg f dU     YZ dV   Z dW   Z dX   Z dY   Z dZ   Z d[   Z d\   Z d]   Z d^   Z d_   Z e d` k ry eu   a WnP e9 k
 rbe  j da IJe	 j   d k r\e  j db IJe  j d  n   n Xy e e  j d e  j d  WnWe k
 re j dc  e j dd de d e  j d  ne k
 r  ne9 k
 re: j e: j e% j&    Z t] e( k rPe j df  e j dg e= e: j f  e j e j  e  j d   n  y t] j e e( e( e(  Wn$ e k
 r  n e9 k
 rn Xe j dh de d e j di  e j dg e= e: j f  e  j d   n Xn  d S(j   iNs-   /usr/lib/uptrack/lib/python2.%s/site-packagesi   s/   /usr/lib/uptrack/lib64/python2.%s/site-packagesi    (   t   OptionParsert   Optiont   SUPPRESS_HELPi   i   t   final(   t   Setc         C   sN   z8 t  j   \ } } } d j t j | | | |    SWd d } } } Xd S(   s%   Like print_exc() but return a string.t    N(   t   syst   exc_infot   joint	   tracebackt   format_exceptiont   None(   t   limitt   etypet   valuet   tb(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   traceback_format_excB   s    #i   i   i   i   i<   iP   (   t   DBusGMainLoopt   set_as_defaults   /var/log/uptrack.logt   roott   admi  s   /usr/share/uptrack/uptrack.gpgs   /etc/uptracks%   /usr/share/uptrack/uptrack-server.gpgt(   9C99586684B64DE53F0885700EE0EADBD74EE7FCs,   /usr/share/uptrack/ksplice-tools-api-versions   /var/run/ksplice/debugs   depmod-neededt   2g      @i  i
   t   Initt   Upgradet   Installt   Removet   Shows   /var/lib/uptrack/autogensG   https://updates.ksplice.com/cgi/code?terms=1&noninteractive=1&noemail=1s   /usr/share/doc/uptrack/toss   SHA-256s   SHA-1c         C   s=   x6 t  D]. } | | k r | | r |  | | | k Sq Wt S(   N(   t   HASH_PRIORITIESt   False(   t   actualt   expectedt	   hash_type(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt
   hash_valid   s    c         C   si   t  j |  d  } i t j d 6t j d 6} i  } x0 | j   D]" \ } } | |  j   | | <q? W| S(   Nt   rbs   SHA-1s   SHA-256(   t   Uptrackt	   read_filet   hashlibt   sha1t   sha256t   itemst	   hexdigest(   t   filenamet   textt   hasherst   hashest   namet   fn(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt	   hash_file   s    
c         C   s]   t  d | d | d |  d d |  d d |  d d	 |  d
 d |  j d d   d |  d d |  	S(   Nt	   local_dirt
   remote_dirt   idt   IDR*   t   FilenameR.   t   NameR&   s   SHA-1R'   s   SHA-256t   targetst   Targetst   order(   t   Updatet   getR   (   t   itemR1   R2   R9   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt
   makeUpdate   s    




c         C   sb   |  d d k r$ |  d d k r$ d  St j j |   j d  d } | r^ | j d d  } n  | S(	   Nis   .kois   .ko.gzt   .i    t   -t   _(   R   t   ost   patht   basenamet   splitt   replace(   R*   t   canonicalizet   module_name(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   toModuleName   s     c          C   sC  t  j d g d t  j d t  j }  |  j   \ } } |  j r t j d  | ro t j d  t j |  n  | r t j d  t j |  n  t  j |  j d   n  i  } x | j	   j
 d  d D]q } | j
 d  d	  } t |  d
 k r
| d	 j
 d  } n g  } i | d d 6| d d 6| d 6| | d <q W| S(   Nt   lsmodt   stdoutt   stderrs   Error in lsmods   stdout:s   stderr:s   
i   i   i   t   ,t   Sizei   t   UseCountt   UsedByi    (   t
   subprocesst   Popent   PIPEt   communicatet
   returncodet   loggingt   errort   debugt   CalledProcessErrort   stripRD   R   t   len(   t   pRJ   RK   t   resultt   lt   fieldst   usedBy(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   getLoadedModules   s(    	 /c         C   s\   t  j d |   t j d |  g d t j d t j } t  j | j   d  | j d k S(   sM   
    Attempt to unload the given module.
    Returns True if successful.
    s   Trying to rmmod %st   rmmodRJ   RK   i    (   RU   RW   RP   RQ   RR   t   STDOUTRS   RT   (   t   moduleR[   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyRa      s
    R:   c           B   s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z e e  Z	 d   Z
 e e
  Z d   Z e e  Z d   Z e e  Z d	   Z d
   Z d   Z d   Z d   Z d   Z d d  Z d d  Z d   Z d   Z d   Z d   Z RS(   c
   
      C   sg   | |  _  | |  _ | |  _ i  |  _ | |  j d <| |  j d <| |  _ | |  _ | |  _ |	 |  _ d  S(   Ns   SHA-1s   SHA-256(   R3   R.   R*   t   verify_hashesR7   R1   R2   R9   (
   t   selfR3   R.   R*   R&   R'   R7   R1   R2   R9   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   __init__   s    				
		c         C   s   d |  j  |  j f S(   Ns   [%s] %s(   R3   R.   (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   __str__   s    c         C   s
   |  j    S(   N(   Rg   (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   __repr__   s    c         C   s   |  j  | j  k S(   N(   R3   (   Re   t   other(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   __eq__   s    c         C   s   t  |  j  S(   N(   t   hashR3   (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   __hash__   s    c         C   s   t  j |  j |  j  S(   N(   t	   posixpathR   R2   R*   (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   _remote_path   s    c         C   s   t  j j |  j |  j  S(   N(   RA   RB   R   R1   R*   (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   _local_path  s    c         C   s    t  j j |  j d d |  j  S(   Nt   updatess   ksplice-(   RA   RB   R   R1   R3   (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt
   _tree_path  s    c         C   s$   t  j j |  j d d |  j d  S(   NRp   s   ksplice-s   .incomplete(   RA   RB   R   R1   R3   (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   _tree_flag_path
  s    c         C   s   |  j  S(   N(   Rd   (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   get_verify_hashes  s    c      
   C   sz  t  j j |  j  s/ t j d d |  j f  Sy t |  j  } Wn; t k
 r t	 j
 t j    t j d d |  j f  SX|  j   } t | |  s+g  } xJ t D]B } | | k r | j d j d | d | | d | |   q q Wt	 j
 d |  j d	 j |  f  t j d d
 |  j f  St  j j |  j  sVt  j j |  j  rpt j d d |  j f  St j   S(   Ni   s(   Update file does not exist for update %ss   Unable to read update file %ss&   {algo}(got {got}, expected {expected})t   algot   gotR   s   %s: invalid checksum: %ss   , s   Invalid checksum for update %s.s    Update %s has not been unpacked.(   RA   RB   t   isfilet
   local_pathR#   t   ResultR3   R0   t   IOErrorRU   RW   R	   t
   format_excRs   R!   R   t   appendt   formatR   t   isdirt	   tree_patht   tree_flag_path(   Re   t	   file_hasht   verify_hasht
   mismatchesRt   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   checkValidFile  s,    
	c         C   s   |  j    j d k S(   Ni    (   R   t   code(   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   isValidFile)  s    c      	   C   s   d   } t  |  j d  t j |  j d t t j d d d |  j d t	 j
 j |  j d  g d	 t j d
 t j d | } | j   d } | j r t j | j |  St	 j |  j  t j   S(   Nc           S   s   t  j  t  j t  j  d  S(   N(   t   signalt   SIGPIPEt   SIG_DFL(    (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   fix_sigpipe-  s    t   wt   ignore_errorst   tars   --force-locals   -xzfs   -CRp   RJ   RK   t
   preexec_fni    (   t   fileR   t   shutilt   rmtreeR~   t   TrueRP   RQ   Rw   RA   RB   R   R1   RR   Rb   RS   RT   R#   Rx   t   unlink(   Re   R   R[   t   output(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   unpack,  s    			c         C   s   t  j j |  j d  } t  j j |  sE t  j j |  j d  } n  y t j |  SWn6 t k
 r t j	 d |   t j	 t
 j    d SXd  S(   Nt   detailst   patchs"   Could not retrieve details from %sR   (   RA   RB   R   R~   Rv   R#   R$   Ry   RU   RW   R	   Rz   (   Re   R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt
   getDetails<  s    c         C   s   d |  j  } t j j |  rZ t j j | d  } t j j |  rS t j |  Sd Sn  d |  j  } t j j |  r t j j | d  } t j j |  r t j |  Sd Sn  t j j |  j d  } t j j |  r t j |  Sd Sd  S(   Ns   /sys/module/ksplice_%s/ksplicet   core_versiont   0s   /sys/kernel/ksplice/%s(   R3   RA   RB   t   existsR   R#   R$   R~   (   Re   t   ksplice_dirt   core_version_file(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   getCoreVersionG  s     c         C   s   g  } | } | s t    } n  g  |  j D] } t |  ^ q( } xC | D]; } | | k rG d |  j | f | k rG | j |  qG qG W| S(   Ns   ksplice_%s_%s_new(   R`   R7   RH   R3   R{   (   Re   t   loadedModulest   lockedt   modulest   xR7   t   t(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   lockedModulesa  s    "%c         C   s   t  |  j |   d k S(   Ni    (   RZ   R   (   Re   R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   isLockedl  s    c      	   C   s   t  j |  |  } t j | d t j d t j } | j   d } | j d k rV | St  j t	 j
 j t   t j | d t d g d t j d t j } | j   d j d  } | j d k r y t	 j t  Wn t k
 r n X| S| j | _ | d | _ | | _ y t  j t  | _ Wn t k
 r9n X| j d k rg  | d D]' } t | j    rT| j d	  ^ qT| _ nu| j d
 k r|  j   | _ nT| j d k s| j d k rLg  | _ g  |  j D] } t |  ^ q}	 t j d  t j |	  t t  t!    j" |	   | _ t j d  t j | j  n | j d k rt    }
 x t!   j#   D]r \ } } | d |  j$ k s| j% d |  j$ d  rt|
 t  g  | d D] } | j% d  s| ^ q O}
 qtqtWt |
  | _& n  | S(   NRJ   RK   i    s   --debugfiles   --raw-errorsi   s   
t	   code_busyt    t   cold_update_loadedt   failed_to_findt   no_matchs&   Run/pre matching failed; targets were:s   Loaded target modules were:t   module_busyt   ksplice_R@   RO   ('   R#   t   ActionResultRP   RQ   RR   Rb   RS   RT   t   mkdirpRA   RB   t   dirnamet   KSPLICE_DEBUG_FILERD   t   removet   OSErrorR   t
   abort_codet   messageR$   RW   Ry   RZ   RY   t   stack_check_processesR   t   locked_modulest   nomatch_modulesR7   RH   RU   t   listt   setR`   t   intersectionR(   R3   t
   startswitht   usedby_modules(   Re   t   commandt   argst   resR[   R   t   linest   lineR   t   target_modulesR   t   modnamet   modinfot   d(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   runKspliceCommando  sX    			>	"!	-=c         C   sh  d | k r t  | d <n  d | k r2 d | d <n  d | k rK d | d <n  | j sX d S| j d k r>d g  | j D] } | d ^ qt k } | r | d r t j d  t d	  t j d
  t	 | d <d S| t
 k r t j d  d S| d t k  r7t j d | d d
  t j d
  | d c d
 7<d Sd Sn&| j d k r@| d d
 k  r@t j r@t   } g  |  j D] } t |  ^ qy} g  t j D]$ }	 |	 | k r|	 | k r|	 ^ q}
 g  } t j sx- |
 D]" } t |  r| | g 7} qqWn  | r9t j d t |  d  | d c d
 7<d Sd Sn$ | j d k r`t j d  d Sd Sd S(   s  
        Logic for deciding whether to retry a runKspliceCommand.

        'retryData' is a dict which stores information on the number
        of times we have retried the command due to various causes.
        The caller can pass a new empty dict the first time it tries
        to execute a given command.

        shouldRetry() returns one of the strings 'Success', 'Failure',
        or 'Retry'.  In the 'Retry' case, the 'retryData' argument
        will have been modified to reflect the retry that occurred.
        t   DidRfcommRetryt   CodeBusyRetriesi    t   RemoveModulesRetriest   SuccessR   t   krfcommds3   Stack check against rfcomm module; trying to removet   rfcommi   t   Retrys   Slow stack check failuret   Failures    Stack check failure %d, retryingR   R   s   Removed modules s
   , retryingt   key_not_availables'   Signing key was not found in the kernelN(   s   no_matchs   failed_to_find(   R   R   R   R   RU   RW   Ra   t   timet   sleepR   t   CODE_BUSY_MAX_DELAYt   CODE_BUSY_RETRIESt   configt   removableModulesR`   R7   RH   t   no_rmmodt   str(   Re   R   t   durationt	   retryDatat   proct   rfcomm_stack_checkR   R   t   targetModulest   mR   t   modulesRemovedRc   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   shouldRetry  sX    	&

	"4	c         C   s  t  } |  j   } | j rI t j |  |  } | j | _ | j | _ | Si  } x t d t d  D] } t j   } |  j	 | d d |  j
 g  } t j   } |  j | | | |  } | d k r Pqc | d k r | t k  r qc | Sqc W|  j st | _ | Sd t j }	 d t j }
 t j j |	 d	  } t j |  t j |
  t g  |  j D]$ } t |  t | d
 t f ^ qW } yt j j |  j
 d  } x t j |  D] \ } } } x | D] } t |  } | d  k s| | k rqn  | j |  } d |	 | f } t j j |  r[t j j |
 d | |  j f  } t j | |  n  t j t j j | | |  |  qWqWWnN t k
 rt j | _ d |  | _ t  j! | j  t  j! t" j#    | SX| rt j | _ d |  d d j |  | _ t  j! | j  | Sd } t j |  x g  |  j D] } t | d
 t ^ q;D]e } d | | f } t j j$ |  sWd | t j f } t  j! d | j%    t j& | |  qWqWWt' | _ | S(   Ni    i   s   /usr/lib/uptrack/ksplice-applys	   --partialR   R   s   /var/run/ksplice/modules/%ss   /var/run/ksplice/modules.old/%st   kspliceRF   R   s   %s/ksplice/%s.kos   %s_pre_%s.kos%   Failure in extracting modules from %ss)   Could not retrieve some modules from %s:
s	    missing R   s   /var/run/ksplice/depmod.ds
   %s/%s.confs'   override %s %s.ksplice-updates ksplice
s   Adding new depmod entry: %s((   t   INSTALLR   R   R#   R   R   t   ranget   MAX_RETRIESR   R   R~   R   R7   R   t   depmod_neededR   t   releaseRA   RB   R   R   t   dictRH   t   walkR   t   popRv   R3   t   renamet   symlinkRy   t   ERROR_GENERIC_ERRORRU   RW   R	   Rz   R   RY   t
   write_fileR   (   Re   t   cmdt   rR   R   t   previousRetriest	   starttimet   endtimet   contt   modroott	   backupdirt   moddirR   R7   t   update_modrootR   R@   t	   filenamesR*   t   canonical_targett   target_proper_casingt   modpatht   backupt
   depmod_dirt   targett   depmod_filet   entry(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   applyUpdate  s    				:
/	c         C   s  t  } i  } x t d t d  D] } t j   } |  j | d |  j g  } t j   } |  j | | | |  } | d k r Pq  | d k r | t k  r q  | Sq  W|  j s t | _	 | Sd } d t
 j }	 d t
 j }
 xg  |  j D] } t | d	 t ^ q D]} d
 | | f } d |	 | f } t j j |
 d | |  j f  } t j j |  rnt j |  n t j d | |  j f  t j j |  ry t j | |  Wqt k
 rt j d | | f  t j t j    qXqt j j |  rpy1 t j d t j |  j    t j |  Wqt k
 rlt j d | f  t j t j    qXqt j d | |  j f  qWt | _	 | S(   Ni    i   s   /usr/lib/uptrack/ksplice-undoR   R   s   /var/run/ksplice/depmod.ds   /var/run/ksplice/modules/%ss   /var/run/ksplice/modules.old/%sRF   s
   %s/%s.confs   %s/ksplice/%s.kos   %s_pre_%s.kos*   Missing patched module %s while undoing %ss%   Failed to restore old module %s -> %ss   Removing depmod entry: %ss   Failed to remove depmod file %ss0   Missing depmod override file %s while undoing %s(   t   REMOVER   R   R   R   R3   R   R7   R   R   R   R   RH   RA   RB   R   Rv   R   RU   t   warningR   Ry   RW   R	   Rz   R#   R$   RY   R   (   Re   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt
   undoUpdateD  s\    			/"		 			N(   t   __name__t
   __module__Rf   Rg   Rh   Rj   Rl   Rn   t   propertyt   remote_pathRo   Rw   Rq   R~   Rr   R   Rs   R   R   R   R   R   R   R   R   R   R   R   R  (    (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR:      s2   																@	D	Qc           C   s)   t  j j t  r% t j t  j   Sd S(   Ns   -1(   RA   RB   R   t   API_VERSION_FILER#   R$   RY   (    (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   kspliceToolsApiVersion{  s    c         C   s5  y t  j  |   d } d | k r/ | d 7} n  t j d d d | g d t d  d	 t j d
 t j } t j d d d d g d | j d	 t j d
 t j } | j   x4 | j D]) } | j d  r | t d  j	   Sq WWnN t j
 k
 r0t j d  t j | j j    t j | j j    d  SXd  S(   Ni   t   :s   :443t   opensslt   s_clients   -connectt   stdins	   /dev/nullRJ   RK   t   x509s   -fingerprints   -sha1s   SHA1 Fingerprint=s-   Error reading server certificate fingerprint.(   t   urlparseRP   RQ   t   openRR   RJ   t   waitR   RZ   RY   RX   RU   RW   RK   t   readR   (   t   urlt   netloct   connR  R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   serverFingerprint  s,    			
t   UptrackRepoc           B   s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z RS(   c         C   s   d  |  _ t |  _ t j | j t j | j	  t j | j
  t j | j  t j | j   |  _ | j |  _ t j j |  j d  |  _ t   |  _ t |  _ d  |  _ t |  _ d  S(   Ns   packages.yml(   R   Rp   t!   UPTRACK_PACKAGES_PROTOCOL_VERSIONt   protocolVersionRm   R   t   remotet   urllibt   quotet   sysnamet   archR   t   versionR2   t   localR1   RA   RB   t   local_package_listR  t   __version__t   clientVersiont
   userStatusR   t   expired(   Re   R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyRf     s    				c   	      C   sy  t  j d  t j d d d t d d d | d d	 g
 d
 t j d t j } | j   \ } } | rt t  j |  n  | r t  j |  n  | j r t j	 d d  Sg  | j
   j d  D] } | j d  ^ q } g  | D] } | d d k r | ^ q } t |  d k  rt j	 d d  St |  d k rAt j	 d d  S| d d | k ret j	 d d  St  j d |  d  S(   Ns   Verifying key fingerprint...t   gpgs   --no-optionss	   --homedirs   --no-default-keyrings   --batchs	   --keyrings   --fingerprints   --with-colonsRJ   RK   i   s*   Ksplice Uptrack failed to read fingerprints   
R	  i    t   fprs/   Ksplice Uptrack could not find any fingerprintss+   Ksplice Uptrack found too many fingerprintsi	   s4   Ksplice Uptrack could not verify the key fingerprints   Verified GPG fingerprint on %s(   RU   RW   RP   RQ   t   UPTRACK_GPG_HOMEDIRRR   RS   RT   R#   Rx   RY   RD   RZ   R   (	   Re   t   keyringt   fingerprintR[   RJ   RK   R]   t   listingst   fprs(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   verifyKeyring  s8    			  	1)c   	      C   s   t  j t j  r d  S|  j t t  } | r2 | St t j  } t	 j
 d |  | d  k rz t  j t  j d t  j f  St j j t j | d  } y[ t  j t  j   t j t j d | d  |  } | d k r t  j d d t  j f  SWnU t j k
 rH} t	 j
 d	 | d
 | d f  t	 j
 t j    t  j t |  SXd  } z{ t j   \ } } t j | d  } | j | d  | j   |  j | | d t st  j d d t j t  j f  SWd  y | rt j  |  n  Wn t! k
 rn XXd  S(   Ns   Got a server fingerprint: %ss   Unable to communicate with your site's Uptrack server.

Please ensure that the update_repo_url setting is correct in
/etc/uptrack/uptrack.conf, and that your Uptrack server is properly configured.
If you need help resolving this issue, please contact %s.s   .sigt   serveri   i0  i   s[   Unable to download the signature for your Uptrack server.
Please contact %s for assistance.s3   cURL error %d (%s) while checking server signature.i    R   s   
R(  s   Unable to verify that the server at <%s>
is an authorized Ksplice Uptrack server. Please contact
Ksplice at <%s> for assistance.(   i   i0  ("   R#   t   server_is_oracleR   t
   remoterootR   R,  t   SERVER_KEYRINGt   SERVER_KEY_FINGERPRINTR  RU   RW   Rx   t   ERROR_NO_NETWORKt	   BUG_EMAILRA   RB   R   t	   localroott   downloadt   getCurlRm   t   pycurlRV   R	   Rz   t   resultFromPycurlt   tempfilet   mkstempt   fdopent   writet   closet   verifySignatureR   R   (	   Re   R   R)  t   sigpathR   t   et   fpfilet   fdt   fh(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   validateServer  s\    
		
c   
      C   s   d  } t j t j t j d   } t j j t j	 d  } t
 j d |  t j   } yMt d t j    } t j j t |  t j | d d d t d t } t j   } | j t j |  | j t j d | f g  | j t j | j  | j   | j t j  } | d	 k s*| d
 k ry t j | | j    Wn3 t  k
 ry}	 t
 j d  t
 j t! j"    n Xy t j# | j    |  _$ Wqt% j& k
 rt
 j d  t j' t j( d t j) f  } qXn d | k od k n r+t
 j d t j*  t j' t j+ d t j,  } nz t
 j d |  t
 j d  t
 j | j    d | k ord k n rt j- j. } n t j' t j/ d t j) f  } Wns t j0 k
 r}	 t
 j d |	 d |	 d f  t
 j t! j"    t j1 t |	  } n t j2 k
 r}	 |	 j. SX| S(   Nt   statuss4   Verifying your access key is valid by requesting: %st   SerialR  i   t   explicit_startt   explicit_endt   requesti   i0  s   Error writing status file.s.   Malformed YAML response when checking the key.s   The server returned an unexpected response.
Please try again in a few minutes. If this problem persists, 
please contact %s for assistance.i  i  s    Your access key (%s) is invalid.sp   Could not connect to the Ksplice Uptrack server with your access key.
Please check that the key in %s is valid.
s,   Unexpected error retrieving status file (%d)s   The server said:i  iW  s   Unexpected error communicating with the server.
Please try again in a few minutes. If this problem persists, 
please contact %s for assistance.s&   cURL error %d (%s) while checking key.i    (   i   i   (3   R   Rm   R   R   R  R  R  RA   RB   R4  RU   RW   t   StringIOR   t   incrementSerialR#   t   Statust   addIdentityt	   yaml_dumpR   R6  t   setoptR7  t   URLt   HTTPPOSTt   WRITEFUNCTIONR<  t   performt   getinfot   RESPONSE_CODER   t   getvalueRy   R	   Rz   t	   yaml_loadR#  t   yamlt	   YAMLErrorRx   t   ERROR_MALFORMED_YAMLR3  t	   accesskeyt   ERROR_INVALID_KEYt   UPTRACK_CONFIG_FILEt   server_error_exceptionR\   t   ERROR_INTERNAL_SERVER_ERRORRV   R8  t   ResultException(
   Re   t   errt	   key_checkt	   localpatht   sRI  t   contentst   cR   R@  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   downloadUserStatus  sl    	
	c         C   s   |  j  d  k r d  Sy d |  j  k rJ |  j  d } t j | d | d  St j rj |  j  j d  rj d  Sd |  j  k r t j |  j  d  n  d |  j  k r t j	 |  j  d  n  Wn* t
 t f k
 r t j d d t n Xd  S(   Nt   Errort   Codet   Messaget   Cront   Warnings   Error parsing user status: R   (   R#  R   R#   Rx   R   t   cronR;   RU   t   infoRV   t	   TypeErrort   AttributeErrorRW   R   (   Re   Ra  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   showUserStatusK  s    c         C   s   |  j    } | r | Sy d |  j k r5 t j   n  d |  j k r[ t j |  j d  n  d |  j k r t j r t j t _ t j t j	    |  j    } | r | Sn  Wn t
 k
 r n X|  j   S(   Nt   RegenerateCront   Backofft   RegenerateUUID(   Rg  R#  R   t   regenerateCront   updateBackofft   use_hw_uuidt   uuidt   olduuidt   setUUIDt   newUUIDRo  Rq  (   Re   Ra  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   handleStatus_  s"      c         C   s5  t  j d |  j  d  } yut j   } xbd d g D]T} t j |  j |  } t j	 j |  j
 |  } y t j | d  Wn t k
 r n Xt j   } t j | | | d | } | d k r q6 n | t k rt  j d | d f  t j | d | j    q6 nz | d k rVt j t j d t j t j t j f  } t  j d  n3 t j t j d | t j f  } t  j d |  | SWWn t j k
 r} t  j d | d | d f  t  j t j    t j t |  } nF t k
 r0t j t j d t t j f  } t  j t j    n X| S(   Ns(   Getting package list and signature from s   packages.ymls   packages.yml.sigs   .expiredt   stringioi   i0  s   Writing expired data to %si  i  s
  Cannot find Ksplice Uptrack information for your kernel version
(%s %s).
Your kernel is probably not yet supported by Ksplice Uptrack.
See http://www.ksplice.com/uptrack/supported-kernels for a summary of
what kernels are supported.
Please contact %s with questions.s7   Error downloading package list.  Checking key validity.s   Unexpected error connecting to the Ksplice Uptrack server.
The web server returned HTTP code %03d.  If this error persists,
please contact %s.s)   Received unexpected HTTP error code %03d.s2   cURL error %d (%s) while downloading package list.i    i   s   Could not save the package list from the Ksplice Uptrack server.
More details may be available in %s.
If this error continues, please e-mail %s.(   i   i0  (   i  i  (    RU   RW   R2   R   R#   R6  Rm   R   RA   RB   R1   R   R   RJ  R5  t   HTTP_CODE_EXPIREDR   RV  Rx   t   ERROR_UNSUPPORTEDR   R   R  R3  R2  R7  RV   R	   Rz   R8  Ry   t   LOGFILE(   Re   Ra  Rf  R*   R  Rd  t   rcodeR@  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   downloadPackageListt  sP    		c         C   s   | d  k r t } n  t j d | f  t j d d t d | | | g d t j d t j } | j   \ } } | r t j |  n  | r t j |  n  | j	 r t
 St S(   Ns   Verifying signature on %s...t   gpgvs	   --homedirs	   --keyringRJ   RK   (   R   t   KEYRINGRU   RW   RP   RQ   R'  RR   RS   RT   R   R   (   Re   R   t   sigfileR(  R[   RJ   RK   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR>    s$     				  	c   	      C   sD  t  j j |  j  s. t j t j d  d  f S|  j |  j |  j d  s` t j d d  d  f St	 j
 d |  j  y t j t |  j   } t  j j |  j d  r
|  j |  j d |  j d  s t j d d  d  f St j t |  j d d   } | | d	 <n  Wn t t j f k
 rt	 j
 d
 d d t j   } t j s[t j | _ n  d | _ t j r| j d 7_ n | j d t j f 7_ | d  f SX| d } | d } |  j | k rt t _ t j d d |  j | f  d  f S| j d d  } t j |  j |  d k  rNt t _ t j t j d |  j | f  d  f S| d } t j | d k rt j d d t j | d f  d  f St j  | d k rt j d d t j  | d f  d  f St j! | d k rt j d d t j! | d f  d  f Sd | k r:| d } t j | d | d  d  f Sd  | f S(    Ns0   Ksplice Uptrack could not find the package list.s   .sigi   s<   Ksplice Uptrack could not verify the package list signature.s!   Trying to read package list at %ss   .expireds   .sig.expiredR   t   Expireds   Error reading the package listR   s   Cannot load the package list.
sM   Please re-run the Ksplice Uptrack client with a network connection available.s   Please report a bug to %st   Clients   Protocol versionsZ   Protocol version mismatch: %s != %s
Please use your package manager to update this client.s   Version to ParseR   i    se   Ksplice Uptrack client too old: %s, require %s
Please use your package manager to update this client.t   Kernelt   Releases!   Kernel release mismatch: %s != %st   Versions!   Kernel version mismatch: %s != %st   Architectures   Wrong architecture: %s != %sRh  Ri  Rj  ("   RA   RB   R   R   R#   Rx   R2  R   R>  RU   RW   RW  R  Rv   Ry   RX  RY  R   t   initR   R   t   allow_no_netR3  R  R   R  t
   new_clientR;   t   compareversionsR"  t   ERROR_TOO_OLD_PARSER   R  R  (	   Re   t   plR$  Ra  t   clientR  t   needVersiont   kernelR@  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   readPackageList  st    
				

			

c   	      C   s  |  j    \ } } | d  k r" | Si  } xF t | d  D]4 \ } } t | |  j |  j |  } | | | j <q9 W| |  _ | d j d d  } t	 j
 |  j |  d k  r t t _ t	 j t	 j d |  j | f  S| d d } |  j d k rt	 j d	 d
 t f  St	 j
 |  j |  d k  rIt t _ t	 j d	 d |  j | f  S|  j | k r{t	 j d	 d |  j | t	 j f  S| j d  a | j d  a | j d  a t rt st j rt j t  n  | j d  } | rt |  _ d | k rt j | d  qn  | S(   Nt   UpdatesR  s   Version to InstallR   i    se   Ksplice Uptrack client too old: %s, require %s
Please use your package manager to update this client.s   Ksplice Tools API versions   -1i   s$   Error: %s: No such file or directorysp   Ksplice Uptrack client too old: tools API version %s < %s
Please use your package manager to update this client.s[   Ksplice Uptrack client too new: tools API version %s > %s
Please report this problem to %s.t   Alertt   Desupportedt   TrayIconErrorR  Rj  (   R  R   t	   enumerateR=   R1   R2   R3   Rp   R;   R#   R  R"  R   R  R  Rx   t   ERROR_TOO_OLD_INSTALLR  R  R3  t   alertt   desupportedt   tray_icon_errorR   Rm  RU   R  R$  (	   Re   Ra  R  t   packagest   iR<   t   uR  R$  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   parsePackageList  sP    								c         C   s  t  j d  |  j j   } | j t j  x}| D]u} | j   r\ t  j d |  q3 n  t  j d |  yv t j t	 j
 j | j   t j t j   | j | j d t } | d k r t j d d | j | t j f  SWn t t j f k
 r}t j   } t j | _ d | t j f | _ t  j d	 | j  t  j d
 | j  t  j d | j  t  j t j    | SXt  j d |  | j   } | j r3 | Sq3 Wd  S(   Ns   Downloading packages.s   Already downloaded %s, skippings   Downloading %st
   ifmodifiedi   i   sz   Unexpected error downloading update %s.
The web server returned HTTP code %03d.
If this error persists, please contact %s.sv   Couldn't download update '%s'.
Please check your network connection and try again.
If this error continues, e-mail %s.s   Error downloading update %s.s
   Remote: %ss	   Local: %ss   Unpacking %s(   RU   RW   Rp   t   valuest   sortR#   t	   cmp_orderR   R   RA   RB   R   Rw   R5  R6  R  R   Rx   R3   R3  Ry   R7  RV   R   R   R   R*   R	   Rz   R   (   Re   Rp   R  R  Ra  R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   downloadPackagesF  s@    				c         C   s6   t  j   } | r | St  j   } | r, | St  j   S(   N(   t   repoR  R  R  (   Re   R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   downloadAllm  s    c         C   s+   |  j  d  k r d  n  t |  j  j    S(   Ns(   BUG: Package list has not yet been read.(   Rp   R   R   R  (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   getAllUpdatesv  s    	c         C   s    |  j  r |  j  j | d  Sd S(   sY   
        Turns ID into Update, or returns
        None if we don't know about it
        N(   Rp   R;   R   (   Re   R3   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt
   idToUpdate{  s    	N(   R  R  Rf   R,  RD  Rg  Rq  R|  R  R   R>  R  R  R  R  R  R  (    (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR    s   			=	E			:	S	4	'			t   AlarmSignaledc           B   s   e  Z RS(    (   R  R  (    (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR    s   c         C   s
   t   d  S(   N(   R  (   t   sigt   frame(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   onAlarm  s    c          C   s   t  j j t j  }  t  j j |   sP y t  j |   WqP t k
 rL t SXn  d  } zj yK t
 j
 t
 j t  } t t j d  } t
 j t  t j | t j  Wn t t f k
 r t SXWd  t
 j d  | d  k	 r t
 j
 t
 j |  n  X| S(   NR   i    (   RA   RB   R   R   t   lockfileR}   t   makedirsRy   R   R   R   t   SIGALRMR  R  t   alarmt   LOCK_TIMEOUTt   fcntlt   flockt   LOCK_EXR  (   t   lockdirt   old_handlert   f(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   getLock  s&    	c           C   s!   t  j t t  j  t j   d S(   s   
    The fd is closed when the variable goes out
    of scope or the process is exited, so this shouldn't
    really be necessary, but is here in case you want
    to explicitly release the lock
    N(   R  R  t   lockt   LOCK_UNR=  (    (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   releaseLock  s    t   UptrackClientConfigc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s  t  t |   j   t t j j |   } | t k r@ d } n? | t k rU d } n* | t	 k rj d } n | t
 k r d } n  t d |  } | j d d d d	 d
 d d d d d | j d d d d d d d d d d | j d d d d d d t d d | j d d d d d d t d d | j d d d d d d t d d | j d  d d	 d d! d d  d
 d" d t | j d# d d	 d d! d
 d$ d t | j d% d d	 d d! d
 d& d t | j d' d d d d( d t d t | j d) d* d d d d+ d d, d t | j d- d d d d. d t d t t d/ d d d d0 d t d d1 } t d2 d d d d3 d t d d4 } t d5 d6 d7 d d8 d d d d9 } t d: d d d d; d t d t }	 t d< d d d d d t d d= }
 t d> d d d d? d t d t } i | |
 | g t	 6| g t 6| | | g t 6| |	 g t
 6} | | k rzx" | | D] } | j |  q`Wn  | j |  \ } } | |  _ | |  _ |  j j r|  j j r| j d@  n  t |  j d8  r|  j j d k  r| j dA  n  |  j   |  j   d  S(B   NsJ   usage: %prog [options] <id>...
Install selected patch to a running kernel.sM   usage: %prog [options] <id>...
Remove selected patches from a running kernel.sK   usage: %prog [options] [<id>...]
Display which updates have been installed.sC   usage: %prog [options]
Apply available updates to a running kernel.t   usages   -qs   --quiett   actiont   store_constt   constit   destt   verboset   helps   don't print status messagess   -vs	   --verboset   counts4   provide more detail about what this program is doingt   defaulti    s   -yt
   store_truet
   answer_yess    answer 'yes' to all user promptss   -nt	   answer_nos   answer 'no' to all user promptss   --allt   alls   take action for all updatess   --initR  t   earlys   --late-initt   lates
   --shutdownt   shutdowns   --check-initt
   check_inits   -Vs	   --versiont   show_versions&   print the version information and exits   --i-accept-the-terms-of-servicet
   accept_toss   --no-networkR  s   Don't use the network.s   --availablet	   availables   Also show available updates.s   --waitt   typet   floatR  s%   time to wait between applying updatess   --cronRm  s   --counts)   Display the number of upgrades installed.s   --uninstallt	   uninstalls#   Please supply only one of -y or -n.s    --wait argument must be positive(   t   superR  Rf   t   extractCommandRA   RB   RC   R   R   t   SHOWt   UPGRADER    t
   add_optionR   R   R   R   t
   parse_argst   optionsR   R  R  RV   t   hasattrR  t   setVerbosityt   setTask(   Re   t   programR   R   R  t   parsert
   opt_no_nett   opt_availablet   opt_waitt   opt_cront	   opt_countt   opt_uninstallt   optmapt   optionR  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyRf     s    													
		$
c         C   s   |  j  j |  _ d  S(   N(   R  R  (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR    s    c         C   s  t  j j d  |  _ d t j d  k |  _ |  j j |  _ |  j j	 |  _	 t
 |  j d t  |  _ |  j j |  _ t |  j d  r |  j j |  _ n  t |  _ t |  _ t |  _ t |  j d  r |  j j r t |  _ t |  _ t |  _ n  t j |  j d d t  |  _ t j |  j d d	 t  |  _ t j |  j d d
 t  |  _ t |  j d  r|  j j rt |  _ |  j |  _ |  j |  _	 d |  _ n  t |  j d  rN|  j j rN|  j j |  _ |  j d 8_ |  j d k rt |  _ t |  _	 t |  _ qN|  j d k r'|  j |  _ |  j |  _	 qN|  j d k rNt |  _ t |  _	 qNn  t |  j d  rr|  j j |  _ n  |  j j |  _ d  S(   Ns   /etc/uptrack/disablet	   nouptracks   /proc/cmdlineR  R  R  t   Settingst   autoinstallt   install_on_reboott   upgrade_on_rebootRm  iR  i   R  R  R  R  (   RA   RB   Rv   t   disabledR#   R$   t
   disablecmdR  R  R  t   getattrR   R  R  R  R  Rm  R  R  R   t   getConfigBooleanOrDieR   t   cron_autoinstallR  R  R  R  R  (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR    sT    									c         C   s   |  j  r d  St } x< d	 D]4 } d | } t j |  j d | t  r t } q q W| r t j d  t j d  t j d  n  d  S(
   Nt   installR  RV   t   cron_output_R  sA   Warning: The cron output configuration options have been removed.sB   Please visit <http://www.ksplice.com/uptrack/notification-options>s   for more information.(   R  s	   availables   error(   Rm  R   R#   R  R   R   RU   R  (   Re   t   show_cron_output_warningt   suffixR  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   checkDeprecatedOptionsL  s    	
(   R  R  Rf   R  R  R  (    (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR    s   	i		5t   PermissionedRotatingFileHandlerc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   si   
    A subclass of logging.handlers.RotatingFileHandler which sets user,
    group, and permissions.
    c         K   s   | |  _  y0 t j t  d |  _ t j t  d |  _ Wn# t	 k
 r^ d  |  _ d  |  _ n Xt d A|  _ t j |  j  } t j j j |  | |  t j |  |  j   d  S(   Ni   i  (   t   _ks_filenamet   pwdt   getpwnamt   LOGUSERt   _ks_uidt   grpt   getgrnamt   LOGGROUPt   _ks_gidt   KeyErrorR   t   LOGMODEt	   _ks_umaskRA   t   umaskRU   t   handlerst   RotatingFileHandlerRf   t   _ksplice_chown(   Re   R*   t   kwargst   old(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyRf   `  s    		c         C   sK   |  j  d  k r d  Sy  t j |  j |  j  |  j  Wn t k
 rF n Xd  S(   N(   R  R   RA   t   chownR  R  R   (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR
  q  s     c         O   s<   t  j |  j  } t j j j |  | |  t  j |  d  S(   N(   RA   R  R  RU   R  R	  t   emit(   Re   R   R  R  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR  {  s    c         O   s'   t  j j j |  | |  |  j   d  S(   N(   RU   R  R	  t
   doRolloverR
  (   Re   R   R  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR    s    (   R  R  t   __doc__Rf   R
  R  R  (    (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR  [  s
   		
	t   Loggerc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   sL  t  j d  } | j t  j  t  j } t t  _ t  j t j	  |  _
 |  j
 j |  t  j d  } |  j
 j |  t  j d  } t t d d
 d d } | j t  j  | j |  t j   |  _ t  j |  j  |  _ |  j j t  j  |  j j |  t  j d  j |  t  j d  j |  j
  t  j d  j |  j  d  S(   NR   s   %(message)ss'   %(asctime)s %(levelname)-8s %(message)st   maxBytesg      @i   t   backupCounti   g      @g      DA(   RU   t	   getLoggert   setLevelt   DEBUGt   INFOR   t   raiseExceptionst   StreamHandlerR   RJ   t   console_loggert	   Formattert   setFormatterR  R  RJ  t	   debug_logt   debug_loggert
   addHandler(   Re   t	   my_loggert   consoleLevelt	   formattert   fformatt
   filelogger(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyRf     s*    				c         C   s9   y* t  j d  j |  j  |  j j   SWn d  SXd  S(   NR   (   RU   R  t   removeHandlerR  R  RV  R   (   Re   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   getDebugLog  s
    c         C   sn   t  j } | j d k  r$ t  j } n6 | j d k  r? t  j } n | j d k rZ t  j } n  |  j j |  d  S(   Nii    (   RU   R  R  t   CRITICALt   ERRORR  R  R  (   Re   R   R!  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt	   configure  s    	(   R  R  Rf   R&  R)  (    (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR    s   		c         C   s   t  j r t St  j r t St j d  d } y t d |   } Wn t t	 f k
 r[ Hn Xt
 |  d k  s | d j   d k r t St S(   NR   t   ns
   %s [y/N]? i   i    t   y(   R   R  R   R  R   RU   Rn  t	   raw_inputt   KeyboardInterruptt   EOFErrorRZ   t   lower(   t   msgt   take_action(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   confirm  s    		(c         C   sW   t  j r. g  | j   D] } | j ^ q } n  t |  | g  | D] } t | f ^ q>  S(   N(   R   R  t   getInstalledUpdatesR3   t   planAndDoActionsR   (   R  R  t   wish_to_removeR  R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   doRemove  s    	%c         C   s   t  j r y" t |  | g   \ } } } } Wn t j k
 rG } | j SXt |  d k r} t  j s t   t	 j
 d  q n t   t |  | j d  | | |  t j   St |  | t d f g  } | j s t  j s t	 j
 d  t   q n  | S(   Ni    s   Nothing to be done.t   heads    Your kernel is fully up to date.(   R   R  t   planActionsR#   R`  R\   RZ   Rm  t   printEffectiveRU   Rn  t   displayAndConfirmt   writeOutStatusR   Rx   R4  R   R   (   R  R  R@   t   new_upgradet   new_initt
   new_removeR@  R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt	   doUpgrade  s&    	"	

		c         C   sP   t  j r t |  |  St |  | g  | D] } t | f ^ q&  } t   | Sd  S(   N(   R   R  R?  R4  R   R9  (   R  R  t   wish_to_installR   R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt	   doInstall  s
    	+c         C   sM   t  j   } | d  k	 rI |  r. t j d  n  t j d | d f  n  d  S(   NR   s   Effective kernel version is %st   PackageVersion(   R  t   getEffectiveR   RU   Rn  (   t
   blank_lineR  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR9    s    	c      	   C   s  t  j d t |   | j   } g  } x | D] } | \ } } |  j |  } | d k r | d k r t  j d | f  q0 | t k r | | k r t  j d | f  q0 | t k r | | k r t  j d | f  q0 | j	 |  q0 W| } g  | D] }	 |	 j
 ^ q }
 t   } g  | D] }	 |	 j |  r!|	 j
 ^ q!} t j | |
 |  } | j |  } g  d D] } | | ^ qp\ } } } } d
 | k r| j | d
  n  t g  | | | | D] } | d |  j k ^ qk r|  j   } | r&| j d k r&t j | j | j   n  xi | | | | D]R } | d |  j k r9t j t j t j d | d j   | d f    q9q9Wn  | j |  | j |  | j |  | j |  | | | | f S(   s  :: Repo -> Local -> [Action] -> IO (Plan, Plan, Plan, Plan)
    data Action = Install Kid | Remove Kid
    -- Implemented as (INSTALL|REMOVE, Kid)
    -- Installing the pseudo-kid "head" means "upgrade fully".
    type Plan = [(INSTALL|REMOVE,Update)]

    Given a set of requested actions, return a set of four plans
    appropriate to carry out those actions and then update our state.

    The four returned plans are, in order:
    *) A plan that includes the requested actions.
    *) A new upgrade plan that is what one would need to do to fully
       update the machine assuming we perform the first plan
       succesfully.
    *) A new init-time plan that is used to take a rebooted machine
       back to the state it would be in after we perform the first
       plan succesfully.
    *) A new remove-all plan, assuming we perform the first plan
       succesfully. (this is used if we are trying to remove all
       updates and don't have network connectivity).

    s$   Constructing plans for the actions: R7  s   Unknown update %s, skipping.s)   Update %s is already installed, skipping.s%   Update %s is not installed, skipping.t   Stepss   Upgrade Plans	   Init Plans   Remove Plant   EffectiveKernelR4   i    sm   Error: Server asked that we %s unknown update %s.
Please report this issue to ksplice-support_ww@oracle.com.
t   CommandN(   RE  s   Upgrade Plans	   Init Plans   Remove Plan(   RU   RW   R   R3  R  R   R  R   R   R{   R3   R`   R   t   UptrackDepSolvert   getPlanst   setEffectiveR   Rp   R  R   R#   R`  R   R_  t   textwrapt   fillR/  t
   unpackPlan(   R  R  t   actionst	   installedt   new_actionst   actR   R3   t   updateR  t   installed_idst   loaded_modulest
   locked_idst   solvert   responset   kt   plant   upgradeR  R   R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR8    sJ    	+&8.c   	      C   s   y" t  |  | |  \ } } } } Wn t j k
 r> } | j SXt |  d k rm t j s t j d  q n t	 |  s t j
 t j d  St | |  } | j r | S| j d | | |  | S(   s   :: Repo -> Local -> [Action] -> Uptrack.Result

    Construct a plan to perform the requested actions, and then carry
    out said plan. In addition, write new upgrade, init-time, and
    remove plans appropriate for the new state.
    i    s   Nothing to be done.s	   Aborting.N(   R8  R#   R`  R\   RZ   R   Rm  RU   Rn  R:  Rx   t   ERROR_USER_NO_CONFIRMt	   doActionsR   R;  R   (	   R  R  RN  RY  t
   new_updateR=  R>  R@  R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR4  :  s    "		c         C   s-  d } d } t  j j |  r t j d | | f  y t j |  Wq t k
 r } t | t	  r| | j
 t
 j k r| q t j d |  t j t j    q Xn  t  j j |  r)y t  j |  Wq)| k
 r%t | t	  r | j
 t
 j k r n  t j d |  t j t j    q)Xn  d  S(   Ns   /var/run/ksplices   /var/run/uptracks$   Cleaning up stale state in %s and %ss#   An error occurred while removing %s(   RA   RB   R}   RU   RW   R   R   t	   Exceptiont
   isinstanceR   t   errnot   ENOENTRV   R	   Rz   R   R   (   R  t   dirR   R@  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   doInitCleanY  s&    !!c         C   s  | j    } t |  d k rT d t j d d d d t j  } t j d |  St |  t j	 s~ t
 j d  t j   Sg  } y7 t
 j d	  | j   } t
 j d
  t
 j |  WnG t t j f k
 rt
 j d  t
 j t j    t j d d  SXt | |  S(   s?   
    Execute the init-time plan previously written to disk
    i    sN   
Error: Uptrack init script started, but some updates are already installed!

sJ   This is most likely because you manually ran '/etc/init.d/uptrack start'. sL   You never need to run the Uptrack init script manually: There is no Uptrack sI   daemon to start.  This init script only exists to reinstall your updates sF   during the boot process.  Please contact %s if you have any questions.i   s#   init-time installation is disabled.s   Reading init-time plan...s3   Installing updates according to the init-time plan:s+   Error reading init-time plan; doing nothings   Error reading init-time plan(   R3  RZ   RK  RL  R#   R3  Rx   Rc  R   R  RU   RW   t   readInitPlanRy   RX  RY  R	   Rz   R\  (   R  R  t   instR0  RY  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   doInito  s,    
	
c         C   sO  t  j   } g  } y t j d  | j   } WnP t t j f k
 r t j d  t j t j	    t  j
 | _ d | _ | SXt |  d k r t j s t j d  q n# t |  s t j d  t  j   St | |  } | j r | St j s5t  j t  j d i d t 6d	 t 6t |  d k f  } n  | j d
 g  g  g   | S(   s<   
    Execute the remove_plan previously written to disk
    s   Reading remove plan...s,   Error reading remove-all plan; doing nothings   Error reading remove-all plani    s   Nothing to be done.s	   Aborting.sl   New updates %s available. Please re-run Uptrack with a network connection available
to view and install themt   ares   may beN(   R#   Rx   RU   RW   t   readRemovePlanRy   RX  RY  R	   Rz   R   R   R   RZ   R   Rm  Rn  R:  R\  R  R2  R   R   R;  R   (   R  R  R   RY  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   doOfflineRemoveAll  s4    		
	 	.c         C   sS   t  j sI t j d  x0 |  D]% } t j d | d | d f  q Wn  t d  S(   Ns"   The following steps will be taken:s   %s %sRG  R:   s   Go ahead(   R   Rm  RU   Rn  R2  (   RN  RQ  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR:    s
    	&c         C   s  t  j   } | j   } t |   } t j j t  } xt |  D]} g  d D] } |  | | ^ qP \ } }	 |  | j	 d  }
 i d t
 6d t 6} t j d | | |	 f  t j j | j   | | |	 j |	 j  | t
 k r|	 | k rt j d |	 j  qC q\|	 j   } nA | t k r\|	 | k rMt j d |	 j  qC q\|	 j   } n  | j rt j d	 |	 j  | j j |  | j | _ t j r| j | _ n  Pns | j j |  | t
 k r| j |	  n | t k r| j |	  n  | p| j  } |
 d  k	 r$| j" |
  n  t j# rC t j d
 t j#  t$ j% t j#  qC qC W| ry t j& t  Wn n Xt j j d | | d d  t j j' d  st  j( d d  n  t) j* d d d g d t) j+ d t) j+ } | j,   \ } } | j- rt j d | j-  | r6t j d  t j |  n  | rYt j d  t j |  n  y t  j( t d  Wn n X| j sd | _ d | _. | Sqn  | S(   NRG  R:   RF  t
   Installingt   Removings   %s %ss'   ...%s is already installed, so skippings'   ...%s is not installed, so not removings   Error processing %ss1   Sleeping %s seconds between updates, as requestedt   DEPMODR   s   /var/run/uptracks   uptrack
s   /bin/shs   -cs   /sbin/ksplice-depmod -aRJ   RK   s   Error in ksplice-depmod (%d)s   stdout:s   stderr:R   i   s   Error running ksplice-depmod.(   s   Commands   Update(/   R#   Rx   R3  RZ   RA   RB   R   t   DEPMOD_NEEDED_FILER   R;   R   R   RU   Rn  R   t   notifyt   WorkingOnUpdatet   upperR3   R.   R  R   R  R   R*   t   failedR{   t   debug_to_serverRW   t	   succeededt   addR   R   R   RJ  R  R   R   R   Rv   R   RP   RQ   RR   RS   RT   R   (   RN  R  R   Re  R  R   R  RX  R   R  t   new_effectivet   commandwordsR   R[   RJ   RK   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR\    s    '(							
c         C   s   y | j    } Wn+ t k
 r= t j d  t j d  n Xt j d  | r xB | D]* } | d d k rX t j | d  qX qX Wn t j d   d  S(   Nsv   Unable to read the list of available updates.
Please run 'uptrack-upgrade -n' to update the list of available updates.i   s   Available updates:RG  R   R:   (   t   readUpgradePlanRy   RU   RV   R   t   exitRn  R   (   R  R  RY  RQ  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   doShowUpgradePlan  s    c   
      C   s  | j    } t j j r; t j t |   t j d  n  t	   } xM | D]E } |  j
 |  } | d k r t j d |  qK n  | j |  qK Wt |  d k rQt j s t j r t |  |  n  t j s t j rAt j d  t |  st j d  qAt |  } | j t j  x | D] } t j |  q'Wn  t d t  n t |  } | j t j  x | D] } | | k rt j d | j  n t j d | j  | j   }	 |	 d k rd	 | j }	 n |	 j   d
 }	 t j |	  qtWd S(   s   
    show has two modes of operation:
    
    When run without arguments, it lists the current status (i.e. what
    is installed). When arguments are passed to it, it shows you the
    detailed information for those updates.
    i    s%   Don't know about update %s; skipping.s   Installed updates:R   RD  s>   Update %s is installed on your system.  Detailed description:
sB   Update %s is NOT installed on your system.  Detailed description:
R   s5   Unable to retrieve detailed description of update %s.s   
N(   R3  R   R  R  RU   Rn  RZ   R   Rx  R   R  R   R  Rt  R  R  Ry  R   R  R#   R  R9  R   R3   R   RY   (
   R  R  t   wish_to_showRe  t   can_showR3   R  t   inst_sortedt   can_show_sortedR[   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   doShow+  sF    	t   DbusNotificationsc           B   se   e  Z d    Z d   Z e j j d d d d  e  Z d   Z e j j d d d d  e  Z RS(   c         C   s#   t  j j j |  t  j   |  d  S(   N(   t   dbust   servicet   ObjectRf   t	   SystemBus(   Re   t   object_path(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyRf   e  s    c         C   s   t  j d |  d  S(   Ns   dbus: Action: %s(   RU   RW   (   Re   R  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   ClientStartStoph  s    t   dbus_interfaces   com.ksplice.uptrack.Clientt	   signatureRd  c         C   s$   t  j d | | | | | f  d  S(   Ns'   dbus: Working on update: %s %i %i %s %s(   RU   RW   (   Re   R  t   numt   totalR3   t   desc(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyRo  m  s    	t   siiss(   R  R  Rf   R  R  R  R   Ro  (    (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR  d  s   			t   NonDbusNotificationsc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   d  S(   N(    (   Re   R  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyRf   t  s    c         C   s   d  S(   N(    (   Re   R  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR  u  s    c         C   s   d  S(   N(    (   Re   R  R  R  R3   R  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyRo  w  s    (   R  R  Rf   R  Ro  (    (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR  s  s   		c         C   s   |  r t  |   n  d  S(   N(   t   quit(   R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   isOkz  s     c         C   s  |  r? t  r t  |  _  n  t r* t |  _ n  t r? t |  _ q? n  |  r} |  j t j k r} t j d  t j	 |  d
 d
 d
  nt j r|  r|  j rt j r|  j t j t j t j t j t j t j t j f k ryE t j d  t t t g   \ } } } } t j	 |  | | |  WqCt k
 r|  j t j k rKt j } n	 t j } | d  t j t j    | d  |  r|  j d k rt j	 |  d
 d
 d
  qt j   } t j | _ d t | _ t j	 | d
 d
 d
  qCXnX |  r |  j r t j d  t j	 |  d
 d
 d
  n# t j d  t j	 |  d
 d
 d
  |  r|  j r|  j d k r|  j t j k rt j  r|  j t j t j t j t j f k rt j |  j  qt j |  j  qt j! |  j  n  t j" j# d	  d } |  r|  j } n  t$ j% |  d
 S(   s  :: Uptrack.Result -> IO ()

    Exit the program, performing appropriate reporting and cleanup
    before we do so. In particular, we must write the current status
    and result to disk (for the UI) and back to the server.

    In addition, we need to make sure we have written out an upgrade
    plan (for the GUI to display), an init-time plan (for next boot),
    and a remove plan (for if we try to remove all updates without
    network).

    If we are exiting successfully, the previous code paths have
    written out new plans if needed. If we're exiting with failure,
    however, we don't know what state we're in, so compute new plans
    to be safe.
    s4   User did not confirm actions. Not writing new plans.s/   Determining new upgrade/init-time/remove plans.s+   Error making upgrade/init-time/remove plansR   i    sK   Internal error while writing Uptrack status files.
See %s for more details.s;   Failed, but running without network. Not writing new plans.s,   Exiting with success. Not writing new plans.t   STOPN(&   R  R  R  R   R#   R[  RU   RW   R  R;  R   R   R  R  Rp   R  R2  R\  t   ERROR_MACHINE_NOT_ACTIVATEDt   ERROR_EXPIREDt   ERROR_SYS_NOT_MOUNTEDt   ERROR_MISSING_KEYR8  R^  R_  RV   R	   Rz   Rx   R   R  R   Rm  Rn  Rn  R  R   Rx  (   R\   R@   RZ  R  R   t   reportt   internal_errorR   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR  }  sn       "	


! c      
   C   s  d  } |  j } | r| d k r t |  j  d k r |  j d d d k r d |  j j   d d d d	 d
 t j } d t j	 |  } q| d k rjd |  j j   d d d d d t j d d } d t j	 |  d } x|  j D]o } d } x/ t
 |  D]! \ } } | j   r| } qqWd j | |   } | | } | d | | f 7} q Wq| d k rd |  j j   d d d } d t j	 |  } q| d k rd d d d } d t j	 |  } | d 7} | d j g  |  j D] }	 d  |	 f ^ q 7} q| dH k rt j   rd t j	 d |  j j   d#  } | d$ 7} | t j	 d% t j d&  7} qt |  j  d k rd t j	 d' d(  d } t j j d)  r| d t j	 d*  d 7} n | d t j	 d+ d,  d 7} x |  j D] }
 | d- |
 7} q	W| d t j	 d. d/  d 7} x |  j D] }
 | dI |
 7} qJW| d t j	 d1 d2 d3 t j  7} qd t j	 d4 d5  } | d6 t j f 7} q| d7 k rc|  j t k rc|  j rcd t j	 d8 d9 d: d d  } | d 7} | d j g  |  j D] }	 d  |	 f ^ q 7} | d t j	 d; d2 d3 t j  7} q| d< k rd t j	 d= d> d? d@ dA dB dC t j  } qn  | sd |  j j   dD dE } d t j	 |  } | d 7} | dF t j f 7} | dG t f 7} n  | S(J   NR   i   i    R   s   Ksplice was unable to s:    the update because the rfcomm module (used for bluetooth)s@    is erroneously triggering a conservative Ksplice safety check. sD    If you are not using bluetooth on this system, you can install thissL    update by first unloading the rfcomm module using "rmmod rfcomm" and tryings5    again.  Please contact %s if you have any questions.s   
s7    the update because one or more programs are constantlys8    using the kernel functions patched by this update.  Yous;    should be able to install this update by trying again.  Ifs:    trying again does not work, please report this problem tos    <%s>. s:    Even if trying again does not work, closing the followings9    programs should make it possible to install this update:s   

R   s     - %s (pid %s)
t   out_of_memorys   Ksplice failed to sD    this update because your kernel is out of memory.  Ksplice's memorysG    consumption is minimal, so this is likely caused by some other problems    on your systemR   s7   Ksplice was unable to remove the update because moduless>    that Uptrack patched off-line are currently loaded.  In orders9    to remove this update, you will need to first unload thes    following kernel modules:s    - %sR   R   s    the update because it could not match the code to be patched in your running kernel.  This could be caused by running Ksplice inside VirtualBox without the VT-x/AMD-V setting enabled.sK   
For more information, see http://www.ksplice.com/uptrack/help/virtualbox

sp   If you are not running VirtualBox, or enabling VT-x/AMD-V does not solve the problem, please report this bug to R>   sJ   Ksplice was unable to install this update because the code in your runnings,    kernel does not match the expected version.s   /etc/debian_versions   You may have upgraded your on-disk kernel package and subsequently loaded one of the updated modules.  You may also be running a backported or custom-compiled kernel module.  The non-matching modules are:s=   You may be running a backported or custom-compiled version ofsU    one or more of the following kernel modules that were provided by your Linux vendor:s     - %s
sH   If you are not intentionally using a different version of these modules,sU    you should be able to install this update by running the following commands as root:s   rmmod s   and then trying again. s8    If you are unable to resolve this issue, please contacts    <%s> for assistance. s>   Ksplice was unable to install this update because your runningsC    kernel has been modified from the version provided by your vendor.s1   
Please contact %s for help resolving this issue.R   s   Ksplice was unable to removes>    the update because it is in use by one or more kernel moduless>    that have been loaded since the update was applied.  In ordersA   You can unload a module by running "rmmod <module name>" as root.R   s&   Ksplice was unable to apply the updates;    because the kernel does not trust the key that was used tos;    sign the update. This is most likely caused by your systems    using UEFI secure boot.s<    Ksplice does not yet support secure boot on platforms others    than Oracle Linux.s7    Please contact <%s> if you have any further questions.s    this updates%    due to an unexpected internal error.s:   Please report this bug to the Uptrack developers at <%s>.
s   Uptrack log file: %s(   s   no_matchs   failed_to_finds   
rmmod (   R   R   RZ   R   R   R/  R#   R3  RK  RL  R  t   isdigitR   R   t   inVirtualBoxR   RA   RB   R   R   R   R  (   RQ  R0  t   whyR   t   pid_iR  t   wordR[   t   pidR   Rc   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   prettyResult  s    	! /

3			$	
0	
c          C   s[   t  r5 t j r5 t j j j d t  t d  }  n t	 j
 d  t d  }  |  t _ d  S(   NR   s   /com/ksplice/uptrack/UptrackUIs3   D-Bus not present, will not notify uptrack-manager.(   t	   have_dbusR   R  R  t   mainloopt   glibR   R   R  RU   RW   R  Rn  (   Rn  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   initializeDBusP  s    c          C   s  t  j d  t j d }  y5 t t j t j d   } t t j |    } Wn# t t f k
 rt d } d } n X| d 7} | | k  r t  j d | |  t j	 |  t
 |  d  t j d  n  t  j d | |  | | 8} t j	 |  t
 |  d  t j t j d d	   d  S(
   Ns   Invoked by the cron job.s   /backoff-counters   /backoffi   i    s(   Counter is %s/%s, waiting for next time.s   
s   Counter is %s/%s, proceeding.i;   (   RU   RW   R   R4  R  R#   R$   Ry   t
   ValueErrorR   R   R   Rx  R   R   t   randomt   randint(   t   counterfilet   backofft   backoff_counter(    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   desyncY  s$    

	

c         C   sx   d  } |  d k r t } nY |  d k r0 t } nD |  d k rE t } n/ |  d k rZ t } n t j d  t j d  | S(   Ns   uptrack-upgrades   uptrack-installs   uptrack-removes   uptrack-shows$   I don't know what you want me to do.i(	   R   R  R   R   R  RU   RV   R   Rx  (   R.   R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyR  q  s    				c      
   C   s  |  t  k rp t j rp t j rp t j d  t j d  t j d  t j d  t j d  t j d  n  |  t  k r t j r t t j	  d k r t j d  t j d  n  t j
 r |  t  k r t j d	  t j d  n  t j rt j	 rt j d
  t j d  n  |  t k rt j rWt j j rWt j d  t j d  n  t j rt j j rt j d  t j d  qn  d S(   sD   Verify that command is allowed in combination with current options. sA   Sorry, removing individual updates requires a network connection.s.   (Run this command again without --no-network?)R   s9   If you wish to remove all updates, run this command agains8   with --all (this does not require a network connection).i   i    s>   Please specify update IDs to remove or use the --all argument.s1   --uninstall may only be used with uptrack-remove.s5   Specifying an update as well as --all makes no sense!s:   Using --all and --count at the same time is not supported.s@   Using --available and --count at the same time is not supported.N(   R   R   R  R  RU   RV   R   Rx  RZ   R   R  R  R  R  R  (   R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   checkCommand  s.    +c         C   s7   | j  r t S|  t k r& | j r& t S| j d k Sd S(   s`   Indicates if the user is both missing an access key and needs one
    for the current operation.R   t   INSERT_ACCESS_KEYN(   R   R  (   R  R   R   R  R[  (   R   R   (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   needs_access_key  s
    	c          C   s   d }  y t  j |  d t j g d t  j d t  j } | j   \ } } | j r t j d |   | r t j d  t j |  n  | r t j d  t j |  q n  Wn7 t	 k
 r } t j d |   t j t
 |   n Xd  S(	   Ns   /sbin/restorecons   -RRJ   RK   s   Error executing %ss   stdout:s   stderr:s   Failed to execute %s(   RP   RQ   R   R4  RR   RS   RT   RU   RW   R   R   (   t
   restoreconR[   RJ   RK   R@  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   selinux_label  s     	c         C   s
  d } d t  j k s# t  j d r3 | t  j d <n t  j d c d | 7<y* t |  |  a t j t  t j   WnI t j k
 r } t	 j
 d  t	 j
 | j j  t j | j j  n Xt j j r d t GHt j d  n  t j j r$t j st j rt j d  n  t j d  n  t  j d  t j t  t   t	 j d	  t	 j d
 |  d j |  f  t t  j j |    } t j d k rt } n  t  |  t j! t j"  t j! t  j j t j" d   t j# rt$   n  t j% rt&   n  t'   a( t( t) k rPt	 j d t j*  t	 j
 d t j+ f  t j d  n  t, | t  rt  j j- t.  rt) } t j/ rt0 } n t j r:t  j1 t j2 j3    r:t j4 t5  } t6 j7 d g d t6 j8 } | j9 d |  xQ t0 r6t: d  j;   j<   } | d k rt0 } Pq| d k rt) } PqqWn  | rt	 j= d  t> j>   }	 y[ t j? t j@   tA d d |	 }
 |
 d k rt	 j
 d |
 t j+ f  t j d  n  Wnq tB j
 k
 r'} t	 j d | d | d f  t	 j tC jD    t	 j
 t jE t |  j  t j d  n Xt6 jF d d d d |	 jG   d  g  } t	 jH d!  tI   t j/ r}t j d  n  t  jJ t jK d t jK  qt	 jH d"  t j t jL  n  y t jM   WnI t j k
 r} t	 j
 d  t	 j
 | j j  t j | j j  n Xt jN jO d#  tP t  aQ t jR t tQ t  a" t, | t  rt jS   } t jL | _ d$ | _ | j d% t jT 7_ tU |  n  t) } | tV k rt jW rt jX rtY tQ jZ    tY tQ j[    t0 } ntQ j\   } | rI| j t j] k rI| tV k rIt j j^ rIt jW rIt	 jH d&  t j d  n  | r| j r| tV k rt	 j
 d'  t j d  n  | r| j r| t k rt_ t"  | j t j] k rd | _ t0 | _` d( | _ tU |  qn  tY |  t  j ja d)  rp| tV k st j j^ rpt  j j- d*  r>d+ t j+ f } n d, t j+ f } t jS t jb |  } tU |  n  | rtY tQ jc    n  t jd r| t k rte d- d.  t0 t _ n  t j r| tV k rt jS   } t jf | _ d/ | _ tU |  n  tQ jg r_| tV k r_| th k o!t ji r_| th k r:d0 } n d1 } tU t jS t jj |   q_n  | t k r}tk tQ t"  } n | tl k rtm tQ t"  } n | tn k rto tQ t" t jp  } n | th k r 	t jX st ji r	t jW stQ jg r	tq tQ t"  } n tr tQ t" t jp  } ts   n$ | tV k rD	tt tQ t" t jp  } n  | r~
| t tl tn th g k r~
| j t ju k r	tU |  n  tv | jw  r	t	 j d	  t	 j d2  x1 | jw D]# } t	 j d3 | jx | jy f  q	Wn  tv | jz  r~
t	 jH d	  t	 j
 d4  xU | jz D]J } t	 j
 d3 | jx | jy f  t	 j
 t{ |   t	 j d5 | j  q
Wt	 j
 d	  t jf | _ q~
n  tU |  d  S(6   Ns   /usr/sbin:/usr/bin:/sbin:/bint   PATHR	  s!   Error loading configuration file:s   %si    i   i   R   s   Client invoked as: %s %sR   R  Rp   s1   Unable to acquire the Uptrack repository lock: %ss   It appears that another Uptrack process is currently running on this
system. Please wait a minute and try again.  If you are unable to
resolve this issue, please contact %s.t   moreR  si   In order to use the Ksplice Uptrack service, you must 
agree to the Ksplice Uptrack terms of service:

%ss?   Do you agree to the Ksplice Uptrack terms of service? [yes|no] t   yest   nos6   Requesting access key... (this may take a few moments)s	   /dev/nullR}  i   su   The Ksplice Uptrack server gave a response code of %d
while requesting access key.  Please contact
%s for assistance.s/   cURL error %d (%s) while requesting access key.t   seds   -is   -es%   s/^\s*accesskey\s*=.*/accesskey = %s/s   /etc/uptrack/uptrack.confs!   Access key successfully requestedsQ   You must accept the Ksplice Uptrack terms of service
in order to use the service.t   STARTs3   You must specify an access key to use the service.
s   Please add your key to %sR   se   Unable to read the package list.
Please run 'uptrack-upgrade -n' to download the latest package list.sJ   Ksplice Uptrack: booting into a new kernel, so not installing any updates.s   /sys/modules   /proc/vzs  Error: You are running Ksplice Uptrack inside a Virtuozzo/OpenVZ container,
  but it needs to run on the hardware node instead.

  If you have purchased a virtual private server (VPS) from a hosting company,
  please contact them and ask them to purchase Ksplice Uptrack for their VPS
  systems. If you are the VPS provider, please install Ksplice Uptrack on the
  hardware node rather than in a container.
  If you need help resolving this issue, please contact %s.sQ  Error: The directory /sys/module was not found.
  You must have the /sys filesystem mounted in order to use Ksplice Uptrack.
  If you are running inside a chroot, you must mount /sys inside the chroot.
  This could also be caused by an old or non-standard system configuration.
  If you need help resolving this issue, please contact %s.s   /etc/uptrack/disableR   sP   Uptrack disabled by system administrator, remove /etc/uptrack/disable to enable.s(   Removing individual updates is disabled.s   Installing updates is disabled.s&   The following actions were successful:s   %s %ss   The following actions failed:s	   Message:
(|   RA   t   environR  R   t   loggerR)  R  R#   R`  RU   RV   R\   R   R   Rx  R   R  R  R!  R  R  R  R  t   initCurlR  RW   R   R  RB   RC   R  t   INITR  R   R  t   rh_derivativeR  Rm  R  R  R  R   R  R3  R  R   t   AUTOGEN_FLAG_FILER  R   t   isattyR  t   filenoR$   t   TOS_FILERP   RQ   RR   RS   R,  RY   R/  R  RJ  R5  R6  t   AUTOGEN_URLR7  R	   Rz   R8  t
   check_callRV  Rn  R  t   execvt   argvR  t   initWithLockRn  R  R  R  t   LocalStatusRx   R]  R  R  R  R  R  RD  R|  R  R2  R  Rc  t	   newkernelR}   R  R  R  R   R   R$  R   R  R  Rf  R  R?  R   RA  R   Ri  R6  R9  R~  R[  RZ   Rs  R   RR  Rq  R  (   R  R   t   default_pathR@  R   t   acceptedt   tosR[   t   choiceRd  R   R   t   will_downloadR   R0  RQ  (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   main  s^   	 	
	
	
		
!		"				(		 	$
			
		"		
$t   __main__s   Unable to set up the logger.s'   The Uptrack client must be run as root.s   Interrupted!R   R   s-   Unexpected error starting the Uptrack client.s!   Please submit a copy of %s to %s.s   Unhandled exceptions   Unexpected error.(   R   t   __excepthook__t
   excepthookt   version_infoRB   R  R  R  Rm   RA   R  R   R`  R   R9  R   RU   t   logging.handlersRX  R  RK  R   t	   cStringIORJ  t   optparseR    R   R   R%   t   ImportErrort   hashlib_compatRP   t   subprocess_compatR   t	   NameErrort   setsR   R	   Rz   Rp  R   R   R7  t   E_COULDNT_RESOLVE_PROXYt   E_COULDNT_RESOLVE_HOSTt   E_COULDNT_CONNECTt   E_OPERATION_TIMEOUTEDt   E_URL_MALFORMATt   E_SSL_CACERTR  R  t   dbus.servicet   dbus.mainloop.glibR  R   R   R  R^  R#   RH  R!  R  R  R  R  R  R'  R0  R1  R  R   R   t   UPTRACK_CACHE_DIRRm  R  R   R   R   R~  R  R  R  R   R   R  R  R  R  R  R   R  R  R   R  R  R  R   R!   R0   R=   RH   R`   Ra   t   objectR:   R  R  R  R  R  R  R  t   UptrackConfigR  R  R	  R  R  R2  R6  R?  RA  R9  R8  R4  Rc  Rf  Ri  R:  R\  Ry  R~  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  RK   t   getuidRx  R  R-  RV   RW   t
   SystemExitRx   t   ERROR_INTERNAL_ERRORR   R3  R   R;  (    (    (    s+   /usr/lib/pymodules/python2.7/uptrack/cli.pyt   <module>   sf        					

	
			
		 		 			
).					J			!	0		S		8		Q							
		 