
j4Vdc           @   sW  d  Z  d d l Z d d l Z d d l m Z d d l m Z d d l Z d d l Z d d l	 Z	 d d l
 m Z m Z m Z d d l m Z m Z m Z d d l m Z m Z d d l m Z d d	 l m Z m Z m Z d d
 l m Z m Z d d l m Z m  Z  m! Z! m" Z" e e e e e g Z# e$ d   e# g   Z% d e& f d     YZ' e'   Z( d   Z) d   Z* d d  Z, d   Z- d d  Z. d   Z/ d   Z0 d   Z1 d   Z2 d   Z3 d   Z4 d   Z5 d   Z6 d   Z7 e8 d  Z9 d d  Z: d  Z; d! Z< d"   Z= d#   Z> d$   Z? d%   Z@ d&   ZA d'   ZB d( d)  ZC d d*  ZD d S(+   s  
This module contains Fab's `main` method plus related subroutines.

`main` is executed as the command line ``fab`` program and takes care of
parsing options and commands, loading the user settings file, loading a
fabfile, and executing the commands given.

The other callables defined in this module are internal only. Anything useful
to individuals leveraging Fabric as a library, should be kept elsewhere.
iN(   t   isMappingType(   t   OptionParser(   t   apit   statet   colors(   t   consolet   filest   project(   t   disconnect_allt   ssh(   t   env_options(   t   Taskt   executet   get_task_details(   t   _Dictt   crawl(   t   abortt   indentt   warnt	   _pty_sizec         C   s   |  t  t t |  j    S(   N(   t   filtert   callablet   varst   values(   t   xt   y(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   <lambda>!   t    t   _ModuleCachec           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   sP   
    Set-like object operating on modules and storing __name__s internally.
    c         C   s   t    |  _ d  S(   N(   t   sett   cache(   t   self(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   __init__,   s    c         C   s   | j  |  j k S(   N(   t   __name__R   (   R   t   value(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   __contains__/   s    c         C   s   |  j  j | j  S(   N(   R   t   addR!   (   R   R"   (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR$   2   s    c         C   s   |  j  j   S(   N(   R   t   clear(   R   (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR%   5   s    (   R!   t
   __module__t   __doc__R    R#   R$   R%   (    (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR   (   s
   			c         C   sg   t  j j |   rc d   } t | t |  d   } t d   g  | D] } | j d  ^ qC D  Si  S(   s   
    Take given file path and return dictionary of any key=value pairs found.

    Usage docs are in sites/docs/usage/fab.rst, in "Settings files."
    c         S   s   |  o |  j  d  S(   Nt   #(   t
   startswith(   t   s(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR   B   R   t   rc         s   s0   |  ]& \ } } } | j    | j    f Vq d  S(   N(   t   strip(   t   .0t   kt   _t   v(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pys	   <genexpr>D   s    t   =(   t   ost   patht   existsR   t   opent   dictt	   partition(   R3   t   commentst   settingsR*   (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   load_settings;   s    		'c         C   s1   t  j j |   o0 t  j j t  j j |  d   S(   s-   
    Is the given path a Python package?
    s   __init__.py(   R2   R3   t   isdirR4   t   join(   R3   (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   _is_packageJ   s    c         C   ss  |  d k r t j j g }  n  |  d j d  sI |  |  d d g 7}  n  t j j |  d  r x|  D]X } t j j |  } t j j	 |  rf | j d  s t
 |  r t j j |  Sqf qf Wn d } x t j j t j j |   d rnxc |  D][ } t j j | |  } t j j	 |  r | j d  s?t
 |  rRt j j |  Sq q Wt j j d |  } q Wd S(   s   
    Attempt to locate a fabfile, either explicitly or by searching parent dirs.

    Usage docs are in sites/docs/usage/fabfiles.rst, in "Fabfile discovery."
    i    s   .pyt   .i   s   ..N(   t   NoneR   t   envt   fabfilet   endswithR2   R3   t   dirnamet
   expanduserR4   R=   t   abspatht   splitR<   (   t   namest   namet   expandedR3   t   joined(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   find_fabfileT   s$    %c         C   s{   |  \ } } yK t  |  oS | t k oS | j d  oS t j |  oR t | t  } Wn t t f k
 rv t	 } n X| S(   sU   
    Takes (name, object) tuple, returns True if it's a non-Fab public callable.
    R/   (
   R   t
   _internalsR)   t   inspectt   isclasst
   issubclasst	   Exceptiont
   ValueErrort	   TypeErrort   False(   t   tupRH   t   funct
   is_classic(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   is_classic_taskw   s    #
c         C   sR  | d k r t } n  t j j |   \ } } t } d } | t j k rd t j j d |  t } nH t j j	 |  } | d k r | } t j j d |  t j | d =n  | t j j
 |  d  } | r t j d =n  | d k	 rt j j | d |  t j d =n  t |  \ } }	 }
 } t j j r5|	 n |
 } t j   | | | f S(   s   
    Import given fabfile path and return (docstring, callables).

    Specifically, the fabfile's ``__doc__`` attribute (a string) and a
    dictionary of ``{'name': callable}`` containing all callables which pass
    the "is a Fabric task" test.
    i    i   N(   R?   t
   __import__R2   R3   RF   RS   t   syst   insertt   Truet   indext   splitextt   load_tasks_from_moduleR   R@   t   new_style_taskst   _seenR%   (   R3   t   importert	   directoryRA   t   added_to_pathR\   t   it   importedt	   docstringt	   new_stylet   classict   defaultt   tasks(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   load_fabfile   s.    		
c         C   s   t  |   } d | k rN g  | D]& } | | d k r | | | f ^ q } n | j   } t |  \ } } } |  j | | | f S(   sH   
    Handles loading all of the tasks for a given `imported` module
    t   __all__(   R   t   itemst   extract_tasksR'   (   Re   t   imported_varsRH   Rg   Rh   Ri   (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR^      s    3c         C   s  t    } i  } d } d t j k r3 t t j _ n  xU|  D]M} | \ } } t |  r t t j _ | j r | j d k r | | | j <n | | _ | | | <| j	 d k	 r x | j	 D] } | | | <q Wn  | j
 r| } qq: t |  r | | | <q: t |  r: t |  \ } }	 }
 } xD |	 j   D]6 \ } } | | k rVt    | | <n  | | | | <q.W| d k	 r| | | _ qq: q: W| | | f S(   s@   
    Handle extracting tasks from a given list of variables
    R_   t	   undefinedN(   R   R?   R   R@   RS   R_   t   is_task_objectR[   RH   t   aliasest
   is_defaultRW   t   is_task_moduleR^   Rm   Ri   (   Ro   R_   t   classic_taskst   default_taskRT   RH   t   objt   aliast   docst   newstyleRh   Ri   t	   task_namet   task(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyRn      s:    		
	c         C   s3   t  |  t j  r/ |  t k r/ t j |   t Sd S(   s:   
    Determine if the provided value is a task module
    N(   t
   isinstancet   typest
   ModuleTypeR`   R$   R[   (   t   a(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyRt      s    c         C   s   t  |  t  o |  j S(   s   
    Determine if the provided value is a ``Task`` object.

    This returning True signals that all tasks within the fabfile
    module must be Task objects.
    (   R}   R   t   use_task_objects(   R   (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyRq      s    c          C   s~  t  d d  }  |  j d d d d d d d+ } |  j d d d | d d
 d d d d d j |  |  j d d d d d t d d |  j d d d d t d d |  j d d d d d d d t d d |  j d d d  d d! d d" d d# |  j d$ d d d d% d t d d& |  j d' d( d d d d) d t d d* x t D] } |  j |  qHW|  j   \ } } |  | | f S(,   s   
    Handle command-line options with optparse.OptionParser.

    Return list of arguments, largely for use in `parse_arguments`.
    t   usagesG   fab [options] <command>[:arg1,arg2=val2,host=foo,hosts='h1;h2',...] ...s   -ds	   --displayt   metavart   NAMEt   helps&   print detailed info about command NAMEt   shortt   normalt   nesteds   -Fs   --list-formatt   choicesRi   t   FORMATs   formats --list, choices: %ss   , s   -Is   --initial-password-promptt   actiont
   store_trues   Force password prompt up-fronts   --initial-sudo-password-prompts#   Force sudo password prompt up-fronts   -ls   --listt   destt   list_commandss(   print list of possible commands and exits   --sets   KEY=VALUE,...t   env_settingsR   s3   comma separated KEY=VALUE pairs to set Fab env varss   --shortlistt	   shortlists   alias for -F short --lists   -Vs	   --versiont   show_versions&   show program's version number and exit(   R   R   R   (   R   t
   add_optionR<   RS   R
   t
   parse_args(   t   parsert   LIST_FORMAT_OPTIONSt   optiont   optst   args(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   parse_options  sV    
	
c         C   s   t  |  | f  p t |  S(   s@   
    Is the object a task as opposed to e.g. a dict or int?
    (   RW   Rq   (   RH   R"   (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   _is_taskh  s    c         C   s   g  g  } } xU |  j    D]G \ } } t | |  rE | j |  q t |  r | j |  q q Wt |  } t |  } | | f S(   N(   t	   iteritemsR   t   appendR    t   sorted(   t   mappingRj   t   collectionsRH   R"   (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   _sift_taskso  s    c            s{   t  |   \ } } xb | D]Z   |    } t | d  rH | j    n    f d   } | j t | t |    q W| S(   s   
    Flatten & sort task names in a breadth-first fashion.

    Tasks are always listed before submodules at the same level, but within
    those two groups, sorting is alphabetical.
    Ri   c            s   d j    |  f  S(   NR>   (   R<   (   R   (   t
   collection(    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR     R   (   R   t   hasattrR   t   extendt   mapt   _task_names(   R   Rj   R   t   moduleR<   (    (   R   sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR   {  s    
 c         C   s6   |  s
 t  St | t j  j } t | t  r2 | Sd  S(   N(   RS   R   R   t   commandsR'   R}   t
   basestring(   t
   docstringsRH   Rf   (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   _print_docstring  s
    c         C   s  g  } t  t j  } t d   | d  } d } d } t   d d t |  } x | D] } d  } t |  |  }	 |	 r t d  |	 j	    }
 |
 d j
   } | | t |  t |  } t |  | k r | |  | } n  | j |  | | } n | } | j t |   qX W| S(   Nc         S   s   t  |  t |   S(   N(   t   maxt   len(   R   t   b(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR     R   i    s     s   ...i   (   R   R   R   t   reduceR   R   R?   R   R   t
   splitlinesR,   t   ljustR   R   (   R   t   resultt
   task_namest   max_lent   sept   trailt	   max_widthRH   t   outputRf   t   linest
   first_linet   size(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   _normal_list  s&    i   c            s   g  } t  |   \ } } | j t   f d   |   xS | D]K } |  | } | j t | d d   d  | j t |   d   q> W| S(   Nc            s   t  |  d   d S(   Nt   spacesi   (   R   (   R   (   t   level(    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR     R   t   :R   i   i   (   R   R   R   R   R   t   _nested_list(   R   R   R   Rj   R   R   R   (    (   R   sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR     s    
!s   Available commandss(    (remember to call as module.[...].task)c         C   s   | d k r t  t j  Sg  } |  rT |  j d  s: d n d } | j |  |  n  t } | d k rs | t 7} n  | j | d  | d k r t   n t t j  } | j	 |  | S(   s  
    Print all found commands/tasks, then exit. Invoked with ``-l/--list.``

    If ``docstring`` is non-empty, it will be printed before the task list.

    ``format_`` should conform to the options specified in
    ``LIST_FORMAT_OPTIONS``, e.g. ``"short"``, ``"normal"``.
    R   s   
R   R   s   :
R   (
   R   R   R   RB   R   t   COMMANDS_HEADERt   NESTED_REMINDERR   R   R   (   Rf   t   format_R   t   trailert   headert   c(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR     s    
$c         C   s   t  |  t j  } | d	 k rJ d } t | |  d j t t   f  n  t | d  rh | j	   } n t
 |  } | r d |  GHd GHt | d t GHd GHn	 d |  GHt j d  d	 S(
   sS   
    Print command function's docstring, then exit. Invoked with -d/--display.
    s8   Task '%s' does not appear to exist. Valid task names:
%ss   
t   __details__s.   Displaying detailed information for task '%s':R   R,   s0   No detailed information available for task '%s':i    N(   R   R   R   R?   R   R<   R   RS   R   R   R   R   R[   RY   t   exit(   RH   t   commandt   msgt   task_details(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   display_command  s    &		c   	      C   s   d |  } | | k r# | j  |   S| j |  \ } } } | j  |   } | d } | d  } t |  |  } | |  | d 7} | | g | d S(   s   
    Allows for escaping of the separator: e.g. task:arg='foo\, bar'

    It should be noted that the way bash et. al. do command line parsing, those
    single quotes are required.
    s   \%sii    i   (   RF   R7   t   _escape_split(	   R   t   argstrt   escaped_sept   beforeR/   t   aftert	   startlistt
   unfinishedt   endlist(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR     s    


c         C   s  g  } x|  D]} g  } i  } g  } g  } g  } d | k r| j  d d  \ } } xUt d |  D]A}	 t d |	  }
 t |
  d k r|
 \ } } | d k r| d k r | j   g } q| d k r g  | j  d
  D] } | j   ^ q } q| d k r| j   g } q| d k rNg  | j  d
  D] } | j   ^ q3} q| d	 k rg  | j  d
  D] } | j   ^ qj} qq| | | <qe | j |
 d  qe Wn  | j | | | | | | f  q W| S(   s   
    Parse string list into list of tuples: command, args, kwargs, hosts, roles.

    See sites/docs/usage/fab.rst, section on "per-task arguments" for details.
    R   i   t   ,R1   t   hostt   hostst   rolet   rolest   exclude_hostst   ;i    (   R   R   R   R   R   (   RF   R   R   R,   R   (   t	   argumentst   cmdst   cmdR   t   kwargsR   R   R   R   t   pairR   R.   R0   R   (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   parse_arguments  s8    ++.#c         C   s   d j  |   S(   sK   
    Merge list of "remainder arguments" into a single command string.
    t    (   R<   (   R   (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   parse_remainder7  s    c         C   sd   |  r0 x' |  j  d  D] } t t j | <q Wn  | r` x' | j  d  D] } t t j | <qF Wn  d S(   sI  
    Update state.output values as per given comma-separated list of key names.

    For example, ``update_output_levels(show='debug,warnings')`` is
    functionally equivalent to ``state.output['debug'] = True ;
    state.output['warnings'] = True``. Conversely, anything given to ``hide``
    sets the values to ``False``.
    R   N(   RF   R[   R   R   RS   (   t   showt   hidet   key(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   update_output_levels>  s    	i    c         C   s(   d j  t |  |   GHt j |  d  S(   Ns   
(   R<   R   RY   R   (   Rf   t   formatt   code(    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   show_commandsO  s    c            s  zsyt    \ } } } | j } | j } xe t d | j  D]Q } t d |  } | d } t } t |  d k r | d } n  | t j | <q= Wx* t	 D]" } t
 | | j  t j | j <q Wx\ d d d g D]K } | t j k r t t j | t  r t j | j d  t j | <q q W| t j d	 <t d
 | j d | j  | j rxd t j j GHd t j GHt j d  n  t j j t t j j   t |   }	 |	 r| rt d  n  |	 t j _ d }
 |	 rt |	  \ } } }
 t j  j |  n  | j! | j" | j# | | |
 f } t$ |  sB| j%   t j d  n  t j  r`| r`t d  n  t j& j' r|	 r~d |	 GHqd GHn  | j" rd | _( t | _! n  | j! rt) | | j(  n  | j# rt* | j#  n  | p| p|
 s| j%   t j d  n  t+ |  } t, |    g  } x> | D]6 } t- | d t j   d k r*| j. | d  q*q*W| rt j j/ d t0  rt1 d t2 |   t) d | j( d  n    rd }   f d   t j  | <| j. | g  i  g  g  g  f  n  | r |
 r | j. |
 j3 g  i  g  g  g  f  n  | j4 rGd } t5 j5 |  t j _6 n  | j7 rnd } t5 j5 |  t j _8 n  t j& j' rd j9 d   | D  } d | GHn  xB | D]: \ } } } } } } t: | d | d | d | | | qWt j& j; rd GHn  Wnv t< k
 r  nc t= k
 rKt j& j; r;t j> j? d  n  t j d  n' t j@ t jA     t j d  n XWd tB   Xt j d  d S(   s+   
    Main command-line execution loop.
    R   R1   i    i   i   R   R   R   Rj   R   R   s	   Fabric %ss   Paramiko %ssg   Couldn't find any fabfiles!

