ó
½-'Nc           @   sï   d  Z  d d l Z d d l Z d d l m Z m Z d d l m Z d d l m	 Z	 d d l
 m Z m Z d d l m Z d d l m Z m Z d	 d
 d d d d d d g Z d e f d „  ƒ  YZ d d „ Z d d „ Z d d d „ Z d S(   s%   Deployment code for the sysinfo tool.iÿÿÿÿN(   t	   getLoggert	   Formatter(   t   RotatingFileHandler(   t
   namedClass(   t   Deferredt   maybeDeferred(   t   Configuration(   t   SysInfoPluginRegistryt   format_sysinfot   Loadt   Diskt   Memoryt   Temperaturet	   Processest   LoggedInUserst   LandscapeLinkt   Networkt   SysInfoConfigurationc           B   sc   e  Z d  Z d Z e j ƒ  d k r@ e e j j d ƒ f 7Z n  d Z d „  Z	 d „  Z
 d „  Z RS(	   s9   Specialized configuration for the Landscape sysinfo tool.s   /etc/landscape/client.confi    s   ~/.landscape/sysinfo.conft   sysinfoc         C   sa   t  t |  ƒ j ƒ  } | j d d d d d ƒ| j d d d d d ƒd d	 j t ƒ | _ | S(
   sg   
        Specialize L{Configuration.make_parser}, adding any
        sysinfo-specific options.
        s   --sysinfo-pluginst   metavart   PLUGIN_LISTt   helpsN   Comma-delimited list of sysinfo plugins to use. Default is to use all plugins.s   --exclude-sysinfo-pluginssh   Comma-delimited list of sysinfo plugins to NOT use. This always take precedence over plugins to include.s   Default plugins: %ss   , (   t   superR   t   make_parsert
   add_optiont   joint   ALL_PLUGINSt   epilog(   t   selft   parser(    (    s@   /usr/lib/python2.7/dist-packages/landscape/sysinfo/deployment.pyR      s    c         C   s&   g  | j  d ƒ D] } | j ƒ  ^ q S(   Nt   ,(   t   splitt   strip(   R   t   plugin_spect   x(    (    s@   /usr/lib/python2.7/dist-packages/landscape/sysinfo/deployment.pyt   get_plugin_names/   s    c         C   s©   |  j  d  k r t } n |  j |  j  ƒ } |  j d  k rB g  } n |  j |  j ƒ } g  | D] } | | k r[ | ^ q[ } g  | D]% } t d | j ƒ  | f ƒ ƒ  ^ q€ S(   Ns   landscape.sysinfo.%s.%s(   t   sysinfo_pluginst   NoneR   R#   t   exclude_sysinfo_pluginsR   t   lower(   R   t   includet   excludeR"   t   pluginst   plugin_name(    (    s@   /usr/lib/python2.7/dist-packages/landscape/sysinfo/deployment.pyt   get_plugins2   s    		%(   s   /etc/landscape/client.conf(   t   __name__t
   __module__t   __doc__t   default_config_filenamest   ost   getuidt   patht
   expandusert   config_sectionR   R#   R,   (    (    (    s@   /usr/lib/python2.7/dist-packages/landscape/sysinfo/deployment.pyR      s   		c         C   s@   |  d k r< t j ƒ  d k r' d }  q< t j j d ƒ }  n  |  S(   ss   
    Work out the correct path to store logs in depending on the effective
    user id of the current process.
    i    s   /var/log/landscapes   ~/.landscapeN(   R%   R1   R2   R3   R4   (   t   landscape_dir(    (    s@   /usr/lib/python2.7/dist-packages/landscape/sysinfo/deployment.pyt   get_landscape_log_directoryA   s
    	c         C   s”   t  |  ƒ }  t d ƒ } t | _ t j j |  ƒ sC t j |  ƒ n  t j j |  d ƒ } t	 | d d	 d d ƒ} | j
 | ƒ | j t d ƒ ƒ d  S(
   Ns   landscape-sysinfos   sysinfo.logt   maxBytesiô  i   t   backupCounti   s'   %(asctime)s %(levelname)-8s %(message)si Ð (   R7   R    t   Falset	   propagateR1   R3   t   isdirt   mkdirR   R   t
   addHandlert   setFormatterR   (   R6   t   loggert   log_filenamet   handler(    (    s@   /usr/lib/python2.7/dist-packages/landscape/sysinfo/deployment.pyt   setup_loggingN   s    		c            s	  y t  ƒ  Wn$ t k
 r1 } t j d | ƒ n Xˆ d k rJ t ƒ  ‰ n  t ƒ  } | j |  ƒ x! | j ƒ  D] } ˆ j	 | ƒ qm W‡ f d †  ‰ ‡ ‡ f d †  ‰ ˆ  d k	 rü t
 ƒ  ‰ ˆ  j ‡ ‡ f d †  ƒ ‡  f d †  } ˆ j | ƒ ˆ  j ƒ  n	 ˆ ƒ  ‰ ˆ S(   sQ   
    @param reactor: The reactor to (optionally) run the sysinfo plugins in.
    s   Unable to setup logging. %sc            s-   t  ˆ  j ƒ  ˆ  j ƒ  ˆ  j ƒ  d d ƒGHd  S(   Nt   indents     (   R   t   get_headerst	   get_notest   get_footnotes(   t   result(   R   (    s@   /usr/lib/python2.7/dist-packages/landscape/sysinfo/deployment.pyt   show_outputk   s    c              s   ˆ j  ƒ  j ˆ  ƒ S(   N(   t   runt   addCallback(    (   RI   R   (    s@   /usr/lib/python2.7/dist-packages/landscape/sysinfo/deployment.pyt   run_sysinfoo   s    c              s   t  ˆ ƒ j ˆ  ƒ S(   N(   R   t   chainDeferred(    (   t   doneRL   (    s@   /usr/lib/python2.7/dist-packages/landscape/sysinfo/deployment.pyt   <lambda>x   s    c            s   ˆ  j  d ˆ  j ƒ |  S(   Ni    (   t	   callLatert   stop(   RH   (   t   reactor(    s@   /usr/lib/python2.7/dist-packages/landscape/sysinfo/deployment.pyt   stop_reactorz   s    N(   RC   t   IOErrort   syst   exitR%   R   R   t   loadR,   t   addR   t   callWhenRunningt   addBothRJ   (   t   argsRR   R   t   et   configt   pluginRS   (    (   RR   RL   RN   RI   R   s@   /usr/lib/python2.7/dist-packages/landscape/sysinfo/deployment.pyRJ   [   s*    			(   R/   R1   RU   t   loggingR    R   t   logging.handlersR   t   twisted.python.reflectR   t   twisted.internet.deferR   R   t   landscape.deploymentR   t   landscape.sysinfo.sysinfoR   R   R   R   R%   R7   RC   RJ   (    (    (    s@   /usr/lib/python2.7/dist-packages/landscape/sysinfo/deployment.pyt   <module>   s   /