ó
j4Vdc        
   @€  s  d  Z  d d l m Z d d l m Z m Z d d l 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 m Z m Z m Z d d	 l m Z m Z d d
 l m Z d d g Z e d d e d d e e d d „ ƒ Z d d e d „ Z d S(   sN   
Useful non-core functionality, e.g. functions composing multiple operations.
iÿÿÿÿ(   t   with_statement(   t   getcwdt   sepN(   t   datetime(   t   mkdtemp(   t
   needs_hostt   key_filenamest	   normalize(   t   localt   runt   sudot   put(   t   envt   output(   t   cdt   rsync_projectt   upload_projectt    s   -pthrvzc	         C€  s<  t  | d ƒ s | f } n  d t | ƒ }	 t g  | D] }
 t |
 ƒ j d d ƒ ^ q5 ƒ } d } t ƒ  } | r‡ d d j | ƒ } n  t t j	 ƒ \ } } } d | } d } t j
 d k rÇ d } n: t t j
 ƒ \ } } } d	 } | | | | | | | f } | | | | g } t | ƒ r5d
 d j | ƒ } n  i | rDd n d d 6|	 | d 6| d 6| d 6| d 6} d | } | d k r¡d t ƒ  j t ƒ d } n  | j d ƒ d k rÉd | | f } n d | | f } | rød | | | |  f } n d | | |  | f } t j r,d t j	 | f GHn  t | d | ƒS(   sÿ  
    Synchronize a remote directory with the current project directory via rsync.

    Where ``upload_project()`` makes use of ``scp`` to copy one's entire
    project every time it is invoked, ``rsync_project()`` uses the ``rsync``
    command-line utility, which only transfers files newer than those on the
    remote end.

    ``rsync_project()`` is thus a simple wrapper around ``rsync``; for
    details on how ``rsync`` works, please see its manpage. ``rsync`` must be
    installed on both your local and remote systems in order for this operation
    to work correctly.

    This function makes use of Fabric's ``local()`` operation, and returns the
    output of that function call; thus it will return the stdout, if any, of
    the resultant ``rsync`` call.

    ``rsync_project()`` uses the current Fabric connection parameters (user,
    host, port) by default, adding them to rsync's ssh options (then mixing in
    ``ssh_opts``, if given -- see below.)

    ``rsync_project()`` takes the following parameters:

    * ``remote_dir``: the only required parameter, this is the path to the
      directory on the remote server. Due to how ``rsync`` is implemented, the
      exact behavior depends on the value of ``local_dir``:

        * If ``local_dir`` ends with a trailing slash, the files will be
          dropped inside of ``remote_dir``. E.g.
          ``rsync_project("/home/username/project/", "foldername/")`` will drop
          the contents of ``foldername`` inside of ``/home/username/project``.
        * If ``local_dir`` does **not** end with a trailing slash (and this
          includes the default scenario, when ``local_dir`` is not specified),
          ``remote_dir`` is effectively the "parent" directory, and a new
          directory named after ``local_dir`` will be created inside of it. So
          ``rsync_project("/home/username", "foldername")`` would create a new
          directory ``/home/username/foldername`` (if needed) and place the
          files there.

    * ``local_dir``: by default, ``rsync_project`` uses your current working
      directory as the source directory. This may be overridden by specifying
      ``local_dir``, which is a string passed verbatim to ``rsync``, and thus
      may be a single directory (``"my_directory"``) or multiple directories
      (``"dir1 dir2"``). See the ``rsync`` documentation for details.
    * ``exclude``: optional, may be a single string, or an iterable of strings,
      and is used to pass one or more ``--exclude`` options to ``rsync``.
    * ``delete``: a boolean controlling whether ``rsync``'s ``--delete`` option
      is used. If True, instructs ``rsync`` to remove remote files that no
      longer exist locally. Defaults to False.
    * ``extra_opts``: an optional, arbitrary string which you may use to pass
      custom arguments or options to ``rsync``.
    * ``ssh_opts``: Like ``extra_opts`` but specifically for the SSH options
      string (rsync's ``--rsh`` flag.)
    * ``capture``: Sent directly into an inner `~fabric.operations.local` call.
    * ``upload``: a boolean controlling whether file synchronization is
      performed up or downstream. Upstream by default.
    * ``default_opts``: the default rsync options ``-pthrvz``, override if
      desired (e.g. to remove verbosity, etc).

    Furthermore, this function transparently honors Fabric's port and SSH key
    settings. Calling this function when the current host string contains a
    nonstandard port, or when ``env.key_filename`` is non-empty, will use the
    specified port and/or SSH key filename(s).

    For reference, the approximate ``rsync`` command-line call that is
    constructed by this function is the following::

        rsync [--delete] [--exclude exclude[0][, --exclude[1][, ...]]] \
            [default_opts] [extra_opts] <local_dir> <host_string>:<remote_dir>

    .. versionadded:: 1.4.0
        The ``ssh_opts`` keyword argument.
    .. versionadded:: 1.4.1
        The ``capture`` keyword argument.
    .. versionadded:: 1.8.0
        The ``default_opts`` keyword argument.
    t   __iter__s    --exclude "%s"t   "s   \\"R   s   -i s    -i s   -p %ss0   -A -o "ProxyCommand=ssh %s -p %s %s@%s nc %s %s"s   --rsh='ssh %s't    s   --deletet   deletet   excludet   rsht   defaultt   extras3   %(delete)s%(exclude)s %(default)s %(extra)s %(rsh)ss   ../iÿÿÿÿt   :i   s   [%s@%s]s   %s@%ss   rsync %s %s %s:%ss   rsync %s %s:%s %ss   [%s] rsync_project: %st   captureN(   t   hasattrt   lent   tuplet   strt   replaceR   t   joinR   R   t   host_stringt   gatewayt   Nonet   anyR   t   splitR   t   countR   t   runningR   (   t
   remote_dirt	   local_dirR   R   t
   extra_optst   ssh_optsR   t   uploadt   default_optst   exclude_optst   st
   exclusionst
   key_stringt   keyst   usert   hostt   portt   port_stringt
   rsh_stringt   gateway_optst   gw_usert   gw_hostt   gw_portt   gw_strt	   rsh_partst   options_mapt   optionst   remote_prefixt   cmd(    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/contrib/project.pyR      sL    Z1	
	

	c   
   
   C€  s  | r t  p t } |  p! t j ƒ  }  |  j t j ƒ }  t j j |  ƒ \ } } d | } t j j | | ƒ } t	 ƒ  } zz t j j | | ƒ }	 t
 d |	 | | f ƒ t |	 | d | ƒt | ƒ ) z | d | ƒ Wd | d | ƒ XWd QXWd t
 d | ƒ Xd S(   s  
    Upload the current project to a remote system via ``tar``/``gzip``.

    ``local_dir`` specifies the local project directory to upload, and defaults
    to the current working directory.

    ``remote_dir`` specifies the target directory to upload into (meaning that
    a copy of ``local_dir`` will appear as a subdirectory of ``remote_dir``)
    and defaults to the remote user's home directory.

    ``use_sudo`` specifies which method should be used when executing commands
    remotely. ``sudo`` will be used if use_sudo is True, otherwise ``run`` will
    be used.

    This function makes use of the ``tar`` and ``gzip`` programs/libraries,
    thus it will not work too well on Win32 systems unless one is using Cygwin
    or something similar. It will attempt to clean up the local and remote
    tarfiles when it finishes executing, even in the event of a failure.

    .. versionchanged:: 1.1
        Added the ``local_dir`` and ``remote_dir`` kwargs.

    .. versionchanged:: 1.7
        Added the ``use_sudo`` kwarg.
    s	   %s.tar.gzs   tar -czf %s -C %s %st   use_sudos   tar -xzf %sNs   rm -f %ss	   rm -rf %s(   R
   R	   t   osR   t   rstripR   t   pathR&   R!   R   R   R   R   (
   R*   R)   RC   t   runnert
   local_patht
   local_namet   tar_filet
   target_tart
   tmp_foldert   tar_path(    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/contrib/project.pyR   ¥   s     
	(    (   t   __doc__t
   __future__R    RD   R   R   t   os.pathR   t   tempfileR   t   fabric.networkR   R   R   t   fabric.operationsR   R	   R
   R   t   fabric.stateR   R   t   fabric.context_managersR   t   __all__R$   t   Falset   TrueR   R   (    (    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/contrib/project.pyt   <module>   s(   "‰