ó
ÍÿŠTc           @   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   LandscapeReactor(   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            sC   ‡  ‡ f d †  } i d d 6|  d 6‰  ˆ j  ƒ  } | j | ƒ | 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.
    c            s   ˆ j  ˆ  |  t ƒ } | S(   N(   t   send_messaget   True(   t
   session_idt   response(   t   messaget   broker(    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyt   got_session_id#   s    s   text-messaget   typeR   (   t   get_session_idt   addCallback(   t   textR   R   t   result(    (   R   R   s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyR	      s
    	c         C   s	   d GHd  S(   Nu   Message sent.(    (   R   (    (    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_message1   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	   R   R   (   t   accepted_typesR   R   R   t   d(    (    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyt   got_accepted_types>   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_connectionR   s    c         S   s   t  |  ƒ d  S(   N(   R    (   t   failure(    (    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyt	   got_errorV   s    c            s
   ˆ  j  ƒ  S(   N(   t
   disconnect(   R   (   t	   connector(    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyt   <lambda>]   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)   b   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.pyR3   H   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   argvR3   (    (    (    s9   /usr/lib/python2.7/dist-packages/landscape/textmessage.pyt   <module>   s   				
