Current Path : /usr/lib/python2.7/dist-packages/twisted/application/ |
Current File : //usr/lib/python2.7/dist-packages/twisted/application/service.pyc |
Nc @ s\ d Z d d l m Z m Z m Z d d l m 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 e f d YZ d d d YZ d e f d YZ d e f d YZ d e f d YZ d d d YZ d d d Z d d Z d d d d d d d d d g Z d S( sa Service architecture for Twisted. Services are arranged in a hierarchy. At the leafs of the hierarchy, the services which actually interact with the outside world are started. Services can be named or anonymous -- usually, they will be named if there is need to access them through the hierarchy (from a parent or a sibling). Maintainer: Moshe Zadka i( t implementst Interfacet Attribute( t namedAny( t components( t defer( t sob( t IPlugint IServiceMakerc B s; e Z d Z e d Z e d Z e d Z d Z RS( s An object which can be used to construct services in a flexible way. This interface should most often be implemented along with L{twisted.plugin.IPlugin}, and will most often be used by the 'twistd' command. s A short string naming this Twisted plugin, for example 'web' or 'pencil'. This name will be used as the subcommand of 'twistd'.sL A brief summary of the features provided by this Twisted application plugin.sc A C{twisted.python.usage.Options} subclass defining the configuration options for this application.c C s d S( s Create and return an object providing L{twisted.application.service.IService}. @param options: A mapping (typically a C{dict} or L{twisted.python.usage.Options} instance) of configuration options to desired configuration values. N( ( t options( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyt makeService/ s ( t __name__t __module__t __doc__R t tapnamet descriptionR R ( ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyR s t ServiceMakerc B sT e Z d Z e e e d Z d Z e e Z d Z e e Z RS( sO Utility class to simplify the definition of L{IServiceMaker} plugins. c C s( | | _ | | _ | | _ | | _ d S( N( t namet moduleR R ( t selfR R R R ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyt __init__A s c C s d } | f S( Nc S s t | j j S( N( R R t Options( R ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyt getI s ( ( R ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyR H s c C s d } | f S( Nc S s t | j j S( N( R R R ( R ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyR P s ( ( R ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyR O s ( R R R R R R R R t propertyR ( ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyR ; s t IServicec B sD e Z d Z d Z d Z d Z d Z d Z d Z RS( s A service. Run start-up and shut-down code at the appropriate times. @type name: C{string} @ivar name: The name of the service (or None) @type running: C{boolean} @ivar running: Whether the service is running. c C s d S( s Set the name of the service. @type name: C{str} @raise RuntimeError: Raised if the service already has a parent. N( ( R ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyt setNamec s c C s d S( sx Set the parent of the service. This method is responsible for setting the C{parent} attribute on this service (the child service). @type parent: L{IServiceCollection} @raise RuntimeError: Raised if the service already has a parent or if the service has a name and the parent already has a child by that name. N( ( t parent( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyt setServiceParentk s c C s d S( s Use this API to remove an L{IService} from an L{IServiceCollection}. This method is used symmetrically with L{setServiceParent} in that it sets the C{parent} attribute on the child. @rtype: L{Deferred<defer.Deferred>} @return: a L{Deferred<defer.Deferred>} which is triggered when the service has finished shutting down. If shutting down is immediate, a value can be returned (usually, C{None}). N( ( ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyt disownServiceParentv s c C s d S( s$ Start the service. N( ( ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyt startService s c C s d S( s" Stop the service. @rtype: L{Deferred<defer.Deferred>} @return: a L{Deferred<defer.Deferred>} which is triggered when the service has finished shutting down. If shutting down is immediate, a value can be returned (usually, C{None}). N( ( ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyt stopService s c C s d S( s Do preparation work for starting the service. Here things which should be done before changing directory, root or shedding privileges are done. N( ( ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyt privilegedStartService s ( R R R R R R R R R ( ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyR W s t Servicec B si e Z d Z e e d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z RS( s Base class for services. Most services should inherit from this class. It handles the book-keeping reponsibilities of starting and stopping, as well as not serializing this book-keeping information. i c C s, | j j } | j d r( | d =n | S( Nt running( t __dict__t copyt has_key( R t dict( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyt __getstate__ s c C s+ | j d k r t d n | | _ d S( Ns% cannot change name when parent exists( R t Nonet RuntimeErrorR ( R R ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyR s c C sH | j d k r | j n t | | } | | _ | j j | d S( N( R R' R t IServiceCollectiont addService( R R ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyR s c C s | j j | } d | _ | S( N( R t removeServiceR' ( R t d( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyR s c C s d S( N( ( R ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyR s c C s d | _ d S( Ni ( R! ( R ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyR s c C s d | _ d S( Ni ( R! ( R ( ( s? /usr/lib/python2.7/dist-packages/twisted/application/service.pyR s N( R R R R R R! R' R R R&