
[XMc           @   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	 m
 Z
 d  d l m Z d  d l m Z m Z e j Z e j Z e  j d e d d	 d
   Z d d d  Z d   Z d e	 j f d     YZ d   Z d S(   iN(   t   servicet   app(   t   sob(   t   usaget   util(   t   plugin(   t   uidFromStringt   gidFromStrings   mktap and related support modules are deprecated as of Twisted 8.0.  Use Twisted Application Plugins with the 'twistd' command directly, as described in 'Writing a Twisted Application Plugin for twistd' chapter of the Developer Guide.t
   stackleveli   c         C   s@   |  d k	 r t |   }  n  | d k	 r6 t |  } n  |  | f S(   s  
    Convert one or both of a string representation of a UID and GID into
    integer form.  On platforms where L{pwd} and L{grp} is available, user and
    group names can be converted.

    @type uid: C{str} or C{NoneType}
    @param uid: A string giving the base-ten representation of a UID or the
        name of a user which can be converted to a UID via L{pwd.getpwnam},
        or None if no UID value is to be obtained.

    @type gid: C{str} or C{NoneType}
    @param uid: A string giving the base-ten representation of a GID or the
        name of a group which can be converted to a GID via
        L{grp.getgrnam}, or None if no UID value is to be obtained.

    @return: A two-tuple giving integer UID and GID information for
        whichever (or both) parameter is provided with a non-C{None} value.

    @raise ValueError: If a user or group name is supplied and L{pwd} or L{grp}
        is not available.
    N(   t   NoneR   R   (   t   uidt   gid(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyt   getid   s
    c         C   s7   i  } t  j t  } x | D] } | | | j <q W| S(   N(   R   t
   getPluginst   IServiceMakert   tapname(   t   debugt   progresst	   tapLookupt   pluginst   plug(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyt   loadPlugins8   s
    c   
      C   s   | r0 t  j j |  r0 t j | d d   } n t j | | |  } | r` | t j |  _ n  |  j	 t j
 |   t j |  j |  t j |  }	 |	 r d  } n  t j |  j d | d |	  d  S(   Nt   picklet   filenamet
   passphrase(   t   ost   patht   existsR    t   loadApplicationR	   t   Applicationt   IProcesst   processNamet   setServiceParentt   IServiceCollectionR   t   IPersistablet   setStyleR   t   getSavePassphraset   save(
   t   sert   namet   appendt   procnamet   typet	   encryptedR
   R   t   aR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyt   addToApplicationA   s    	t   FirstPassOptionsc           B   s
  e  Z d  Z d Z d) Z d d d* d e g d d d* d e g d d	 d* d
 g d d d d g d d d* d g g Z d d d g d d d g d d d g d d d g g Z	 i d d 6d d 6Z
 i d  d 6d! d 6d" d 6d# d 6Z d$   Z d%   Z d&   Z d'   Z d(   Z RS(+   s6   Usage:    mktap [options] <command> [command options] i    R
   t   us   The uid to run as.R   t   gs   The gid to run as.R(   R,   sN   An existing .tap file to append the plugin to, rather than creating a new one.R*   t   tR   sC   The output format to use; this can be 'pickle', 'xml', or 'source'.t   appnamet   ns-   The process name to use for this application.R+   t   esZ   Encrypt file before writing (will make the extension of the resultant file begin with 'e')R   t   ds)   Show debug information for plugin loadingR   t   ps,   Show progress information for plugin loadingt   helpt   hs   Display this messages   _files -g "*.tap"s   (pickle xml source)s   tap file to append tos   uid to run ass   gid to run ass   output formatc      	   C   s   g  } xy | j    D]k \ } } t j |  rS | j | d  | d  | j f  q | j | d  | d  t | d d  f  q W| j   | |  _ d  S(   Nc         S   s
   |  j    S(   N(   t   options(   t   m(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyt   <lambda>v   s    c         S   s   |  j    j   S(   N(   t   loadt   Options(   t   obj(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyR;   y   s    t   descriptiont    (	   t	   iteritemsR   t
   providedByR(   R	   R?   t   getattrt   sortt   subCommands(   t   selfR   t   scR'   t   module(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyt   initq   s    
c         G   s   |  j  | 7_  d  S(   N(   t   params(   RF   t   rest(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyt	   parseArgs   s    c         C   s   d G| GHd  S(   Ns   Debug: (    (   RF   t   info(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyt   _reportDebug   s    c         C   sC   |  j  |  } | r  d G| Gn  | d k r? d d d d Gn  d  S(   Ns   Progress: g      ?s   t    iO   (   t   pb(   RF   RM   t   s(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyt   _reportProgress   s
    c         C   sc  |  j  r d  Sd  } } |  d r- |  j } n  |  d rX |  j } t j d d  |  _ n  y t | |  |  _ Wn  t	 k
 r t
 j d   n X|  j |  j  d |  _  |  j |  j  t |  d  s |  d r t
 j t |     n  t |  d  r(|  j j d  r(t
 j t |  j    n  |  j j |  j  s_t
 j d	 d
 j |  j    n  d  S(   NR   R   i<   g      ?s   Couldn't load the plugins file!i   t
   subOptionsR7   s   Please select one of: RO   (   t	   recursingR	   RN   RR   R   t   makeStatBarRP   R   R   t   IOErrorR   t
   UsageErrorRI   t   parseOptionsRJ   t   hasattrt   strRS   t   gett   has_keyt
   subCommandt   join(   RF   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyt   postOptions   s,    	


		!	(    N(   t   __name__t
   __module__t   synopsisRT   RJ   R	   R   R   t   optParameterst   optFlagst   zsh_actionst   zsh_actionDescrRI   RL   RN   RR   R_   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyR.   O   s.   		

				c       
   C   s   t    }  y |  j t j d  WnE t j k
 rK } | GHt j d  n t k
 rh t j d  n X|  j |  j	 } t
 j |  s | j   } n  | j |  j  } t | |  j	 |  d |  d |  d |  d |  d |  d  d  S(	   Ni   i   R(   R2   R*   R+   R
   R   (   R.   RX   t   syst   argvR   RW   t   exitt   KeyboardInterruptR   R]   R   RB   R<   t   makeServiceRS   R-   (   R9   R4   t   plgR&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyt   run   s     	(   t   warningsRg   R   t   twisted.applicationR    R   t   twisted.persistedR   t   twisted.pythonR   R   t   twistedR   t   twisted.python.utilR   R   R   t   ServiceMakert
   _tapHelpert   warnt   DeprecationWarningR   R	   R   R-   R=   R.   Rm   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/mktap.pyt   <module>   s   $					V