File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/rsync.cpython-310.pyc
Back
o ;j� � @ s� d Z ddlZddlZddlZddlZddlZddlZddlm Z m Z e�e�Z dZdd� Zdd� Z ddd�Zdd � Zddd�ZdS )z� Wrapper for rsync .. versionadded:: 2014.1.0 This data can also be passed into :ref:`pillar <pillar-walk-through>`. Options passed into opts will overwrite options passed into pillar. � N)�CommandExecutionError�SaltInvocationError�rsyncc C s t jj�d�r tS dS )z5 Only load module if rsync binary is present r )FzQThe rsync execution module cannot be loaded: the rsync binary is not in the path.)�salt�utils�path�which�__virtualname__� r r �F/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/rsync.py�__virtual__ s r c C s� dg}| r |� d� |r|� d� |r|� d� |r"|� d|� �� |r+|�d|g� |r8|�d|g� |r8d}|rSt|t�rL|D ] } |�d | g� qAn|�d |g� |rZ|� d � |S )z Generate rsync options z-avzz--deletez--forcez--updatez--rsh=z--password-filez--exclude-fromFz --excludez --dry-run)�append�extend� isinstance�list) �delete�force�update�passwordfile�exclude�excludefrom�dryrun�rsh�optionsZex_r r r �_check% s0 � r F�basec C s | st d d�} |st d d�}|st d d�}|s t d d�}|s(t d d�}|s0t d d�}|s8t d d�}|s@t d d �}|sHt d d �}| sPt d d�} | rT|sXtd��d }| �d�r�| } t�dd| �}d}|t d |d�v rud}|r�t�� }t d | ||�}|r�|} | �d�s�| � d�} n!t| � d���t j j�� }t d | ||�}|r�|} nt| � d���t |||||||| �}| r�t| t�r�|| }dg| | |g }t�d|� z%zt d |dd�W W |r�t d |� S S ty� } zt|j��d }~ww |�rt d |� w w )a .. versionchanged:: 2016.3.0 Return data now contains just the output of the rsync command, instead of a dictionary as returned from :py:func:`cmd.run_all <salt.modules.cmdmod.run_all>`. Rsync files from src to dst src The source location where files will be rsynced from. dst The destination location where files will be rsynced to. delete : False Whether to enable the rsync `--delete` flag, which will delete extraneous files from dest dirs force : False Whether to enable the rsync `--force` flag, which will force deletion of dirs even if not empty. update : False Whether to enable the rsync `--update` flag, which forces rsync to skip any files which exist on the destination and have a modified time that is newer than the source file. passwordfile A file that contains a password for accessing an rsync daemon. The file should contain just the password. exclude Whether to enable the rsync `--exclude` flag, which will exclude files matching a PATTERN. excludefrom Whether to enable the rsync `--excludefrom` flag, which will read exclude patterns from a file. dryrun : False Whether to enable the rsync `--dry-run` flag, which will perform a trial run with no changes made. rsh Whether to enable the rsync `--rsh` flag, to specify the remote shell to use. additional_opts Any additional rsync options, should be specified as a list. saltenv Specify a salt fileserver environment to be used. CLI Example: .. code-block:: bash salt '*' rsync.rsync /path/to/src /path/to/dest delete=True update=True passwordfile=/etc/pass.crt exclude=exclude/dir salt '*' rsync.rsync /path/to/src delete=True excludefrom=/xx.ini salt '*' rsync.rsync /path/to/src delete=True exclude='[exclude1/dir,exclude2/dir]' additional_opts='["--partial", "--bwlimit=5000"]' z config.optionz rsync.srcz rsync.dstzrsync.deletezrsync.forcezrsync.updatezrsync.passwordfilez rsync.excludezrsync.excludefromzrsync.dryrunz rsync.rshzsrc and dst cannot be emptyNzsalt://� Fzcp.list_master_dirs)�saltenvTz cp.get_dir�/� does not existzcp.get_filer zRunning rsync command: %szcmd.run_all�Zpython_shellzfile.remove)�__salt__r � startswith�re�sub�tempfileZmkdtemp�endswithr r r �filesZmkstempr r r �log�debug�OSError�strerror)�src�dstr r r r r r r r Zadditional_optsr Ztmp_srcZ_src�_pathZ src_is_dirZdir_srcZfile_src�option�cmd�excr r r r D s| M ���� ���c C sl zt d ddgdd�} W n ty } zt|j��d}~ww z| �d�d �� d W S ty5 td ��w )aB .. versionchanged:: 2016.3.0 Return data now contains just the version number as a string, instead of a dictionary as returned from :py:func:`cmd.run_all <salt.modules.cmdmod.run_all>`. Returns rsync version CLI Example: .. code-block:: bash salt '*' rsync.version zcmd.run_stdoutr z --versionFr N� r � z!Unable to determine rsync version)r! r* r r+ �split� IndexError)�outr1 r r r �version� s ���r7 �/etc/rsyncd.confc C s� d}z+t jj�| d��}|D ]}|t jj�|�7 }qW d � W |S 1 s&w Y W |S tyn } z5|jtjkrBt | � d���|jtj krPt d| � d���|jtjkr^t d| � d���t d|j� d |j� ���d}~ww ) a� .. versionchanged:: 2016.3.0 Return data now contains just the contents of the rsyncd.conf as a string, instead of a dictionary as returned from :py:func:`cmd.run_all <salt.modules.cmdmod.run_all>`. Returns the contents of the rsync config file conf_path : /etc/rsyncd.conf Path to the config file CLI Example: .. code-block:: bash salt '*' rsync.config r �rNr zUnable to read z, access deniedz, path is a directoryzError z: ) r r r'