Remember that -f can be used to specify fabfile path, and use -h for help.s$   Fabfile didn't contain any commands!s   Using fabfile '%s's+   No fabfile loaded -- remainder command onlyR   t   skip_unknown_taskss   Command(s) not found:
%ss   <remainder>c              s   t  j    S(   N(   R   t   run(    (   t   remainder_command(    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyR     R   s    Initial value for env.password: s%   Initial value for env.sudo_password: s   , c         s   s   |  ] } | d  Vq d S(   i    N(    (   R-   R   (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pys	   <genexpr>  s    s   Commands to run: %ss   
Done.s
   
Stopped.
N(C   R   t   largst   rargsR   R   R[   R   R   R@   R
   t   getattrR   R}   R   RF   R   R   R   R   t   versionR	   t   __version__RY   R   t   updateR:   t   rcfileRK   R   t   real_fabfileR?   Rk   R   R   R   t   displayt   anyt
   print_helpR   t   debugt   list_formatR   R   R   R   R   R   t   getRS   R   R   RH   t   initial_password_promptt   getpasst   passwordt   initial_sudo_password_promptt   sudo_passwordR<   R   t   statust
   SystemExitt   KeyboardInterruptt   stderrt   writet
   excepthookt   exc_infoR   (   t   fabfile_locationsR   t   optionsR   t   remainder_argumentsR   R   R"   R   RA   Ri   Rf   t	   callablest   actionst   commands_to_runt   unknown_commandsRT   R+   t   promptRG   RH   R   R   t	   arg_hostst	   arg_rolest   arg_exclude_hosts(    (   R   sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   mainT  s     		
 %$	

				
"%		(E   R'   R   RM   t   operatorR    t   optparseR   R2   RY   R~   t   fabricR   R   R   t   fabric.contribR   R   R   t   fabric.networkR   R	   t   fabric.stateR
   t   fabric.tasksR   R   R   t   fabric.task_utilsR   R   t   fabric.utilsR   R   R   R   t   _modulesR   RL   t   objectR   R`   R:   R=   R?   RK   RW   Rk   R^   Rn   Rt   Rq   R   R   R   R   R   R[   R   R   R   R   R   R   R   R   R   R   R   R  (    (    (    sY   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/main.pyt   <module>
   s\   "					
#	/		'		
	`								)		