ó
½-'Nc           @   sr   d  d l  Z  d  d l Z d  d l m Z d  d l m Z d  d l m Z d  d l m	 Z	 d e	 f d „  ƒ  YZ
 d S(   iÿÿÿÿN(   t   getProcessOutput(   t   PackageStore(   t   find_reporter_command(   t   MonitorPlugint   PackageMonitorc           B   sb   e  Z d  Z d
 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z RS(   i  c         C   sD   t  t |  ƒ j ƒ  | r+ t | ƒ |  _ n	 d  |  _ t ƒ  |  _ d  S(   N(   t   superR   t   __init__R   t   _package_storet   NoneR   t   _reporter_command(   t   selft   package_store_filename(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/packagemonitor.pyR      s
    	c         C   s¸   | j  |  _  t t |  ƒ j | ƒ |  j sX t j j | j  j d ƒ } t	 | ƒ |  _ n  | j
 d |  j ƒ | j j d |  j ƒ | j j d |  j ƒ |  j d |  j ƒ |  j ƒ  d  S(   Ns   package/databases   package-idst   resynchronizes   server-uuid-changedt   packages(   t   configR   R   t   registerR   t   ost   patht   joint	   data_pathR   t   register_messaget!   _enqueue_message_as_reporter_taskt   reactort   call_ont   _resynchronizet   _server_uuid_changedt   call_on_acceptedt   spawn_reportert   run(   R
   t   registryt   filename(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/packagemonitor.pyR      s    			

c         C   s!   |  j  j d | ƒ |  j ƒ  d  S(   Nt   reporter(   R   t   add_taskR   (   R
   t   message(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/packagemonitor.pyR   (   s    c         C   s&   |  j  j j ƒ  } | j |  j ƒ | S(   N(   R   t   brokert   get_accepted_message_typest   addCallbackt   _got_message_types(   R
   t   result(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/packagemonitor.pyR   ,   s    c         C   s   d | k r |  j  ƒ  n  d  S(   NR   (   R   (   R
   t   message_types(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/packagemonitor.pyR%   1   s    c      
   C   so   d g } |  j  j  r1 | j d |  j  j  g ƒ n  t |  j d | d t j d d d d  ƒ} | j |  j ƒ | S(   Ns   --quiets   -ct   argst   envt   errortooi   R   (	   R   t   extendR    R	   R   t   environR   R$   t   _got_reporter_output(   R
   R(   R&   (    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/packagemonitor.pyR   5   s    		c         C   s   | r t  j d | ƒ n  d  S(   Ns   Package reporter output:
%s(   t   loggingt   warning(   R
   t   output(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/packagemonitor.pyR-   C   s    c         C   s6   |  j  j d i d d 6ƒ } |  j  j d | f ƒ d S(   s:  
        Remove all tasks *except* the resynchronize task.  This is
        because if we clear all tasks, then add the resynchronize,
        it's possible that the reporter may be running a task at this
        time and when it finishes, it will unknowningly remove the
        resynchronize task because sqlite resets its serial primary
        keys when you delete an entire table.  This problem is avoided
        by adding the task first and removing them all *except* the
        resynchronize task and not causing sqlite to reset the serial
        key.
        R   R   t   typet   except_tasksN(   R   R    t   clear_tasks(   R
   t   task(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/packagemonitor.pyR   G   s    c         C   s    | d k	 r |  j j ƒ  n  d S(   sµ   Called when the broker sends a server-uuid-changed event.

        The package hash=>id map is server-specific, so when we change
        servers, we should reset this map.
        N(   R   R   t   clear_hash_ids(   R
   t   old_uuidt   new_uuid(    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/packagemonitor.pyR   W   s    	N(   t   __name__t
   __module__t   run_intervalR   R   R   R   R   R%   R   R-   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/packagemonitor.pyR      s   							(   R.   R   t   twisted.internet.utilsR    t   landscape.package.storeR   t   landscape.package.reporterR   t   landscape.monitor.pluginR   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/landscape/monitor/packagemonitor.pyt   <module>   s   