ó
j4Vdc           @€  sš  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 d  d l	 m
 Z
 m Z m 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 m Z m Z d  d
 l m Z e j d  d k r"d e f d „  ƒ  YZ d „  Z e j e _  e e _ n  d „  Z! d „  Z" d e f d „  ƒ  YZ# d e# f d „  ƒ  YZ$ d „  Z% d „  Z& d „  Z' d „  Z( d „  Z) d „  Z* d S(   iÿÿÿÿ(   t   with_statement(   t   wrapsN(   t   state(   t   abortt   warnt   error(   t   to_dictt   normalize_to_stringt   disconnect_all(   t   settings(   t   JobQueue(   t   crawlt   merget   parse_kwargs(   t   NetworkErrori   i   t   ArgSpecc           B€  s   e  Z d  „  Z d „  Z RS(   c         C€  s=   | |  _  | |  _ | |  _ | |  _ | | | | f |  _ d  S(   N(   t   argst   varargst   keywordst   defaultst   _tuple(   t   selfR   R   R   R   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   __init__   s
    				c         C€  s   |  j  | S(   N(   R   (   R   t   idx(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   __getitem__   s    (   t   __name__t
   __module__R   R   (    (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyR      s   	c         C€  s   t  t j |  ƒ Œ  S(   N(   R   t   inspectt   _getargspec(   t   func(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   patched_get_argspec   s    c   	   	   C€  sÙ   |  j  r t j |  j  ƒ n d g } t j |  ƒ } | j sB g  n | j } t | ƒ } | j t | j ƒ |  } | j d | } | j d d j	 | g  t
 | | ƒ D] \ } } d | | f ^ q¤ ƒ ƒ d j	 | ƒ S(   Ns   No docstring providediÿÿÿÿs   Arguments: %ss   , s   %s=%rs   
(   t   __doc__t   textwrapt   dedentR   t
   getargspecR   t   lenR   t   appendt   joint   zip(	   t   taskt   detailst   argspect   default_argst   num_default_argst   args_without_defaultst   args_with_defaultst   argt   default(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   get_task_details%   s    		5c         €  s   ‡  f d †  } | S(   Nc         €  s   ˆ  j  |  g  ƒ S(   N(   t   get(   t   key(   t   env(    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   inner=   s    (    (   R3   R4   (    (   R3   sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt	   _get_list<   s    t   Taskc           B€  sb   e  Z d  Z d Z e Z d Z e Z	 d d e d d „ Z
 d „  Z d „  Z d d „ Z d „  Z RS(   s˜  
    Abstract base class for objects wishing to be picked up as Fabric tasks.

    Instances of subclasses will be treated as valid tasks when present in
    fabfiles loaded by the :doc:`fab </usage/fab>` tool.

    For details on how to implement and use `~fabric.tasks.Task` subclasses,
    please see the usage documentation on :ref:`new-style tasks
    <new-style-tasks>`.

    .. versionadded:: 1.1
    t	   undefinedc         O€  sX   | d  k	 r | g |  _ n  | d  k	 r3 | |  _ n  | d  k	 rK | |  _ n  | |  _ d  S(   N(   t   Nonet   aliasest   namet
   is_default(   R   t   aliasR9   R/   R:   R   t   kwargs(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyR   U   s    c         C€  s   t  |  j ƒ S(   N(   R0   t   run(   R   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   __details___   s    c         C€  s
   t  ‚ d  S(   N(   t   NotImplementedError(   R   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyR>   b   s    c   	      C€  så   | p i g  d 6g  d 6g  d 6} | j  d i  ƒ } | s? | rX t | | | | ƒ | f St |  d g  ƒ } t |  d g  ƒ } | sˆ | r¡ t | | | | ƒ | f St t | ƒ d j ƒ  ƒ } | j | ƒ t | Œ  | j  d g  ƒ f S(   sø   
        Return a tuple containing the host list the given task should be using
        and the roles being used.

        See :ref:`host-lists` for detailed documentation on how host lists are
        set.

        .. versionchanged:: 1.9
        t   hostst   rolest   exclude_hostst   roledefss   hosts roles exclude_hosts(   R1   R   t   getattrt   mapR5   t   splitR$   (	   R   t	   arg_hostst	   arg_rolest   arg_exclude_hostsR3   RD   t
   func_hostst
   func_rolest   env_vars(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   get_hosts_and_effective_rolese   s    
!c         C€  sj   | p t  | ƒ } t |  d d  ƒ } t | p0 | ƒ } t | t  | ƒ f ƒ } t j j rf d | GHn  | S(   Nt	   pool_sizes(   Parallel tasks now using pool size of %d(   R#   RE   R8   t   intt   minR   t   outputt   debug(   R   RA   R/   t   default_pool_sizet	   from_taskRO   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   get_pool_size   s    N(   R   R   R   R:   t   Truet   use_task_objectsR8   R9   t   FalseR;   R   R?   R>   RN   RV   (    (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyR6   B   s   
		t   WrappedCallableTaskc           B€  s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sù   
    Wraps a given callable transparently, while marking it as a valid Task.

    Generally used via `~fabric.decorators.task` and not directly.

    .. versionadded:: 1.1

    .. seealso:: `~fabric.docs.unwrap_tasks`, `~fabric.decorators.task`
    c         O€  s¥   t  t |  ƒ j | | Ž  | |  _ t | d ƒ re |  j d k rV | j |  _ |  _ qe |  j |  _ n  t | d ƒ rƒ | j |  _ n  t | d ƒ r¡ | j |  _ n  d  S(   NR   R7   R   R   (	   t   superRZ   R   t   wrappedt   hasattrR:   R   R   R   (   R   t   callableR   R=   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyR   ›   s    	c         O€  s   |  j  | | Ž  S(   N(   R>   (   R   R   R=   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   __call__ª   s    c         O€  s   |  j  | | Ž  S(   N(   R\   (   R   R   R=   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyR>   ­   s    c         C€  s   t  |  j | ƒ S(   N(   RE   R\   (   R   t   k(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   __getattr__°   s    c         C€  s8   |  } x% d | j  k r- | j  j d ƒ } q	 Wt | ƒ S(   NR\   (   t   __dict__R1   R0   (   R   t   orig(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyR?   ³   s    (   R   R   R   R   R_   R>   Ra   R?   (    (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyRZ   ‘   s   					c         C€  s/   t  j j r t |  d t ƒ p. t |  d t ƒ S(   s  
    Returns True if given ``task`` should be run in parallel mode.

    Specifically:

    * It's been explicitly marked with ``@parallel``, or:
    * It's *not* been explicitly marked with ``@serial`` *and* the global
      parallel option (``env.parallel``) is set to ``True``.
    t   serialt   parallel(   R   R3   Re   RE   RY   (   R'   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   requires_parallelº   s    c         C€  s   t  t d „  |  ƒ ƒ S(   Nc         S€  s   t  t |  d t j ƒ ƒ S(   Ni    (   Rf   R   R   t   commands(   t   x(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   <lambda>Ì   t    (   t   anyRF   (   t   commands_to_run(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   _parallel_tasksÊ   s    c           C€  s   t  j j d o t  j j S(   Nt   network(   R   R3   t   use_exceptions_fort   skip_bad_hosts(    (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   _is_network_error_ignoredÑ   s    c         €  s  t  j j r2 t ˆ  d ƒ r2 d | | d f GHn  t | ƒ } | j | ƒ | d k	 ru | j i t d 6t d 6ƒ n  | d k	 rô | d }	 ‡  f d †  }
 i | d 6| d	 6| d
 6|	 d 6| d 6} | j d |
 d	 | ƒ } |	 | _	 | j
 | ƒ n# t |    ˆ  j | | Ž  SWd QXd S(   s4   
    Primary single-host work body of execute()
    t   return_values   [%s] Executing task '%s't   commandRe   t   linewiset   host_stringc         €  sÌ   t  j j | ƒ ‡  ‡ f d †  } y' t  j j ƒ  | ˆ j |  | Ž  ƒ Wn| t k
 rÇ } | j t k	 r¦ t	 | t
 ƒ o t ƒ  s™ t j j d ˆ  ƒ n  | | ƒ n  t	 | t
 ƒ o» t ƒ  sÈ ‚  qÈ n Xd  S(   Nc         €  s   ˆ j  i ˆ  d 6|  d 6ƒ d  S(   NR:   t   result(   t   put(   Rv   (   R:   t   queue(    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   submitî   s    s0   !!! Parallel execution exception under host %r:
(   R   R3   t   updatet   connectionst   clearR>   t   BaseExceptiont	   __class__t
   SystemExitt
   isinstanceR   Rq   t   syst   stderrt   write(   R   R=   Rx   R:   R3   Ry   t   e(   R'   (   R:   Rx   sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyR4   ì   s    		R   R=   Rx   R:   R3   t   targetN(   R   RR   t   runningR]   R   Rz   R8   RW   t   ProcessR:   R$   R	   R>   (   R'   t   hostt   my_envR   R=   t   jobsRx   t   multiprocessingt	   local_envR:   R4   t
   kwarg_dictt   p(    (   R'   sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   _executeÕ   s(    

	c         C€  s   t  |  t ƒ S(   N(   R€   R6   (   R'   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   _is_task  s    c      
   O€  s»  i t  d 6} i  } t |  ƒ } | p. t |  ƒ s |  | d <t |  t j ƒ }  |  d k rÅ d | d f } t j j d t	 ƒ r t
 | ƒ d St | ƒ qÅ n( t |  d d ƒ } t |  d | ƒ | d <t |  ƒ sà t |  ƒ }  n  t | ƒ \ } }	 }
 } |  j |	 |
 | t j ƒ \ | d <| d	 <t |  ƒ } | r€y d
 d l } Wq†t k
 r|d
 d l } | j ƒ  } t | d ƒ q†Xn d } |  j | d t j j ƒ } | r´| j ƒ  n d } t | | ƒ } t j j rát  | _ n  | d rŽx» | d D]¯ } y) t |  | | | | | | | ƒ | | <Wng t k
 rŽ} | | | <t j j d sˆt j j rct
 n t } t  | j! d | d | j" ƒq‚  n Xt j j# röt$ ƒ  qöqöW| r·d | d } | j% ƒ  | j& ƒ  } xµ | j' ƒ  D]¤ \ } } | d d k rvt( | d t ƒ r?t) ƒ  r?t  | d j! d t
 d | d j" ƒqvt( | d t* ƒ rit  | d | d ƒqvt  | ƒ n  | d | | <qàWq·n) t+ |    |  j& | | Ž  | d <Wd QX| S(   s  
    Execute ``task`` (callable or name), honoring host/role decorators, etc.

    ``task`` may be an actual callable object, or it may be a registered task
    name, which is used to look up a callable just as if the name had been
    given on the command line (including :ref:`namespaced tasks <namespaces>`,
    e.g. ``"deploy.migrate"``.

    The task will then be executed once per host in its host list, which is
    (again) assembled in the same manner as CLI-specified tasks: drawing from
    :option:`-H`, :ref:`env.hosts <hosts>`, the `~fabric.decorators.hosts` or
    `~fabric.decorators.roles` decorators, and so forth.

    ``host``, ``hosts``, ``role``, ``roles`` and ``exclude_hosts`` kwargs will
    be stripped out of the final call, and used to set the task's host list, as
    if they had been specified on the command line like e.g. ``fab
    taskname:host=hostname``.

    Any other arguments or keyword arguments will be passed verbatim into
    ``task`` (the function itself -- not the ``@task`` decorator wrapping your
    function!) when it is called, so ``execute(mytask, 'arg1',
    kwarg1='value')`` will (once per host) invoke ``mytask('arg1',
    kwarg1='value')``.

    :returns:
        a dictionary mapping host strings to the given task's return value for
        that host's execution run. For example, ``execute(foo, hosts=['a',
        'b'])`` might return ``{'a': None, 'b': 'bar'}`` if ``foo`` returned
        nothing on host `a` but returned ``'bar'`` on host `b`.

        In situations where a task execution fails for a given host but overall
        progress does not abort (such as when :ref:`env.skip_bad_hosts
        <skip-bad-hosts>` is True) the return value for that host will be the
        error object or message.

    .. seealso::
        :ref:`The execute usage docs <execute>`, for an expanded explanation
        and some examples.

    .. versionadded:: 1.3
    .. versionchanged:: 1.4
        Added the return value mapping; previously this function had no defined
        return value.
    t   clean_revertRs   s'   %r is not callable or a valid task namet   skip_unknown_tasksNR   R:   t	   all_hostst   effective_rolesiÿÿÿÿsÙ   
    At least one task needs to be run in parallel, but the
    multiprocessing module cannot be imported (see above
    traceback.) Please make sure the module is installed
    or that the above ImportError is fixed.Rn   R   t	   exceptions2   One or more hosts failed while executing task '%s't	   exit_codei    t   resultss   <local-only>(,   RW   R^   R   R   R   Rg   R8   R3   R1   RY   R   R   RE   RZ   R   RN   Rf   R‹   t   ImportErrort	   tracebackt
   format_excRV   RO   t   QueueR
   RR   RS   t   _debugR   R   Ro   Rp   R   t   messageR\   t   eagerly_disconnectR   t   closeR>   t	   iteritemsR€   Rq   R}   R	   (   R'   R   R=   R‰   R—   t   is_callablet   msgt   dunder_namet
   new_kwargsRA   RB   RC   Re   R‹   R™   t   tbRO   Rx   RŠ   Rˆ   R„   R   t   errt   ran_jobsR:   t   d(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   execute  s‚    -




	'(   i   i   (+   t
   __future__R    t	   functoolsR   R   R   R    t   fabricR   t   fabric.utilsR   R   R   t   fabric.networkR   R   R   t   fabric.context_managersR	   t   fabric.job_queueR
   t   fabric.task_utilsR   R   R   t   fabric.exceptionsR   t   version_infot   objectR   R   R"   R   R0   R5   R6   RZ   Rf   Rm   Rq   R   R   R©   (    (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/tasks.pyt   <module>   s4   			O)				B	