ó
½-'Nc           @   sR   d  d l  Z  d  d l Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t	   read_file(   t   MonitorPlugint   RebootRequiredc           B   sY   e  Z d  Z d Z d Z e Z d d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z RS(
   s±   
    Report whether the system requires a reboot.

    @param reboot_required_filename: The path to the flag file that indicates
        if the system needs to be rebooted.
    s   reboot-requiredi„  s   /var/run/reboot-requiredc         C   s   | |  _  | d |  _ d  S(   Ns   .pkgs(   t   _flag_filenamet   _packages_filename(   t   selft   reboot_required_filename(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/rebootrequired.pyt   __init__   s    	c         C   s   t  j j |  j ƒ S(   s@   Return a boolean indicating whether the computer needs a reboot.(   t   ost   patht   existsR   (   R   (    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/rebootrequired.pyt	   _get_flag   s    c         C   sN   t  j j |  j ƒ s g  St |  j ƒ j ƒ  } t d „  | Dƒ ƒ } t | ƒ S(   s;   Return the list of packages that required a reboot, if any.c         s   s*   |  ]  } | r | j  ƒ  j d  ƒ Vq d S(   s   utf-8N(   t   stript   decode(   t   .0t   line(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/rebootrequired.pys	   <genexpr>"   s    (   R   R	   R
   R   R    t
   splitlinest   sett   sorted(   R   t   linest   packages(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/rebootrequired.pyt   _get_packages   s
    c         C   s†   i  } |  j  ƒ  } |  j ƒ  } xa d | f d | f g D]G \ } } | |  j j | ƒ k ra q7 n  |  j j | | ƒ | | | <q7 W| S(   s:   Return the body of the reboot-required message to be sent.t   flagR   (   R   R   t   _persistt   getR   (   R   t   messageR   R   t   keyt   value(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/rebootrequired.pyt   _create_message%   s    %c         C   sI   |  j  ƒ  } | rE d | d <t j d ƒ |  j j j | d t ƒn  d S(   s˜   Send a reboot-required message if needed.

        A message will be sent only if the reboot-required status of the
        system has changed.
        s   reboot-required-infot   types5   Queueing message with updated reboot-required status.t   urgentN(   R   t   loggingt   infot   registryt   brokert   send_messaget   True(   R   R   (    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/rebootrequired.pyR#   1   s
    
c         C   s   |  j  j j d |  j ƒ S(   s9   Send reboot-required messages if the server accepts them.s   reboot-required-info(   R!   R"   t   call_if_acceptedR#   (   R   (    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/rebootrequired.pyt   run>   s    (   t   __name__t
   __module__t   __doc__t   persist_namet   run_intervalR$   t   run_immediatelyR   R   R   R   R#   R&   (    (    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/rebootrequired.pyR      s   					(   R   R   t   landscape.lib.fsR    t   landscape.monitor.pluginR   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/rebootrequired.pyt   <module>   s   