ó
½-'Nc           @   s¦   d  d l  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 d  d l m Z m Z d e e f d „  ƒ  YZ d	 „  Z d S(
   iÿÿÿÿN(   t   Applicationt   Service(   t   startApplication(   t   rotate_logs(   t   TwistedReactor(   t   get_versioned_persistt   init_loggingt   LandscapeServicec           B   s5   e  Z d  Z e Z d Z d „  Z d „  Z d „  Z	 RS(   s  Utility superclass for defining Landscape services.

    This sets up the reactor and L{Persist} object.

    @cvar service_name: The lower-case name of the service. This is used to
        generate the bpickle and the Unix socket filenames.
    @ivar config: A L{Configuration} object.
    @ivar reactor: A L{TwistedReactor} object.
    @ivar persist: A L{Persist} object, if C{persist_filename} is defined.
    @ivar factory: A L{LandscapeComponentProtocolFactory}, it must be provided
        by instances of sub-classes.
    c         C   sÂ   | |  _  y d d l m } Wn t k
 r0 n X| j ƒ  |  j ƒ  |  _ |  j re t |  ƒ |  _	 n  |  j  d  k	 o} |  j  j s™ t j t j d „  ƒ n  t j j |  j  j |  j d ƒ |  _ d  S(   Niÿÿÿÿ(   t   bpickle_dbusc         S   s   t  ƒ  S(   N(   R   (   t   signalt   frame(    (    s5   /usr/lib/python2.7/dist-packages/landscape/service.pyt   <lambda>)   s    s   .sock(   t   configt   landscape.libR   t   ImportErrort   installt   reactor_factoryt   reactort   persist_filenameR   t   persistt   Nonet   ignore_sigusr1R	   t   SIGUSR1t   ost   patht   joint   sockets_patht   service_namet   socket(   t   selfR   R   (    (    s5   /usr/lib/python2.7/dist-packages/landscape/service.pyt   __init__   s    	
	c         C   sX   t  j |  ƒ t j d |  j j ƒ  |  j j ƒ  f ƒ |  j j	 |  j
 |  j ƒ |  _ d  S(   Ns   %s started with config %s(   R   t   startServicet   loggingt   infoR   t
   capitalizeR   t   get_config_filenameR   t   listen_unixR   t   factoryt   port(   R   (    (    s5   /usr/lib/python2.7/dist-packages/landscape/service.pyR   -   s    	 c         C   s:   t  j |  ƒ t j d |  j j ƒ  |  j j ƒ  f ƒ d  S(   Ns   %s stopped with config %s(   R   t   stopServiceR    R!   R   R"   R   R#   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/landscape/service.pyR'   3   s    	N(
   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R'   (    (    (    s5   /usr/lib/python2.7/dist-packages/landscape/service.pyR      s   		c         C   s•   |  ƒ  } | j  | ƒ t | | j ƒ t d | j f ƒ } | | ƒ } | j | ƒ t | t ƒ | j r„ t j t j	 t j
 ƒ n  | j j ƒ  d S(   s{  Run a Landscape service.

    This function instantiates the specified L{LandscapeService} subclass and
    attaches the resulting service object to a Twisted C{Application}.  After
    that it starts the Twisted L{Application} and calls the
    L{TwistedReactor.run} method of the L{LandscapeService}'s reactor.

    @param configuration_class: The service-specific subclass of
        L{Configuration} used to parse C{args} and build the C{service_class}
        object.
    @param service_class: The L{LandscapeService} subclass to create and start.
    @param args: Command line arguments used to initialize the configuration.
    s   landscape-%sN(   t   loadR   R   R    t   setServiceParentR   t   Falset   ignore_sigintR	   t   SIGINTt   SIG_IGNR   t   run(   t   configuration_classt   service_classt   argst   configurationt   applicationt   service(    (    s5   /usr/lib/python2.7/dist-packages/landscape/service.pyt   run_landscape_service;   s    		(   R   R    R	   t   twisted.application.serviceR    R   t   twisted.application.appR   t   landscape.logR   t   landscape.reactorR   t   landscape.deploymentR   R   t   objectR   R8   (    (    (    s5   /usr/lib/python2.7/dist-packages/landscape/service.pyt   <module>   s   .