ó
ÍÿŠTc           @   sf   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d Z d Z	 d e f d „  ƒ  YZ
 d	 S(
   iÿÿÿÿ(   t   maybeDeferred(   t   log_failure(   t   format_object(   t   BrokerClientPlugini   i   t   ManagerPluginc           B   s    e  Z e d  „  ƒ Z d „  Z RS(   c         C   s   |  j  S(   s&   An alias for the C{client} attribute}.(   t   client(   t   self(    (    s<   /usr/lib/python2.7/dist-packages/landscape/manager/plugin.pyt   manager   s    c   	         sm   t  ˆ ˆ ˆ Ž } d „  } ‡ ‡ ‡ f d †  } ‡  ‡ f d †  } | j | ƒ | j | ƒ | j | ƒ | S(   s"  Send an operation-result message after calling C{callable}.

        If the function returns normally, an operation-result
        indicating success will be sent.  If the function raises an
        exception, an operation-result indicating failure will be
        sent.

        The function can also return a C{Deferred}, and the behavior above
        still applies.

        @param message: The original message.
        @param callable: The function to call to handle the message.
            C{args} and C{kwargs} are passed to it.
        c         S   s
   t  |  f S(   N(   t	   SUCCEEDED(   t   text(    (    s<   /usr/lib/python2.7/dist-packages/landscape/manager/plugin.pyt   success$   s    c            sK   d |  j  j |  j f } d t ˆ ƒ ˆ  ˆ f } t |  d | ƒt | f S(   Ns   %s: %ss9   Error occured running message handler %s with args %r %r.t   msg(   t   typet   __name__t   valueR   R   t   FAILED(   t   failureR	   R   (   t   argst   callablet   kwargs(    s<   /usr/lib/python2.7/dist-packages/landscape/manager/plugin.pyR   '   s
    c            s]   |  \ } } i d d 6| d 6ˆ d d 6} | r> | | d <n  ˆ  j  j j | ˆ  j d t ƒS(   Ns   operation-resultR   t   statuss   operation-ids   result-textt   urgent(   R   t   brokert   send_messaget   _session_idt   True(   t   .0R   R	   t   result(   R   t   message(    s<   /usr/lib/python2.7/dist-packages/landscape/manager/plugin.pyt   send.   s    	
(   R    t   addCallbackt
   addErrback(	   R   R   R   R   R   t   deferredR
   R   R   (    (   R   R   R   R   R   s<   /usr/lib/python2.7/dist-packages/landscape/manager/plugin.pyt   call_with_operation_result   s    		(   R   t
   __module__t   propertyR   R!   (    (    (    s<   /usr/lib/python2.7/dist-packages/landscape/manager/plugin.pyR      s   N(   t   twisted.internet.deferR    t   landscape.lib.logR   t   landscape.logR   t   landscape.broker.clientR   R   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/landscape/manager/plugin.pyt   <module>   s   