ó
½-'Nc           @   sµ   d  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	 e
 f d
     YZ d   Z d   Z d   Z d   Z e j d  Z d S(   sĀ   
Support code for the C{landscape-message} utility, which sends a text
message to the Landscape web UI via the landscape-client's dbus
messaging service (see L{landscape.plugins.dbus_message}).
i’’’’N(   t   log_failure(   t   TwistedReactor(   t   RemoteBrokerConnector(   t   Configurationt   AcceptedTypeErrorc           B   s   e  Z d  Z RS(   sZ   
    Raised when a message is sent without 'text-message' being an
    accepted type.
    (   t   __name__t
   __module__t   __doc__(    (    (    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyR      s   t   EmptyMessageErrorc           B   s   e  Z d  Z RS(   s(   Raised when an empty message is provied.(   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyR      s   c         C   s*   i d d 6|  d 6} | j  | t  } | S(   s  Add a message to the queue via a remote broker.

    The message is of type C{text-message}.

    @param broker: A connected L{RemoteBroker} object to use to send
        the message.
    @return: A L{Deferred} which will fire with the result of the send.
    s   text-messaget   typet   message(   t   send_messaget   True(   t   textt   brokerR
   t   response(    (    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyR      s    	c         C   s	   d GHd  S(   Nu   Message sent.(    (   t   result(    (    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyt
   got_result(   s    c         C   s   t  j j p d } t |   d k  rD d GHt  j j   j |  } n/ d j g  |  d D] } | j |  ^ qU  } | s t d   n  | S(   Ns   UTF-8i   sN   Please enter your message, and send EOF (Control + D after newline) when done.u    i   s   Text messages may not be empty.(   t   syst   stdint   encodingt   lent   readt   decodet   joinR   (   t   argsR   R
   t   x(    (    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyt   get_message,   s    /c         C   sG   d |  k r t  d   n  t |  } t | |  } | j t  | S(   Ns   text-messagesR   Text messages may not be created.  Is Landscape Client registered with the server?(   R   R   R   t   addCallbackR   (   t   accepted_typesR   R   R
   t   d(    (    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyt   got_accepted_types9   s    c            s¦   t      t   } | j    f d   } d   } t   |    j   } | j |  | j |  | j  f d    | j   f d      j   | S(   s   Send a message to Landscape.

    This function runs a Twisted reactor, prints various status
    messages, and exits the process.
    c            s   |  j    } | j t |     S(   N(   t   get_accepted_message_typesR   R   (   R   R   (   R   (    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyt   got_connectionM   s    c         S   s   t  |   d  S(   N(   R    (   t   failure(    (    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyt	   got_errorQ   s    c            s
     j    S(   N(   t
   disconnect(   R   (   t	   connector(    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyt   <lambda>X   s    c            s     j  d   j j  S(   Ni    (   t
   call_latert   _reactort   stop(   t   ignored(   t   reactor(    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyR&   ]   s   (	   R   R   t   loadR   t   connectR   t
   addErrbackt   addBotht   run(   R   t   configR!   R#   R   (    (   R+   R   R%   s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyR0   C   s    			
(   R   R   t   landscape.lib.logR    t   landscape.reactorR   t   landscape.broker.ampR   t   landscape.deploymentR   t	   ExceptionR   R   R   R   R   R   t   argvR0   (    (    (    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyt   <module>   s   				
