%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/file.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZmZddlmZddlmZddlm Z m!Z!ddl"m#Z$yddl%Z%ddl&Z&Wne'k
r�nXddl(Z)ddl*Z)ddl+Z)ddl,Z)ddl-Z)ddl.Z)ddl/Z)ddl0Z)ddl1Z)ddl2Z)ddl3Z)ddl4Z)ddl5Z)ddl6Z)ddl7Z)ddl+Z)ddl8Z)dd	l9m:Z:m;Z;m<Z<m=Z>dd
l-m?Z?m@Z@e
jAeB�ZCidd6ZDed
d�ZEd�ZFd�ZGd�ZHd�ZId�ZJd�ZKd�ZLd�ZMd�ZNd�ZOePd�ZQePd�ZRd�ZSd�ZTePd�ZUePd�ZVePd�ZWd �ZXd!�ZYd"�ZZd#�Z[d$�Z\d%�Z]d&�Z^d'd(�Z_d'd)d*�Z`d+d+eaead,d-�Zbd.�Zcd/�Zdeed0�Zfd+d1d2d3eeeed4�Zgd+d3d5�Zhd+d1d6eeeed7�Ziie
jjd86e
jkd96e
jld:6e
jmd;6e
jnd<6e
jod=6Zpd>�Zqd?d1d@�Zrd?d1dA�Zsd?ePd1dB�ZtdC�ZudD�ZvePdE�ZwePdF�ZxdG�ZydHdI�ZzdJ�Z{dK�Z|dL�Z}dM�Z~dN�ZeaeaeaeaeaeaePeeeeePdO�
Z�ddPdHeeeeead1eeeeePeeePeedQ�
Z�dRdSd+eeeed1eeePeedT�	Z�dPdHeeeedU�Z�d+eedV�Z�dW�Z�d+dX�Z�dY�Z�dZ�Z�d[�Z�d\�Z�eaead]�Z�d^�Z�d_�Z�d`�Z�da�Z�db�Z�dc�Z�dd�Z�eeeede�Z�df�Z�dg�Z�eedh�Z�eedi�Z�dj�Z�dk�Z�eaePdl�Z�dm�Z�dn�Z�do�Z�dp�Z�dq�Z�eedr�Z�ds�Z�eaeaeaeadt�Z�du�Z�dv�Z�eedw�Z�d'd+d+eadx�Z�eaeedy�Z�eaeedz�Z�eaeeeed{�Z�ead|�Z�d,ePePeeeaead}�Z�eeeaePeaeaePeeeeead~d�
Z�eaeaead��Z�eaeaead��Z�eaead�d��Z�d��Z�d��Z�eaead�d��Z�d��Z�eaead�d��Z�d��Z�eaead�d��Z�ddeaead�d��Z�ead��Z�e)j�jj�e�d��Z�ead��Z�d��Z�d��Z�e)j�jj�e�d��Z�d��Z�eed��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�dS(�u|
Manage information about regular files, directories,
and special files on the minion, set/read user,
group, mode, and data
i(tabsolute_importtprint_functiontunicode_literalsN(tIterabletMappingt
namedtuple(treduce(tsix(trangetzip(turlparse(tCommandExecutionErrortMinionErrortSaltInvocationErrortget_error_message(tHASHESt
HASHES_REVMAPumakedirsu	makedirs_uAttrChangesu
added,removedcC@s tjjj�rtdfStS(u)
    Only work on POSIX-like systems
    uiThe file execution module cannot be loaded: only available on non-Windows systems - use win_file instead.(tsalttutilstplatformt
is_windowstFalsetTrue(((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt__virtual__Nsc@s��jtjjtj�tjjj	��r�t
jjt
jtd��}t�fd�|D��}tjj��r�|r�tj��q�ndS(u(
    Clean out a template temp file
    u
file_rootsc3@s|]}�j|�VqdS(N(t
startswith(t.0troot(tsfn(s5/usr/lib/python2.7/site-packages/salt/modules/file.pys	<genexpr>esN(Rtostpathtjointtempfilet
gettempdirRRtfilestTEMPFILE_PREFIXt	itertoolstchaint
from_iterableRt
itervaluest__opts__tanytexiststremove(Rt	all_rootstin_roots((Rs5/usr/lib/python2.7/site-packages/salt/modules/file.pyt__clean_tmp\s	cC@st|d<||d<|S(uH
    Common function for setting error information for return dicts
    uresultucomment(R(tretterr_msg((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_errorks

cC@setd|�}td|�}t||f�rat||f�rJdS|rTdS|radSndS(uc
    This function does NOT do any diffing, it just checks the old and new files
    to see if either is binary, and provides an appropriate string noting the
    difference between the two files. If neither file is binary, an empty
    string is returned.

    This function should only be run AFTER it has been determined that the
    files differ.
    u
files.is_textuReplace binary fileu"Replace binary file with text fileu"Replace text file with binary fileu(t	__utils__R(tall(toldtnewt	old_isbint	new_isbin((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_binary_replacets
cC@stjjtdd�d�S(u@
    Get the location of the backup dir in the minion cache
    u
config.getucachedirufile_backup(RRRt__salt__(((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_get_bkroot�scC@s>|j�}|jd�s*|jd�r:|jd�n|S(u�
    Returns a list of the lines in the string, breaking at line boundaries and
    preserving a trailing newline (if present).

    Essentially, this works like ``str.striplines(False)`` but preserves an
    empty line at the end. This is equivalent to the following code:

    .. code-block:: python

        lines = str.splitlines()
        if str.endswith('
') or str.endswith('
'):
            lines.append('')
    u
u
u(t
splitlinestendswithtappend(tstrtlines((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt'_splitlines_preserving_trailing_newline�scC@s�tjjjd�}|s.tjjj�r2dS|g}td|dtdt	�}t
jdtjjj
|��}|dkr�d}n|jd�}|S(u0
    Return the version of chattr installed
    utune2fsucmd.runtignore_retcodetpython_shellutune2fs (?P<version>[0-9\.]+)uversionN(RRRtwhichRtis_aixtNoneR8RRtretsearchtstringutilstto_strtgroup(ttune2fstcmdtresulttmatchtversion((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_chattr_version�s		cC@sMt�}|dkrtStjjjd�}tjjj|�}||kS(u|
    Return ``True`` if chattr supports extended attributes, that is,
    the version is >1.41.22. Otherwise, ``False``
    u1.41.12N(RORDRRRtversionstLooseVersion(tvertneeded_versiontchattr_version((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_chattr_has_extended_attrs�s	cC@ssyt|�}Wntk
r/t|�}nX|dkr@dSytj|�jSWnttfk
rn|SXdS(u�
    Convert the group id to the group name on this system

    gid
        gid to convert to a group name

    CLI Example:

    .. code-block:: bash

        salt '*' file.gid_to_group 0
    uN(tintt
ValueErrortgroup_to_gidtgrptgetgrgidtgr_nametKeyErrort	NameError(tgid((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytgid_to_group�s

cC@sP|dkrdSy't|t�r&|Stj|�jSWntk
rKdSXdS(u�
    Convert the group to the gid on this system

    group
        group to convert to its gid

    CLI Example:

    .. code-block:: bash

        salt '*' file.group_to_gid root
    uN(RDt
isinstanceRVRYtgetgrnamtgr_gidR\(RI((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyRX�s

cC@s(ttjj|�d|�jdd�S(u^
    Return the id of the group that owns a given file

    path
        file or directory of which to get the gid

    follow_symlinks
        indicated if symlinks should be followed


    CLI Example:

    .. code-block:: bash

        salt '*' file.get_gid /etc/passwd

    .. versionchanged:: 0.16.4
        ``follow_symlinks`` option added
    tfollow_symlinksugidi����(tstatsRRt
expandusertget(RRc((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytget_gidscC@s(ttjj|�d|�jdt�S(uW
    Return the group that owns a given file

    path
        file or directory of which to get the group

    follow_symlinks
        indicated if symlinks should be followed

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_group /etc/passwd

    .. versionchanged:: 0.16.4
        ``follow_symlinks`` option added
    Rcugroup(RdRRReRfR(RRc((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt	get_groupscC@s3ytj|�jSWnttfk
r.|SXdS(u�
    Convert a uid to a user name

    uid
        uid to convert to a username

    CLI Example:

    .. code-block:: bash

        salt '*' file.uid_to_user 0
    N(tpwdtgetpwuidtpw_nameR\R](tuid((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytuid_to_user5s
cC@sa|dkr!tjjj�}ny't|t�r7|Stj|�j	SWnt
k
r\dSXdS(u�
    Convert user name to a uid

    user
        user name to convert to its uid

    CLI Example:

    .. code-block:: bash

        salt '*' file.user_to_uid root
    uN(RDRRtusertget_userR`RVRitgetpwnamtpw_uidR\(Rn((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytuser_to_uidIs

cC@s(ttjj|�d|�jdd�S(u\
    Return the id of the user that owns a given file

    path
        file or directory of which to get the uid

    follow_symlinks
        indicated if symlinks should be followed

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_uid /etc/passwd

    .. versionchanged:: 0.16.4
        ``follow_symlinks`` option added
    Rcuuidi����(RdRRReRf(RRc((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytget_uid`scC@s(ttjj|�d|�jdt�S(uT
    Return the user that owns a given file

    path
        file or directory of which to get the user

    follow_symlinks
        indicated if symlinks should be followed

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_user /etc/passwd

    .. versionchanged:: 0.16.4
        ``follow_symlinks`` option added
    Rcuuser(RdRRReRfR(RRc((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyRovscC@s(ttjj|�d|�jdd�S(uI
    Return the mode of a file

    path
        file or directory of which to get the mode

    follow_symlinks
        indicated if symlinks should be followed

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_mode /etc/passwd

    .. versionchanged:: 2014.1.0
        ``follow_symlinks`` option added
    Rcumodeu(RdRRReRf(RRc((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytget_mode�scC@s�tjj|�}tj|�jd�}|s9d}ntjj|�sctdj|���nytj	|t
|d��Wntk
r�d|SXt|�S(u�
    Set the mode of a file

    path
        file or directory of which to set the mode

    mode
        mode to set the path to

    CLI Example:

    .. code-block:: bash

        salt '*' file.set_mode /etc/passwd 0644
    u0Oou0u{0}: File not foundiu
Invalid Mode (
RRReRt	text_typetlstripR)RtformattchmodRVt	ExceptionRt(Rtmode((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytset_mode�s	
	cC@s�tjj|�}t|�}t|�}d}|dkrX|rO|d7}qXd}n|dkr�|rw|d7}q�d}ntj|||�S(u+
    Chown a file, pass the file the desired user and group without following
    symlinks.

    path
        path to the file or directory

    user
        user owner

    group
        group owner

    CLI Example:

    .. code-block:: bash

        salt '*' file.chown /etc/passwd root root
    uuUser does not exist
i����uGroup does not exist
(RRReRrRXtlchown(RRnRIRlR^terr((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR|�s
	
	cC@s�tjj|�}t|�}t|�}d}|dkrX|rO|d7}qXd}n|dkr�|rw|d7}q�d}ntjj|�s�ytj|||�SWntk
r�nX|d7}n|r�|Stj|||�S(u
    Chown a file, pass the file the desired user and group

    path
        path to the file or directory

    user
        user owner

    group
        group owner

    CLI Example:

    .. code-block:: bash

        salt '*' file.chown /etc/passwd root root
    uuUser does not exist
i����uGroup does not exist
uFile not found(	RRReRrRXR)R|tOSErrortchown(RRnRIRlR^R}((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�s*
	
	

cC@s.tjj|�}t|�}t|||�S(u�
    Change the group of a file

    path
        path to the file or directory

    group
        group owner

    CLI Example:

    .. code-block:: bash

        salt '*' file.chgrp /etc/passwd root
    (RRReRoR(RRIRn((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytchgrpscC@s�tjjj�rdSyt|�j|d�}Wntk
rFdSXt|�}t|�}t	ddj
||�p{dddj
||�p�d�S(u�
    .. versionadded:: 2018.3.0

    Compare attributes of a given file to given attributes.
    Returns a pair (list) where first item are attributes to
    add and second item are to be removed.

    Please take into account when using this function that some minions will
    not have lsattr installed.

    path
        path to file to compare attributes with.

    attrs
        string of attributes to compare against a given file
    utaddedtremovedN(RRRRCRDtlsattrRftAttributeErrortsettAttrChangesR(RtattrstlattrsR4R3((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt
_cmp_attrs+s
cC@s�tjjjd�s(tjjj�r,d
Stjj|�sMt	d��nd|g}t
d|dtdt�}i}xl|j
�D]^}|jd�s�|jd
d�\}}t�r�d}nd	}tj||�||<q�q�W|S(uV
    .. versionadded:: 2018.3.0
    .. versionchanged:: 2018.3.1
        If ``lsattr`` is not installed on the system, ``None`` is returned.
    .. versionchanged:: 2018.3.4
        If on ``AIX``, ``None`` is returned even if in filesystem as lsattr on ``AIX``
        is not the same thing as the linux version.

    Obtain the modifiable attributes of the given file. If path
    is to a directory, an empty list is returned.

    path
        path to file to obtain attributes of. File/directory must exist.

    CLI Example:

    .. code-block:: bash

        salt '*' file.lsattr foo1.txt
    ulsattru!File or directory does not exist.ucmd.runR@RAulsattr: iu[aAcCdDeijPsStTu]u[acdijstuADST]N(RRRRBRRCRDRR)R
R8RRR:RtsplitRUREtfindall(RRKRLtresultstlineR�tfiletpattern((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�Os(		c	O@sZ|jdd�}|jdd�}|jdd�}|jdd�}|dks`|dkrotd��n|dkr�td��nd	g}|dkr�d
j|�}n|dkr�dj|�}n|j|�|dk	r|jdj|��n|dk	r#|jd|g�n|j|�td
|dt�}t|�rVtSt	S(uI
    .. versionadded:: 2018.3.0

    Change the attributes of files. This function accepts one or more files and
    the following options:

    operator
        Can be wither ``add`` or ``remove``. Determines whether attributes
        should be added or removed from files

    attributes
        One or more of the following characters: ``aAcCdDeijPsStTu``,
        representing attributes to add to/remove from files

    version
        a version number to assign to the file(s)

    flags
        One or more of the following characters: ``RVf``, representing
        flags to assign to chattr (recurse, verbose, suppress most errors)

    CLI Example:

    .. code-block:: bash

        salt '*' file.chattr foo1.txt foo2.txt operator=add attributes=ai
        salt '*' file.chattr foo3.txt operator=remove attributes=i version=2
    uoperatoru
attributesuflagsuversionuadduremoveu9Need an operator: 'add' or 'remove' to modify attributes.u"Need attributes: [aAcCdDeijPsStTu]uchattru+{0}u-{0}u-vucmd.runRAN(uadduremove(
tpopRDR
RwR<textendR8RtboolR(	R!tkwargstoperatort
attributestflagsRNRKR�RL((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytchattrzs0	

usha256cC@sAtjj|�}tjj|�s(dStjjj||d�S(uq
    Return the checksum for the given file. The following checksum algorithms
    are supported:

    * md5
    * sha1
    * sha224
    * sha256 **(default)**
    * sha384
    * sha512

    path
        path to the file or directory

    form
        desired sum format

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_sum /etc/passwd sha512
    uFile not foundi(RRRetisfileRRt	hashutilstget_hash(Rtform((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytget_sum�sicC@s%tjjjtjj|�||�S(uT
    Get the hash sum of a file

    This is better than ``get_sum`` for the following reasons:
        - It does not read the entire file into memory.
        - It does not return a string on error. The returned value of
            ``get_sum`` cannot really be trusted since it is vulnerable to
            collisions: ``get_sum(..., 'xyz') == 'Hash xyz not supported'``

    path
        path to the file or directory

    form
        desired sum format

    chunk_size
        amount to sum at once

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_hash /etc/shadow
    (RRR�R�RRRe(RR�t
chunk_size((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR��suubasec@s��fd�}d
}tjj��r0�}n�yrt��j}|tjjj	kr�t
d�|�}|s�tdj����q�n|dkr�|�nWnt
tfk
r�|�nX|d
k	rt|d|||�}|d
kr�|�n|dj�|d<|Si}y=g�jdd�D]}	|	j�^q1\|d<|d<Wn�t
k
rr|�nstk
r�tjd	jtj���s�|�n�|d<t��}
|
tkr�t|
|d<q�|�nX|dtkr$td
j|ddjt�|d���ngt|d�}|tkrJ|�nA|t|dkr�tdj||d|dt|���n|dj�|d<|Sd
S(uV
    .. versionadded:: 2016.11.0

    Used by :py:func:`file.get_managed <salt.modules.file.get_managed>` to
    obtain the hash and hash type from the parameters specified below.

    file_name
        Optional file name being managed, for matching with
        :py:func:`file.extract_hash <salt.modules.file.extract_hash>`.

    source
        Source file, as used in :py:mod:`file <salt.states.file>` and other
        states. If ``source_hash`` refers to a file containing hashes, then
        this filename will be used to match a filename in that file. If the
        ``source_hash`` is a hash expression, then this argument will be
        ignored.

    source_hash
        Hash file/expression, as used in :py:mod:`file <salt.states.file>` and
        other states. If this value refers to a remote URL or absolute path to
        a local file, it will be cached and :py:func:`file.extract_hash
        <salt.modules.file.extract_hash>` will be used to obtain a hash from
        it.

    source_hash_name
        Specific file name to look for when ``source_hash`` refers to a remote
        file, used to disambiguate ambiguous matches.

    saltenv : base
        Salt fileserver environment from which to retrieve the source_hash. This
        value will only be used when ``source_hash`` refers to a file on the
        Salt fileserver (i.e. one beginning with ``salt://``).

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_source_sum /tmp/foo.tar.gz source=http://mydomain.tld/foo.tar.gz source_hash=499ae16dcae71eeb7c3a30c75ea7a1a6
        salt '*' file.get_source_sum /tmp/foo.tar.gz source=http://mydomain.tld/foo.tar.gz source_hash=https://mydomain.tld/hashes.md5
        salt '*' file.get_source_sum /tmp/foo.tar.gz source=http://mydomain.tld/foo.tar.gz source_hash=https://mydomain.tld/hashes.md5 source_hash_name=./dir2/foo.tar.gz
    c
@sctdj�djtjjj�djgtt�D]}djt||�^q4����dS(uD
        DRY helper for reporting invalid source_hash input
        ukSource hash {0} format is invalid. The supported formats are: 1) a hash, 2) an expression in the format <hash_type>=<hash>, or 3) either a path to a local file containing hashes, or a URI of a remote hash file. Supported protocols for remote hash files are: {1}. The hash may also not be of a valid length, the following are supported hash types and lengths: {2}.u, u	{0} ({1})N(	RRwRRRR!tVALID_PROTOStsortedR(tx(tsource_hash(s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_invalid_source_hash_format$su
cp.cache_fileuSource hash file {0} not founduuhsumu=iu	hash_typeu^[{0}]+$u�Invalid hash type '{0}'. Supported hash types are: {1}. Either remove the hash type and simply use '{2}' as the source_hash, or change the hash type to a supported type.u, u�Invalid length ({0}) for hash type '{1}'. Either remove the hash type and simply use '{2}' as the source_hash, or change the hash type to '{3}'N(RDRRtisabst	_urlparsetschemeRRR!R�R8RRwR�t	TypeErrortextract_hashtlowerR�tstripRWRERMtstringt	hexdigitstlenRRR(t	file_nametsourceR�tsource_hash_nametsaltenvR�thash_fntprotoR.R�tsource_hash_lenthsum_len((R�s5/usr/lib/python2.7/site-packages/salt/modules/file.pytget_source_sum�sd.	
=




&
c
C@s�tjj|�}t|tj�s3td��nx�dD].}||kr:|j|d�\}}Pq:q:W|}t|�}t	j
|�}|d	kr�tdj||dj
gtt	�D]}djt	||�^q�����nt||�|kS(
uI
    Check if a file matches the given hash string

    Returns ``True`` if the hash matches, otherwise ``False``.

    path
        Path to a file local to the minion.

    hash
        The hash to check against the file specified in the ``path`` argument.

        .. versionchanged:: 2016.11.4

        For this and newer versions the hash can be specified without an
        accompanying hash type (e.g. ``e138491e9d5b97023cea823fe17bac22``),
        but for earlier releases it is necessary to also specify the hash type
        in the format ``<hash_type>=<hash_value>`` (e.g.
        ``md5=e138491e9d5b97023cea823fe17bac22``).

    CLI Example:

    .. code-block:: bash

        salt '*' file.check_hash /etc/fstab e138491e9d5b97023cea823fe17bac22
        salt '*' file.check_hash /etc/fstab md5=e138491e9d5b97023cea823fe17bac22
    uhash must be a stringu:u=iusHash {0} (length: {1}) could not be matched to a supported hash type. The supported hash types and lengths are: {2}u, u	{0} ({1})(u:u=N(RRReR`Rtstring_typesR
R�R�RRfRDRwRR�R�(Rt	file_hashtsept	hash_typet
hash_valuethash_lenR�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt
check_hash�s&
8c	O@s�d|krd|d<nd|kr2d|d<nytjjj|�}Wntk
rj}dj|�SXggtjtjj	|��D]}|j|�^q�D]}|D]}|^q�q�}|j
�|S(u�
    Approximate the Unix ``find(1)`` command and return a list of paths that
    meet the specified criteria.

    The options include match criteria:

    .. code-block:: text

        name    = path-glob                 # case sensitive
        iname   = path-glob                 # case insensitive
        regex   = path-regex                # case sensitive
        iregex  = path-regex                # case insensitive
        type    = file-types                # match any listed type
        user    = users                     # match any listed user
        group   = groups                    # match any listed group
        size    = [+-]number[size-unit]     # default unit = byte
        mtime   = interval                  # modified since date
        grep    = regex                     # search file contents

    and/or actions:

    .. code-block:: text

        delete [= file-types]               # default type = 'f'
        exec    = command [arg ...]         # where {} is replaced by pathname
        print  [= print-opts]

    and/or depth criteria:

    .. code-block:: text

        maxdepth = maximum depth to transverse in path
        mindepth = minimum depth to transverse before checking files or directories

    The default action is ``print=path``

    ``path-glob``:

    .. code-block:: text

        *                = match zero or more chars
        ?                = match any char
        [abc]            = match a, b, or c
        [!abc] or [^abc] = match anything except a, b, and c
        [x-y]            = match chars x through y
        [!x-y] or [^x-y] = match anything except chars x through y
        {a,b,c}          = match a or b or c

    ``path-regex``: a Python Regex (regular expression) pattern to match pathnames

    ``file-types``: a string of one or more of the following:

    .. code-block:: text

        a: all file types
        b: block device
        c: character device
        d: directory
        p: FIFO (named pipe)
        f: plain file
        l: symlink
        s: socket

    ``users``: a space and/or comma separated list of user names and/or uids

    ``groups``: a space and/or comma separated list of group names and/or gids

    ``size-unit``:

    .. code-block:: text

        b: bytes
        k: kilobytes
        m: megabytes
        g: gigabytes
        t: terabytes

    interval:

    .. code-block:: text

        [<num>w] [<num>d] [<num>h] [<num>m] [<num>s]

        where:
            w: week
            d: day
            h: hour
            m: minute
            s: second

    print-opts: a comma and/or space separated list of one or more of the
    following:

    .. code-block:: text

        group: group name
        md5:   MD5 digest of file contents
        mode:  file permissions (as integer)
        mtime: last modification time (as time_t)
        name:  file basename
        path:  file absolute path
        size:  file size in bytes
        type:  file type
        user:  user name

    CLI Examples:

    .. code-block:: bash

        salt '*' file.find / type=f name=\*.bak size=+10m
        salt '*' file.find /var mtime=+30d size=+10m print=path,size,mtime
        salt '*' file.find /var/log name=\*.[0-9] mtime=+30d size=+10m delete
    udeleteufuprintupathu
error: {0}(RRtfindtFinderRWRwtglobRRRetsort(	RtargsR�tfindertextptititemR.((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR��sr

W
cC@s^d}|jdd�jdd�}|tkrZx'|D]}|j|d|�}q7Wn|S(u2
    Escape single quotes and forward slashes
    u^.[$()|*+?{u'u'"'"'u/u\/u\(treplaceR(R�t
escape_allt
special_charstchar((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_sed_esc=s
u.baku-r -eugc	
C@sQtjj|�}tjj|�s(tStj|�}tj|�}t||�}t||�}t||�}tj	dkr�|j
dd�}ndg}	|	j|r�dj|�nd�|	j
tjjj|��|	jdjd|rd	j|�nd
d|rdnd
d
|d|d|��|	j|�td|	dt�S(u�
    .. deprecated:: 0.17.0
       Use :py:func:`~salt.modules.file.replace` instead.

    Make a simple edit to a file

    Equivalent to:

    .. code-block:: bash

        sed <backup> <options> "/<limit>/ s/<before>/<after>/<flags> <file>"

    path
        The full path to the file to be edited
    before
        A pattern to find in order to replace with ``after``
    after
        Text that will replace ``before``
    limit : ``''``
        An initial pattern to search for before searching for ``before``
    backup : ``.bak``
        The file will be backed up before edit with this file extension;
        **WARNING:** each time ``sed``/``comment``/``uncomment`` is called will
        overwrite this backup
    options : ``-r -e``
        Options to pass to sed
    flags : ``g``
        Flags to modify the sed search; e.g., ``i`` for case-insensitive pattern
        matching
    negate_match : False
        Negate the search command (``!``)

        .. versionadded:: 0.17.0

    Forward slashes and single quotes will be escaped automatically in the
    ``before`` and ``after`` patterns.

    CLI Example:

    .. code-block:: bash

        salt '*' file.sed /etc/httpd/httpd.conf 'LogLevel warn' 'LogLevel info'
    udarwinu-ru-Eusedu-i{0}u-iu/{limit}{negate_match}s/{before}/{after}/{flags}tlimitu/{0}/ utnegate_matchu!tbeforetafterR�ucmd.run_allRA(RRReR)RRRuR�tsysRR�R<RwR�RRR�tshlex_splitR8(
RR�R�R�tbackuptoptionsR�R�R�RK((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytsedIs,7	"	

c	C@stjj|�}tjj|�s(tSttj|�t�}ttj|�t�}d}tj	dkr�|j
dd�}ndg}|jtj
jj|��|jdjd|r�dj|�nd	d
|ddj|���|j|�td
|dt�}t|�S(uh
    .. deprecated:: 0.17.0
       Use :func:`search` instead.

    Return True if the file at ``path`` contains ``text``. Utilizes sed to
    perform the search (line-wise search).

    Note: the ``p`` flag will be added to any flags you pass in.

    CLI Example:

    .. code-block:: bash

        salt '*' file.contains /etc/crontab 'mymaintenance.sh'
    u-n -r -eudarwinu-ru-Eusedu{limit}s/{before}/$/{flags}R�u/{0}/ uR�R�up{0}ucmd.runRA(RRReR)RR�RRuR�RR�R�RRR�R�R<RwR8R�(RttextR�R�R�R�RKRL((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytsed_contains�s$		
ugMScC@sntjj|�}t|�}tj|�}tj|�}t||�}t||�}tj|dj	||��t
jjj
|d���}t
jjj
dj	||�d���}	|tkrx�|	j�D]C}
|jt
jjjtt
jjj|
�||||���q�WnC|jt
jjjtt
jjj|	j��||||���WdQXWdQXdS(u�
    .. deprecated:: 0.17.0
       Use :py:func:`~salt.modules.file.replace` instead.

    Make a simple edit to a file (pure Python version)

    Equivalent to:

    .. code-block:: bash

        sed <backup> <options> "/<limit>/ s/<before>/<after>/<flags> <file>"

    path
        The full path to the file to be edited
    before
        A pattern to find in order to replace with ``after``
    after
        Text that will replace ``before``
    limit : ``''``
        An initial pattern to search for before searching for ``before``
    backup : ``.bak``
        The file will be backed up before edit with this file extension;
        **WARNING:** each time ``sed``/``comment``/``uncomment`` is called will
        overwrite this backup
    flags : ``gMS``
        Flags to modify the search. Valid values are:
          - ``g``: Replace all occurrences of the pattern, not just the first.
          - ``I``: Ignore case.
          - ``L``: Make ``\w``, ``\W``, ``\b``, ``\B``, ``\s`` and ``\S``
            dependent on the locale.
          - ``M``: Treat multiple lines as a single line.
          - ``S``: Make `.` match all characters, including newlines.
          - ``U``: Make ``\w``, ``\W``, ``\b``, ``\B``, ``\d``, ``\D``,
            ``\s`` and ``\S`` dependent on Unicode.
          - ``X``: Verbose (whitespace is ignored).
    multi: ``False``
        If True, treat the entire file as a single line

    Forward slashes and single quotes will be escaped automatically in the
    ``before`` and ``after`` patterns.

    CLI Example:

    .. code-block:: bash

        salt '*' file.sed /etc/httpd/httpd.conf 'LogLevel warn' 'LogLevel info'
    u{0}{1}uwurN(RRReR�RRuR�tshutiltcopy2RwRRR!tfopenRtreadlinetwriteRGRHt_psedt
to_unicodetread(RR�R�R�R�R�R�tmultitofiletifileR�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytpsed�s6;'uIuLuMuSuUuXc
C@s�|}|r@tj|�}|j|�}dj|d�}nd}d|krmd}|jdd�}nd}x|D]}	|t|	O}qzWtj|d|�}tj|||d|�}|S(uS
    Does the actual work for file.psed, so that single lines can be passed in
    uiugiR�tcount(REtcompileR�RR�t
RE_FLAG_TABLEtsub(
R�R�R�R�R�tatexttcompsR�taflagstflag((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�;s
u#cC@s%td|d|d|dtd|�S(uj
    .. deprecated:: 0.17.0
       Use :py:func:`~salt.modules.file.replace` instead.

    Uncomment specified commented lines in a file

    path
        The full path to the file to be edited
    regex
        A regular expression used to find the lines that are to be uncommented.
        This regex should not include the comment character. A leading ``^``
        character will be stripped for convenience (for easily switching
        between comment() and uncomment()).
    char : ``#``
        The character to remove in order to uncomment a line
    backup : ``.bak``
        The file will be backed up before edit with this file extension;
        **WARNING:** each time ``sed``/``comment``/``uncomment`` is called will
        overwrite this backup

    CLI Example:

    .. code-block:: bash

        salt '*' file.uncomment /etc/hosts.deny 'ALL: PARANOID'
    RtregexR�tcmntR�(tcomment_lineR(RR�R�R�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt	uncommentXs
cC@s%td|d|d|dtd|�S(u�
    .. deprecated:: 0.17.0
       Use :py:func:`~salt.modules.file.replace` instead.

    Comment out specified lines in a file

    path
        The full path to the file to be edited
    regex
        A regular expression used to find the lines that are to be commented;
        this pattern will be wrapped in parenthesis and will move any
        preceding/trailing ``^`` or ``$`` characters outside the parenthesis
        (e.g., the pattern ``^foo$`` will be rewritten as ``^(foo)$``)
    char : ``#``
        The character to be inserted at the beginning of a line in order to
        comment it out
    backup : ``.bak``
        The file will be backed up before edit with this file extension

        .. warning::

            This backup will be overwritten each time ``sed`` / ``comment`` /
            ``uncomment`` is called. Meaning the backup will only be useful
            after the first invocation.

    CLI Example:

    .. code-block:: bash

        salt '*' file.comment /etc/modules pcspkr
    RR�R�R�R�(R�R(RR�R�R�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytcomment}s
#cC@s:|rZdj|jd�r!dnd|jd�jd�|jd�rNdnd�}n<dj||jd�jd�|jd�r�dnd�}tjjtjj|��}tjj	|�s�t
dj|���ntd|�st
dj|���nt}g}g}tjj
|�}y�tjjj|d	d
d|���}	x�|	D]{}
tjjj|
�}
tj||
�rX|j|
�|r�|jdj||
��n|j|
j|��t}qXqXWWd
QXWn1ttfk
r}tdj||���nX|stStjjj�sdt|�}t|�}
tjjjt |��}nyt!d|dt�}Wn.ttfk
r�}tdj|���nXy�t"j#r�tjjj�r�dnd}tjjj|d	|d|��^}y&tjjj|d	d
d|���}	x�|	D]�}
tjjj|
�}
y�tj||
�r�|rudj||
�}q�|
j|�}n|
}t"j#r�tjjj�r�tjjj$|�ntjjj%|�}|j&|�Wq*ttfk
r}tdj|||���q*Xq*WWd
QXWn.ttfk
rR}tdj|���nXWd
QXWn.ttfk
r�}tdj|���nX|r�dj||�}yt'j(||�Wq�ttfk
r�}tdj|||���q�Xn
tj)|�tjjj�s)t*|d
||
|�ntd||�S(u�
    Comment or Uncomment a line in a text file.

    :param path: string
        The full path to the text file.

    :param regex: string
        A regex expression that begins with ``^`` that will find the line you wish
        to comment. Can be as simple as ``^color =``

    :param char: string
        The character used to comment a line in the type of file you're referencing.
        Default is ``#``

    :param cmnt: boolean
        True to comment the line. False to uncomment the line. Default is True.

    :param backup: string
        The file extension to give the backup file. Default is ``.bak``
        Set to False/None to not keep a backup.

    :return: boolean
        Returns True if successful, False if not

    CLI Example:

    The following example will comment out the ``pcspkr`` line in the
    ``/etc/modules`` file using the default ``#`` character and create a backup
    file named ``modules.bak``

    .. code-block:: bash

        salt '*' file.comment_line '/etc/modules' '^pcspkr'


    CLI Example:

    The following example will uncomment the ``log_level`` setting in ``minion``
    config file if it is set to either ``warning``, ``info``, or ``debug`` using
    the ``#`` character and create a backup file named ``minion.bk``

    .. code-block:: bash

        salt '*' file.comment_line 'C:\salt\conf\minion' '^log_level: (warning|info|debug)' '#' False '.bk'
    u{0}({1}){2}u^uu$u^{0}\s*({1}){2}uFile not found: {0}u
files.is_textu8Cannot perform string replacements on a binary file: {0}Rzurbt	bufferingu{0}{1}Nu)Unable to open file '{0}'. Exception: {1}Rtpreserve_inodeuException: {0}uwbuwulUnable to write file '{0}'. Contents may be truncated. Temporary file contains copy at '{1}'. Exception: {2}uKUnable to move the temp file '{0}' to the backup file '{1}'. Exception: {2}ustringutils.get_diff(,RwRRvtrstripR;RRtrealpathReR�R
R1RtgetsizeRRR!R�RGR�RERMR<RR~tIOErrorRRRRoRhtnormalize_modeRtt
_mkstemp_copyRtPY2tto_bytesRHR�R�tmoveR*tcheck_permsRD(RR�R�R�R�tfoundt	orig_filetnew_filetbufsizetr_fileR�texctpre_usert	pre_grouptpre_modet	temp_fileRztw_filetwlinetbackup_name((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR��s�3!

'
0$#
cC@s�t|tj�r|g}nt|t�r�t|t�r�g}xc|D][}tttj|�j��}t|tj	�s�t
dj|���n|j|�qJWt
tj|�St|tj	�r�|St
dj|���dS(u#
    Return an integer appropriate for use as a flag for the re module from a
    list of human-readable strings

    .. code-block:: python

        >>> _get_flags(['MULTILINE', 'IGNORECASE'])
        10
        >>> _get_flags('MULTILINE')
        8
        >>> _get_flags(2)
        2
    uInvalid re flag given: {0}ujInvalid re flags: "{0}", must be given either as a single flag string, a list of strings, or as an integerN(R`RR�RRtgetattrRERutuppert
integer_typesR
RwR<RR�t__or__(R�t
_flags_accR�t_flag((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt
_get_flags]s 
cC@s t|�}t|�}||BS(u-
    Combine ``flags`` and ``new_flags``
    (R(R�t	new_flags((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt
_add_flags�scC@s�d}y%tjjjdtjjj�}Wn.ttfk
r[}tdj	|���nX|r�yt
j||�Wq�ttfk
r�}tdj	|||���q�XnKyt
j||�Wn4ttfk
r�}tdj	|||���nX|S(uZ
    Create a temp file and move/copy the contents of ``path`` to the temp file.
    Return the path to the temp file.

    path
        The full path to the file whose contents will be moved/copied to a temp file.
        Whether it's moved or copied depends on the value of ``preserve_inode``.
    preserve_inode
        Preserve the inode of the file, so that any hard links continue to share the
        inode with the original filename. This works by *copying* the file, reading
        from the copy, and writing to the file at the original inode. If ``False``, the
        file will be *moved* rather than copied, and a new file will be written to a
        new inode, but using the original filename. Hard links will then share an inode
        with the backup, instead (if using ``backup`` to create a backup copy).
        Default is ``True``.
    tprefixu*Unable to create temp file. Exception: {0}u@Unable to copy file '{0}' to the temp file '{1}'. Exception: {2}u@Unable to move file '{0}' to the temp file '{1}'. Exception: {2}N(
RDRRR!tmkstempR"R~R�RRwR�R�R�(RR�RR((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR��s*%cC@s1d�}d�}d}d}|s,|r0|S|jd�}|jd�}||kr^|S||rs||�pv|�}||r�||�p�|�}t|�t|�kr�||fp�||f\}}dj|�}xKtt|��D]7}	dj||	d �}
|
r�|j|
�r�|	Sq�W|S(uZ
    Returns True if src and probe at least matches at the beginning till some point.
    cS@sH|jdd�}t|�dkrDt|d�dkrD|dpG|S(u�
        Strip possible comments.
        Usually comments are one or two symbols at the beginning of the line, separated with space
        u iii(R�R�(ttxttbuff((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_strip_comments�scS@s>|r:g|j�jd�D]}|j�r|^qp=|S(u 
        Split by words
        u (R�R�(Rtw((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt	_to_words�si����iu

u i(R�R�RRR(tsrctprobetstrip_commentsRRtno_matchtequalta_bufftb_bufftidxtprb((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_starts_till�s&		6cC@s�|s|rdSyPtj|tj�}g|D]*}|j|�sU|j|�r1|^q1}Wn1tk
r�}tdjt	|�|���nX|r�|p�gS(u4
    Expand regular expression to static match.
    u
{0}: '{1}'N(
RDRER�tDOTALLRFR�RyRRwt_get_error_message(RR�tcompiledR�R�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_regex_to_static�s;"icC@spt|�}||kr!d}n*||kr6d}n|sEd}nd}|rltdj||���n|S(u\
    Raise an exception, if there are different amount of specified occurrences in src.
    u	more thanu	less thanunou2Found {0} expected occurrences in "{1}" expressionN(R�RDRRw(Rttargettamounttocctmsg((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_assert_occurrence�s			cC@sU|s
|Sg}x+|D]#}|dkr-Pn|j|�qWdj|�|j�S(u/
    Indent the line with the source line.
    u	u u(u	u (R<RRv(RR�tindenttidttc((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_set_line_indents
cC@s(tjd|�}|r$|j�p'dS(Nu((?<!
)
|
(?!
)|
)$u(RERFRI(R�RM((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_get_eol scC@s#t|�ptj}|j�|S(u
    Add line ending
    (R0RtlinesepR�(RR�tline_ending((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt
_set_line_eol%scC@sW|s*|rSt||d|�dkrSt||||�}|j||�n|S(Nii(R"R/tinsert(R tbodytcontentR,tcnd((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_insert_line_before-s*cC@s||dt|�kr$||dp'd}|dksKt||�dkrxt||||�}|j|d|�n|S(Nii(R�RDR"R/R4(R R5R6R,t	next_lineR7((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_insert_line_after4s
*!cC@s�tjjtjj|��}tjj|�sR|	sNtdj|���ntS|rd|j�pg|}|d#kr�|dkr�td��q�tdj|���ndg}||kr�|dkr�tdjd	j
|����n~|dkr|dkr|r|}ntjj
j|d
d��"}tjjj|j��}
WdQXtjtjjjd
j
|
���j�}|
r�t|
d�r�|
jd
�nt|
|�}t|
|�}t|
|�}tj|�jdkr|d$krtjdj||��g}
n|dkrY|rYg|
D]}||dkr4|^q4}
n�|dkr�|r�|
j|d�}|
j|�}|
j |t!|||
��np|dkr�|r�|r�|r�td��n|s|r�|r�t"|d�t"|d�g}t}xl|
D]d}||dkr:t#}n8||dkrr|rrt!|||
�}|j|�n|j|�qW|}
n|r�|r�t"|d�|
j|d�}t$||
||
�}
q�|r�|r�t"|d�|
j|d�}t%||
||
�}
q�q|dkrb|
rK|
j dt&|
d|��q�|
j|tj'�q|dkr|
j|
r�t!|
d||
�n|�qn|dkr|r�|r�t"|d�t"|d�t(g|
D]}|j)|�r�|^q��}|s|
j|d�}|t*|
�dkrq|
|d|dkrqt!|
|||
�}|
j |d|�q�td��qq|r�|r�t"|d�|
j|d�}t$||
||
�}
q|r
|r
t"|d�|
j|d�}t%||
||
�}
qtd��n|
r�xmt+|
�D]_\}}t|�r/|dt*|
�kr/|rn|dpqd}t&|
||�|
|<q/q/Wd
|
dkr�|
j�q�n|tjtjjjd
j
|
���j�k}|r|rt,dtkryGt-d|dt#�}t.j/|dj|t0j1dt0j2����Wqt3t4fk
r{}tdj||���qXnd}|r�|r�tjj
j|d��+}tjjj|j5�j6t#��}WdQXt7d||
�}nt,dtkr�d}z�t8j9r>tjj:j;�r>d }tjjj<|
�}
n!d!}tjjj|
d"t#�}
tjj=j>||�}|j?|
�Wd|r�|j@�nXq�n|r�|p�|S(%uj

    .. versionadded:: 2015.8.0

    Edit a line in the configuration file. The ``path`` and ``content``
    arguments are required, as well as passing in one of the ``mode``
    options.

    path
        Filesystem path to the file to be edited.

    content
        Content of the line. Allowed to be empty if mode=delete.

    match
        Match the target line for an action by
        a fragment of a string or regular expression.

        If neither ``before`` nor ``after`` are provided, and ``match``
        is also ``None``, match becomes the ``content`` value.

    mode
        Defines how to edit a line. One of the following options is
        required:

        - ensure
            If line does not exist, it will be added. This is based on the
            ``content`` argument.
        - replace
            If line already exists, it will be replaced.
        - delete
            Delete the line, once found.
        - insert
            Insert a line.

        .. note::

            If ``mode=insert`` is used, at least one of the following
            options must also be defined: ``location``, ``before``, or
            ``after``. If ``location`` is used, it takes precedence
            over the other two options.

    location
        Defines where to place content in the line. Note this option is only
        used when ``mode=insert`` is specified. If a location is passed in, it
        takes precedence over both the ``before`` and ``after`` kwargs. Valid
        locations are:

        - start
            Place the content at the beginning of the file.
        - end
            Place the content at the end of the file.

    before
        Regular expression or an exact case-sensitive fragment of the string.
        This option is only used when either the ``ensure`` or ``insert`` mode
        is defined.

    after
        Regular expression or an exact case-sensitive fragment of the string.
        This option is only used when either the ``ensure`` or ``insert`` mode
        is defined.

    show_changes
        Output a unified diff of the old file and the new file.
        If ``False`` return a boolean if any changes were made.
        Default is ``True``

        .. note::
            Using this option will store two copies of the file in-memory
            (the original version and the edited version) in order to generate the diff.

    backup
        Create a backup of the original file with the extension:
        "Year-Month-Day-Hour-Minutes-Seconds".

    quiet
        Do not raise any exceptions. E.g. ignore the fact that the file that is
        tried to be edited does not exist and nothing really happened.

    indent
        Keep indentation with the previous line. This option is not considered when
        the ``delete`` mode is specified.

    CLI Example:

    .. code-block:: bash

        salt '*' file.line /etc/nsswitch.conf "networks:	files dns" after="hosts:.*?" mode='ensure'

    .. note::

        If an equal sign (``=``) appears in an argument to a Salt command, it is
        interpreted as a keyword argument in the format of ``key=val``. That
        processing can be bypassed in order to pass an equal sign through to the
        remote shell command by manually specifying the kwarg:

        .. code-block:: bash

            salt '*' file.line /path/to/file content="CREATEMAIL_SPOOL=no" match="CREATE_MAIL_SPOOL=yes" mode="replace"
    u,File "{0}" does not exists or is not a file.uinsertuensureudeleteureplaceu.Mode was not defined. How to process the file?uUnknown mode: "{0}"u*Content can only be empty if mode is "{0}"u, RzurNui����iu-Cannot find text to {0}. File '{1}' is empty.uIOn insert must be defined either "location" or "before/after" conditions.ubeforeuafterustartuendiuAFound more than one line between boundaries "before" and "after".u\Wrong conditions? Unable to ensure line without knowing where to put it before and/or after.utestRR�u{0}.{1}u%Y-%m-%d-%H-%M-%Su7Unable to create the backup file of {0}. Exception: {1}ustringutils.get_diffuwbuwRH(uinsertuensureudeleteureplace(udeleteureplace(ARRR�ReR�RRwRR�RDRRRR!R�tdatatdecode_listt	readlinesthashlibtsha256RGR�t	hexdigestR0R<R&tstattst_sizetlogtwarningtindexR�R4R/R+RR8R:R3R1R�R�R�t	enumerateR'R�R�R�ttimetstrftimet	localtimeR~R�R�R:R1RR�RRtencode_listt
atomicfiletatomic_opent
writelinestclose(RR6RMRztlocationR�R�tshow_changesR�tquietR,tempty_content_modestfp_R5tbody_beforeR�R t	file_linetouttin_rangeR7tltis_theretprevtchangedRRtchanges_difftpath_contenttfh_((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�=s�g	!	!-$	,


		



 /

..



#32*ic+C@s~	t}t|�r<t}tj|�}tjj|�}ntjjtjj|��}tjj|�s�|
rvtSt	dj
|���ntd|�s�t	dj
|���n|r�|s�|r�t	d��n|r�|r�t	d��nt|�}t
jtjjj|�|�}tjj|�}|dkrF|}nt}g}g}tjjj�s�t|�}t|�}tjjjt|��}ntjjjtj|��}|r�tjjj|�}nt}d}|r|s�|rtjjj|�ntjjj|�}z�y�d}tjjj|ddd	|���} y%t j | j!�d
dt j"�}Wn8t#t j$fk
r�tjjjdj%| ��}nX|r�t
j&||�r�tStSn�t
j'||r�|j(d
d�n|||�\}!}"|"d
kr:t}||kr1tn|}n|sF|r�t
j&tjjjdj
t
j)|���|d|�r�t}q�nt*|t j �r�|j+|�j,t�n|j,t�}|!j,t�}WdQXWn1t-t.fk
r
}#t/dj
||#���nXWd|r7t*|t j �r7|j0�nX|r1|
r1yt1d|d|�}Wn.t-t.fk
r�}#t/dj
|#���nXd}yhtjjj|ddd	|��A}$zy�tjjj|ddd	|���} t j | j!�d
dt j"�}t
j'||r(|j(d
d�n|||�\}!}"y |$j2tjjj3|!��Wn4t-t.fk
r�}#t/dj
|||#���nXWdQXWn.t-t.fk
r�}#t/dj
|#���nXWd|r�t*|t j �r�|j0�nXWdQXWq1t-t.fk
r-}#t/dj
|#���q1Xn|r�|sD|r�|dkrY|}n|r�|j4d
|tjjjtj5��n�d
t6|�kr�|dj7tjjjtj5��s�|dctjjjtj5�7<q�n|j8|tjjjtj5��t}|
s�yt1d|d|�}Wn.t-t.fk
r_}#t/dj
|#���nXzItjj9j:|d�}%x*|D]"}&|%j2tjjj|&��q�WWd|%j0�Xq�n|	r�|r�|
r�dj
||	�}'yt;j<||'�Wn4t-t.fk
r,}#t/dj
|||#���nX|r	dj
||	�}(dj
||	�})ytj=|)|(�Wq�t-k
r�tj>|(�tj=|)|(�q�t?k
r�t/dj
|(|)|#���q�Xq	nN|r	ytj>|�Wq	t-t.fk
r	}#t/dj
||#���q	Xn|
rN	tjjj�rN	t@|d|||�ntd||�}*|rk	|*S|*sz	t}n|S( u�
    .. versionadded:: 0.17.0

    Replace occurrences of a pattern in a file. If ``show_changes`` is
    ``True``, then a diff of what changed will be returned, otherwise a
    ``True`` will be returned when changes are made, and ``False`` when
    no changes are made.

    This is a pure Python implementation that wraps Python's :py:func:`~re.sub`.

    path
        Filesystem path to the file to be edited. If a symlink is specified, it
        will be resolved to its target.

    pattern
        A regular expression, to be matched using Python's
        :py:func:`~re.search`.

    repl
        The replacement text

    count : 0
        Maximum number of pattern occurrences to be replaced. If count is a
        positive integer ``n``, only ``n`` occurrences will be replaced,
        otherwise all occurrences will be replaced.

    flags (list or int)
        A list of flags defined in the ``re`` module documentation from the
        Python standard library. Each list item should be a string that will
        correlate to the human-friendly flag name. E.g., ``['IGNORECASE',
        'MULTILINE']``. Optionally, ``flags`` may be an int, with a value
        corresponding to the XOR (``|``) of all the desired flags. Defaults to
        8 (which supports 'MULTILINE').

    bufsize (int or str)
        How much of the file to buffer into memory at once. The
        default value ``1`` processes one line at a time. The special value
        ``file`` may be specified which will read the entire file into memory
        before processing.

    append_if_not_found : False
        .. versionadded:: 2014.7.0

        If set to ``True``, and pattern is not found, then the content will be
        appended to the file.

    prepend_if_not_found : False
        .. versionadded:: 2014.7.0

        If set to ``True`` and pattern is not found, then the content will be
        prepended to the file.

    not_found_content
        .. versionadded:: 2014.7.0

        Content to use for append/prepend if not found. If None (default), uses
        ``repl``. Useful when ``repl`` uses references to group in pattern.

    backup : .bak
        The file extension to use for a backup of the file before editing. Set
        to ``False`` to skip making a backup.

    dry_run : False
        If set to ``True``, no changes will be made to the file, the function
        will just return the changes that would have been made (or a
        ``True``/``False`` value if ``show_changes`` is set to ``False``).

    search_only : False
        If set to true, this no changes will be performed on the file, and this
        function will simply return ``True`` if the pattern was matched, and
        ``False`` if not.

    show_changes : True
        If ``True``, return a diff of changes made. Otherwise, return ``True``
        if changes were made, and ``False`` if not.

        .. note::
            Using this option will store two copies of the file in memory (the
            original version and the edited version) in order to generate the
            diff. This may not normally be a concern, but could impact
            performance if used with large files.

    ignore_if_missing : False
        .. versionadded:: 2015.8.0

        If set to ``True``, this function will simply return ``False``
        if the file doesn't exist. Otherwise, an error will be thrown.

    preserve_inode : True
        .. versionadded:: 2015.8.0

        Preserve the inode of the file, so that any hard links continue to
        share the inode with the original filename. This works by *copying* the
        file, reading from the copy, and writing to the file at the original
        inode. If ``False``, the file will be *moved* rather than copied, and a
        new file will be written to a new inode, but using the original
        filename. Hard links will then share an inode with the backup, instead
        (if using ``backup`` to create a backup copy).

    backslash_literal : False
        .. versionadded:: 2016.11.7

        Interpret backslashes as literal backslashes for the repl and not
        escape characters.  This will help when using append/prepend so that
        the backslashes are not interpreted for the repl on the second run of
        the state.

    If an equal sign (``=``) appears in an argument to a Salt command it is
    interpreted as a keyword argument in the format ``key=val``. That
    processing can be bypassed in order to pass an equal sign through to the
    remote shell command by manually specifying the kwarg:

    .. code-block:: bash

        salt '*' file.replace /path/to/file pattern='=' repl=':'
        salt '*' file.replace /path/to/file pattern="bind-address\s*=" repl='bind-address:'

    CLI Examples:

    .. code-block:: bash

        salt '*' file.replace /etc/httpd/httpd.conf pattern='LogLevel warn' repl='LogLevel info'
        salt '*' file.replace /some/file pattern='before' repl='after' flags='[MULTILINE, IGNORECASE]'
    uFile not found: {0}u
files.is_textu8Cannot perform string replacements on a binary file: {0}u;search_only cannot be used with append/prepend_if_not_foundu8Only one of append and prepend_if_not_found is permittedufileRzurbR�itaccessuu\u\\u^{0}($|(?=
))R�Nu)Unable to open file '{0}'. Exception: {1}RR�uException: {0}uwurulUnable to write file '{0}'. Contents may be truncated. Temporary file contains copy at '{1}'. Exception: {2}i����uwbu{0}{1}uKUnable to move the temp file '{0}' to the backup file '{1}'. Exception: {2}uDUnable create backup symlink '{0}'. Target was '{1}'. Exception: {2}u0Unable to delete temp file '{0}'. Exception: {1}ustringutils.get_diff(ARtis_linkRRtreadlinkRReR�R)R
RwR1RRER�RRRGR�R�RRRoRhR!R�RtRRuRDR�R�tmmaptfilenotACCESS_READRWterrorRRFtsubnR�tescapeR`R�R:R~R�RRNR�R�RHR4R1R�R;R<RKRLR�R�tsymlinkR*RyR�(+RR�treplR�R�R�tappend_if_not_foundtprepend_if_not_foundtnot_found_contentR�tdry_runtsearch_onlyRPtignore_if_missingR�tbackslash_literalRhttarget_patht
given_patht	flags_numtcpatterntfilesizethas_changesR�R�RRRR�RR6tr_dataRRLtnreplRRR^R�Rtsymlink_backupt
target_backuptdifferences((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�GsP�!	'"	*	*

	  	)%(#

$


	u#-- start managed zone --u#-- end managed zone --c
@s�|r|rtd��ntjj|�}tjj|�sWtdj|���nytd|�}
Wntk
r�d}
nXtd|�r�|
s�tdj|���q�n�dkr�|j	tj
df�r�t�ng�x>|jd�D]-}x$|jd�D]}�j
|�qWq�Wt���t}
g}g}t}t}d}dtd�����fd�}zMytj|d	d
d|
dd
�}x�|D]�}t}|dkr|j	d�r�d}q|j	d�r�d}qtj
}n�|krt}nY|rot}|j��}|dkrot}t}||d|dtd||�qon|j
|�|r�|j
|�q�q�WWn1ttfk
r�}tdj||���nXWd|dkr�tj
}ny|j�Wntk
rnXX|rtd��n|s�|rS||�}|j|�|}t}q�|r�dt|�kr�|dj	|�s�|dc|7<q�n||d|�t}q�td��n|r�td||�}|d
k	}
|
r�|r�i}t|�|d<t|�|d<tjjjt|��|d<|tk	r�dj||�}tj ||�tjj!j"�r�t#d|ddd|d�q�t#d|ddd |dd!|dd	|d�nzOtjj$j%|d"�}x0|D](}|j&tjj'j(|d|
��q�WWd|j�Xtjj!j"�rVt#d|ddd|d�q�t#|ddd |dd!|dd	|d�n|r�|Sn|
S(#u
    .. versionadded:: 2014.1.0

    Replace content of a text block in a file, delimited by line markers

    A block of content delimited by comments can help you manage several lines
    entries without worrying about old entries removal.

    .. note::

        This function will store two copies of the file in-memory (the original
        version and the edited version) in order to detect changes and only
        edit the targeted file if necessary.

    path
        Filesystem path to the file to be edited

    marker_start
        The line content identifying a line as the start of the content block.
        Note that the whole line containing this marker will be considered, so
        whitespace or extra content before or after the marker is included in
        final output

    marker_end
        The line content identifying the end of the content block. As of
        versions 2017.7.5 and 2018.3.1, everything up to the text matching the
        marker will be replaced, so it's important to ensure that your marker
        includes the beginning of the text you wish to replace.

    content
        The content to be used between the two lines identified by marker_start
        and marker_stop.

    append_if_not_found : False
        If markers are not found and set to ``True`` then, the markers and
        content will be appended to the file.

    prepend_if_not_found : False
        If markers are not found and set to ``True`` then, the markers and
        content will be prepended to the file.


    backup
        The file extension to use for a backup of the file if any edit is made.
        Set to ``False`` to skip making a backup.

    dry_run : False
        If ``True``, do not make any edits to the file and simply return the
        changes that *would* be made.

    show_changes : True
        Controls how changes are presented. If ``True``, this function will
        return a unified diff of the changes made. If False, then it will
        return a boolean (``True`` if any changes were made, otherwise
        ``False``).

    append_newline : False
        Controls whether or not a newline is appended to the content block. If
        the value of this argument is ``True`` then a newline will be added to
        the content block. If it is ``False``, then a newline will *not* be
        added to the content block. If it is ``None`` then a newline will only
        be added to the content block if it does not already end in a newline.

        .. versionadded:: 2016.3.4
        .. versionchanged:: 2017.7.5,2018.3.1
            New behavior added when value is ``None``.
        .. versionchanged:: 2019.2.0
            The default value of this argument will change to ``None`` to match
            the behavior of the :py:func:`file.blockreplace state
            <salt.states.file.blockreplace>`

    CLI Example:

    .. code-block:: bash

        salt '*' file.blockreplace /etc/hosts '#-- start managed zone foobar : DO NOT EDIT --' \
        '#-- end managed zone foobar --' $'10.0.1.1 foo.foobar\n10.0.1.2 bar.foobar' True

    u8Only one of append and prepend_if_not_found is permitteduFile not found: {0}ufiles.get_encodingufiles.is_binaryu8Cannot perform string replacements on a binary file: {0}u
u
c@s�|dkrg}t}n|dkr0�}n|jd�|}|r]|j�|�n�r�x�t�d�D]d\}}|�kr�|j||�qs�r�|j||�|j|�qs|j||�qsWn
|j|�|S(Nu
i(RDRR�R<RF(R1R>tinclude_marker_starttend_lineREtcontent_line(tappend_newlinet
line_countt
marker_endtmarker_startt
split_content(s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_add_contentH
s$		
Rzurtencodingtnewlineui����R>R|R}uFailed to read from {0}: {1}NuAUnterminated marked block. End of file reached before marker_end.iu9Cannot edit marked block. Markers were not found in file.ustringutils.get_diffuuserugroupumodeu{0}{1}RR.townertnameRnRIuwb()R
RRReR)RwR1RRDR;R1RR�R<R�RtiotopenR�R�R~RNRyR�RoRhRRR!R�RtR�R�RRR�RKRLR�RGR�(RR�R�R6RjRkR�RmRPRt
file_encodingtwin_lineR~RvR�R�tin_blocktblock_foundR1R�tfi_fileR�twrite_line_to_new_filetmarker_end_posRtprepended_contenttdifftpermstbackup_pathR^((RR�R�R�R�s5/usr/lib/python2.7/site-packages/salt/modules/file.pytblockreplace�	s�Y

%	!
			


		



*	

cC@sR|rt|d�}d}nt||dd|d|dtdtdtd	|�S(
u�
    .. versionadded:: 0.17.0

    Search for occurrences of a pattern in a file

    Except for multiline, params are identical to
    :py:func:`~salt.modules.file.replace`.

    multiline
        If true, inserts 'MULTILINE' into ``flags`` and sets ``bufsize`` to
        'file'.

        .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt '*' file.search /etc/crontab 'mymaintenance.sh'
    u	MULTILINEufileuR�R�RmRnRPRo(RR�RR(RR�R�R�Rot	multiline((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyRF�
s	c	C@s�tjjjd�}|s*td��n|g}|jtjjj|��|r�tddkru|j	d�q�|j	d�nd|kr�d	|kr�|j	d	�nt
}xB|D]:}|d
ks�|jd�s�|jd�r�t}Pq�q�W|s|j	d
�n|jd|g�t
jj|�r�|jd|g�t
}x6|D].}|jd�sw|jd�rSt}PqSqSW|s�|j	d�q�n
|j	|�td|dt
�S(uX
    .. versionadded:: 0.10.4

    Apply a patch to a file or directory.

    Equivalent to:

    .. code-block:: bash

        patch <options> -i <patchfile> <originalfile>

    Or, when a directory is patched:

    .. code-block:: bash

        patch <options> -i <patchfile> -d <originalfile> -p0

    originalfile
        The full path to the file or directory to be patched
    patchfile
        A patch file to apply to ``originalfile``
    options
        Options to pass to patch.

    CLI Example:

    .. code-block:: bash

        salt '*' file.patch /opt/file.txt /tmp/file.txt.patch
    upatchuJpatch executable not found. Is the distribution's patch package installed?ukerneluFreeBSDuOpenBSDu-Cu	--dry-runu-Nu	--forwardu-ru-r u
--reject-fileu--reject-file=-u-iu-du-pu--strip=u	--strip=0ucmd.run_allRA(uFreeBSDuOpenBSD(RRRRBRR�R�R�t
__grains__R<RRRRtisdirR8(	toriginalfilet	patchfileR�Rmt	patchpathRKthas_rejectfile_optiontoptionthas_strip_option((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytpatch#s@	


cC@s�tjj|�}tjj|�s(tStj|�j�}yGtj	j
j|��(}x|D]}||kr_tSq_WWdQXtSWnt
tfk
r�tSXdS(u�
    .. deprecated:: 0.17.0
       Use :func:`search` instead.

    Return ``True`` if the file at ``path`` contains ``text``

    CLI Example:

    .. code-block:: bash

        salt '*' file.contains /etc/crontab 'mymaintenance.sh'
    N(RRReR)RRRuR�RRt
filebuffertBufferedReaderRR�R~(RR�t
stripped_texttbreadertchunk((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytcontainsus

cC@s�tjj|�}tjj|�s(tSy}tjjj|d��_}xQ|D]I}tjj	j
|�}|r�|j|�}ntj
||�rMtSqMWtSWdQXWnttfk
r�tSXdS(u�
    .. deprecated:: 0.17.0
       Use :func:`search` instead.

    Return True if the given regular expression matches on any line in the text
    of a given file.

    If the lchar argument (leading char) is specified, it
    will strip `lchar` from the left side of each line before trying to match

    CLI Example:

    .. code-block:: bash

        salt '*' file.contains_regex /etc/crontab
    urN(RRReR)RRRR!R�RGR�RvRERFRR�R~(RR�tlcharR'R�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytcontains_regex�s
cC@s�tjj|�}tjj|�s(tSyMtjjj|��2}x$|D]}t	j	||�rJt
SqJWtSWdQXWnttfk
r�tSXdS(u�
    .. deprecated:: 0.17.0
       Use :func:`search` instead.

    Return ``True`` if the given glob matches a string in the named file

    CLI Example:

    .. code-block:: bash

        salt '*' file.contains_glob /etc/foobar '*cheese*'
    N(
RRReR)RRRR�R�tfnmatchRR�R~(Rt	glob_exprR�R�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt
contains_glob�s

cO@s�tjj|�}d|krNt|dt�r>|d}qN|dg}ntjjj|d���}tjj	j
tj�}y|jt
|�tj�Wn4tk
r�}|jtjtjfkr�q�n?X|jt
|��|kr|jdtj�|j|�nWdQXtjjj|d��C}x9|D]1}|jtjj	jdj|tj���q<WWdQXdjt
|�|�S(u�
    .. versionadded:: 0.9.5

    Append text to the end of a file

    path
        path to file

    `*args`
        strings to append to file

    CLI Example:

    .. code-block:: bash

        salt '*' file.append /etc/motd \
                "With all thine offerings thou shalt offer salt." \
                "Salt is what makes things taste bad when it isn't in them."

    .. admonition:: Attention

        If you need to pass a string to append and that string contains
        an equal sign, you **must** include the argument name, args.
        For example:

        .. code-block:: bash

            salt '*' file.append /etc/motd args='cheese=spam'

            salt '*' file.append /etc/motd args="['cheese=spam','spam=cheese']"

    uargsurb+iNuau{0}{1}uWrote {0} lines to "{1}"(RRReR`tlistRRR!R�RGR�R1tseekR�tSEEK_ENDR�terrnotEINVALtESPIPER�R�RHRw(RR�R�R�R1Rtnew_line((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR<�s,!

#c	O@sKtjj|�}d|krNt|dt�r>|d}qN|dg}nyPtjjj|��5}g|j	�D]}tjj
j|�^qv}WdQXWntk
r�g}nXg}x$|D]}|j
dj|��q�Wtjjj|d��6}||}|jtjj
jdj|���WdQXdjt|�|�S(u�
    .. versionadded:: 2014.7.0

    Prepend text to the beginning of a file

    path
        path to file

    `*args`
        strings to prepend to the file

    CLI Example:

    .. code-block:: bash

        salt '*' file.prepend /etc/motd \
                "With all thine offerings thou shalt offer salt." \
                "Salt is what makes things taste bad when it isn't in them."

    .. admonition:: Attention

        If you need to pass a string to append and that string contains
        an equal sign, you **must** include the argument name, args.
        For example:

        .. code-block:: bash

            salt '*' file.prepend /etc/motd args='cheese=spam'

            salt '*' file.prepend /etc/motd args="['cheese=spam','spam=cheese']"

    uargsNu{0}
uwuuPrepended {0} lines to "{1}"(RRReR`R�RRR!R�R=RGR�R�R<RwR�RHRR�(RR�R�tfhrR�tcontentstprefaceR�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytprepends$!
5



+cO@s�tjj|�}d|krNt|dt�r>|d}qN|dg}ng}x$|D]}|jdj|��q[Wtjj	j
|d��,}|jtjjj
dj|���WdQXdjt|�|�S(u�
    .. versionadded:: 2014.7.0

    Write text to a file, overwriting any existing contents.

    path
        path to file

    `*args`
        strings to write to the file

    CLI Example:

    .. code-block:: bash

        salt '*' file.write /etc/motd \
                "With all thine offerings thou shalt offer salt."

    .. admonition:: Attention

        If you need to pass a string to append and that string contains
        an equal sign, you **must** include the argument name, args.
        For example:

        .. code-block:: bash

            salt '*' file.write /etc/motd args='cheese=spam'

            salt '*' file.write /etc/motd args="['cheese=spam','spam=cheese']"

    uargsu{0}
uwuNuWrote {0} lines to "{1}"(RRReR`R�R<RwRRR!R�R�RGRHRR�(RR�R�R�R�R�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�Ss 

+c	C@sZtjj|�}|r3|j�r3t|�}n|rT|j�rTt|�}ny�tjj|�s�tjjj	|d��WdQXn|r�|r�d}nP|r�|r�|tj�f}n.|r�|r�tj�|f}n||f}tj||�WnDt
k
r"td��n(ttfk
rI}t|j��nXtjj|�S(um
    .. versionadded:: 0.9.5

    Just like the ``touch`` command, create a file if it doesn't exist or
    simply update the atime and mtime if it already does.

    atime:
        Access time in Unix epoch time
    mtime:
        Last modification in Unix epoch time

    CLI Example:

    .. code-block:: bash

        salt '*' file.touch /var/log/emptyfile
    uaNu atime and mtime must be integers(RRRetisdigitRVR)RRR!R�RDRGtutimeR�R
R�R~Rtstrerror(R�tatimetmtimettimesR((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyttouch�s,		


cC@sqtjj|�}tj|tj�}z5tj|t|�d�tj|t|��}Wdtj|�X|S(u.
    .. versionadded:: 2014.1.0

    Seek to a position on a file and read it

    path
        path to file

    seek
        amount to read at once

    offset
        offset to start into the file

    CLI Example:

    .. code-block:: bash

        salt '*' file.seek_read /path/to/file 4096 0
    iN(	RRReR�tO_RDONLYtlseekRVR�RN(Rtsizetoffsettseek_fhR;((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt	seek_read�scC@sxtjj|�}tj|tj�}z<tj|t|�d�tj||�}tj|�Wdtj	|�X|S(u@
    .. versionadded:: 2014.1.0

    Seek to a position on a file and write to it

    path
        path to file

    data
        data to write to file

    offset
        position in file to start writing

    CLI Example:

    .. code-block:: bash

        salt '*' file.seek_write /path/to/file 'some data' 4096
    iN(
RRReR�tO_WRONLYR�RVR�tfsyncRN(RR;R�R�R.((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt
seek_write�scC@sJtjj|�}tjjj|d��}|jt|��WdQXdS(u
    .. versionadded:: 2014.1.0

    Seek to a position on a file and delete everything after that point

    path
        path to file

    length
        offset into file to truncate

    CLI Example:

    .. code-block:: bash

        salt '*' file.truncate /path/to/file 512
    urb+N(	RRReRRR!R�ttruncateRV(RtlengthR�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR��scC@s~tjj|�}tjj|�s3td��nytj||�tSWn,ttfk
ryt	dj
|���nXtS(u�
    .. versionadded:: 2014.1.0

    Create a hard link to a file

    CLI Example:

    .. code-block:: bash

        salt '*' file.link /path/to/file /path/to/link
    uFile path must be absolute.uCould not create '{0}'(RRReR�R
tlinkRR~R�RRwR(RR((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�
scC@stjjtjj|��S(u�
    Check if the path is a symbolic link

    CLI Example:

    .. code-block:: bash

       salt '*' file.is_link /path/to/link
    (RRtislinkRe(R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR`!
scC@s�tjj|�}yHtjjtj|��tjj|�krYtjd||�tSWntk
rmnXtjj	|�s�t
d��nytj||�tSWn,ttfk
r�t
dj|���nXtS(u�
    Create a symbolic link (symlink, soft link) to a file

    CLI Example:

    .. code-block:: bash

        salt '*' file.symlink /path/to/file /path/to/link
    u'link already in correct state: %s -> %suFile path must be absolute.uCould not create '{0}'(RRRetnormpathRaRCtdebugRR~R�R
RhR�RRwR(RR((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyRh3
s
-
cC@s�tjj|�}tjj|�}tjj|�sEtd��nytj||�tSWn)tk
r�tdj	||���nXt
S(u�
    Rename a file or directory

    CLI Example:

    .. code-block:: bash

        salt '*' file.rename /path/to/src /path/to/dst
    uFile path must be absolute.uCould not rename '{0}' to '{1}'(RRReR�R
trenameRR~RRwR(Rtdst((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�Q
s

cC@s�tjj|�}tjj|�}tjj|�sEtd��ntjj|�sotdj|���ntj	j
j�s�t|�}t
|�}tj	jjt|��}ny�tjj|�r�tjj|�s�tjj|�rY|std��n|r@tjj|�r-tj|�ntj||�qitj	jj||�ntj||�Wn)tk
r�tdj||���nXtj	j
j�s�t|d|||�ntS(u�
    Copy a file or directory from source to dst

    In order to copy a directory, the recurse flag is required, and
    will by default overwrite files in the destination with the same path,
    and retain all other existing files. (similar to cp -r on unix)

    remove_existing will remove all files in the target directory,
    and then copy files from the source.

    .. note::
        The copy function accepts paths that are local to the Salt minion.
        This function does not support salt://, http://, or the other
        additional file paths that are supported by :mod:`states.file.managed
        <salt.states.file.managed>` and :mod:`states.file.recurse
        <salt.states.file.recurse>`.

    CLI Example:

    .. code-block:: bash

        salt '*' file.copy /path/to/src /path/to/dst
        salt '*' file.copy /path/to/src_dir /path/to/dst_dir recurse=True
        salt '*' file.copy /path/to/src_dir /path/to/dst_dir recurse=True remove_existing=True

    uFile path must be absolute.uNo such file or directory '{0}'uECannot copy overwriting a directory without recurse flag set to true!uCould not copy '{0}' to '{1}'N(RRReR�R
R)RRwRRRRRoRhR!R�RtR�R�trmtreetcopytreetrecursive_copytcopyfileR~R�RDR(RR�trecursetremove_existingRRR((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytcopyk
s66
c
@sytjj|�}tjj|�s3td��ny-tj|��t�fd�dD��SWntk
rtiSXdS(
u�
    .. versionadded:: 2014.1.0

    Returns the lstat attributes for the given file or dir. Does not support
    symbolic links.

    CLI Example:

    .. code-block:: bash

        salt '*' file.lstat /path/to/file
    uPath to file must be absolute.c3@s$|]}|t�|�fVqdS(N(R	(Rtkey(tlst(s5/usr/lib/python2.7/site-packages/salt/modules/file.pys	<genexpr>�
sust_atimeust_ctimeust_gidust_modeust_mtimeust_nlinkust_sizeust_uidN(ust_atimeust_ctimeust_gidust_modeust_mtimeust_nlinkust_sizeust_uid(RRReR�R
tlstattdictRy(R((R�s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR��
s

cC@s�tjj|�}tjj|�s3td��nitjd6tjd6tjd6tjd6}||kr�tj	|||�S|t
j|�kr�tj	||�Std��dS(u�
    .. versionadded:: 2014.1.0

    Test whether the Salt process has the specified access to the file. One of
    the following modes must be specified:

    .. code-block::text

        f: Test the existence of the path
        r: Test the readability of the path
        w: Test the writability of the path
        x: Test whether the path can be executed

    CLI Example:

    .. code-block:: bash

        salt '*' file.access /path/to/file f
        salt '*' file.access /path/to/file x
    uPath to link must be absolute.ufuruwuxuInvalid mode specified.N(RRReR�R
tF_OKtR_OKtW_OKtX_OKR_RR&(RRztmodes((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR_�
s



cC@s]d}|tkr|d7}ntjjj||�� }tjjj|j��SWdQXdS(u�
    .. versionadded:: 2017.7.0

    Return the content of the file.

    CLI Example:

    .. code-block:: bash

        salt '*' file.read /path/to/file
    urubN(RRRR!R�RGR�R�(Rtbinarytaccess_modetfile_obj((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR��
s

cC@s{tjj|�}tjj|�s3td��ntjj|�sTtd��n|rjtjj|�Stj|�SdS(u�
    .. versionadded:: 2014.1.0

    Return the path that a symlink points to
    If canonicalize is set to True, then it return the final target

    CLI Example:

    .. code-block:: bash

        salt '*' file.readlink /path/to/link
    uPath to link must be absolute.uA valid link was not specified.N(RRReR�R
R�R�Ra(Rtcanonicalize((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyRa�
s
cC@sztjj|�}tjj|�s3td��ntjj|�sTtd��nddg}|jtj|��|S(u�
    .. versionadded:: 2014.1.0

    Return a list containing the contents of a directory

    CLI Example:

    .. code-block:: bash

        salt '*' file.readdir /path/to/dir/
    uDir path must be absolute.u$A valid directory was not specified.u.u..(RRReR�R
R�R�tlistdir(Rtdirents((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytreaddirsc@s�tjj|�}tjj|�s3td��ny-tj|��t�fd�dD��SWn,ttfk
r�t	d
j
|���nXtS(u�
    .. versionadded:: 2014.1.0

    Perform a statvfs call against the filesystem that the file resides on

    CLI Example:

    .. code-block:: bash

        salt '*' file.statvfs /path/to/file
    uFile path must be absolute.c3@s$|]}|t�|�fVqdS(N(R	(RR�(tstv(s5/usr/lib/python2.7/site-packages/salt/modules/file.pys	<genexpr>Fsuf_bavailuf_bfreeuf_blocksuf_bsizeuf_favailuf_ffreeuf_filesuf_flaguf_frsizeu	f_namemaxuCould not statvfs '{0}'(
uf_bavailuf_bfreeuf_blocksuf_bsizeuf_favailuf_ffreeuf_filesuf_flaguf_frsizeu	f_namemax(RRReR�R
tstatvfsR�R~R�RRwR(R((R�s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�3scC@sUtjj|�}i}tjj|�siytj|�}Wq�tk
retdj|���q�Xn'|r�tj|�}ntj|�}|j	|d<|j
|d<|j|d<t|j�|d<t
|j
�|d<|j|d<|j|d<|j|d	<|j|d
<tjjjttj|j���|d<|rXt||�|d<nd
|d<tj|j�r�d|d<ntj|j�r�d|d<ntj|j�r�d|d<ntj|j�r�d
|d<ntj|j�r�d|d<ntj|j�rd|d<ntj |j�r;d|d<ntjj!|�|d<|S(u�
    Return a dict containing the stats for a given file

    CLI Example:

    .. code-block:: bash

        salt '*' file.stats /etc/passwd
    uPath not found: {0}uinodeuuidugidugroupuuseruatimeumtimeuctimeusizeumodeusumufileutypeudirucharublockulinkupipeusocketutarget("RRReR)R�R~RRwRAtst_inotst_uidtst_gidR_Rmtst_atimetst_mtimetst_ctimeRBRRR!R�tocttS_IMODEtst_modeR�tS_ISDIRtS_ISCHRtS_ISBLKtS_ISREGtS_ISLNKtS_ISFIFOtS_ISSOCKR�(RR�RcR.tpstat((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyRdNsN








+







cC@s�tjj|�}tjj|�s3td��ntjj|�sTtd��nytj|�tSWntk
r�}|j	SXdS(u�
    .. versionadded:: 2014.1.0

    Remove the specified directory. Fails if a directory is not empty.

    CLI Example:

    .. code-block:: bash

        salt '*' file.rmdir /tmp/foo/
    uFile path must be absolute.u$A valid directory was not specified.N(
RRReR�R
R�trmdirRR~R�(RR((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR��s
cC@s�tjj|�}tjj|�s<tdj|���ny\tjj|�sctjj|�rttj|�t	Stjj
|�r�tj|�t	SWn1t
tfk
r�}tdj||���nXtS(u�
    Remove the named file. If a directory is supplied, it will be recursively
    deleted.

    CLI Example:

    .. code-block:: bash

        salt '*' file.remove /tmp/foo
    uFile path must be absolute: {0}uCould not remove '{0}': {1}(RRReR�R
RwR�R�R*RR�R�R�R~R�RR(RR((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR*�s$

cC@stjjtjj|��S(u�
    Tests to see if path is a valid directory.  Returns True/False.

    CLI Example:

    .. code-block:: bash

        salt '*' file.directory_exists /etc

    (RRR�Re(R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytdirectory_exists�scC@stjjtjj|��S(u�
    Tests to see if path is a valid file.  Returns True/False.

    CLI Example:

    .. code-block:: bash

        salt '*' file.file_exists /etc/passwd

    (RRR�Re(R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytfile_exists�scC@s#tjtjj|��rtStS(uM
    Tests to see if path after expansion is a valid path (file or directory).
    Expansion allows usage of ? * and character ranges []. Tilde expansion
    is not supported. Returns True/False.

    .. versionadded:: 2014.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' file.path_exists_glob /etc/pam*/pass*

    (R�RRReRR(R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytpath_exists_glob�scC@s<|rdd|g}ndd|g}td|dt�S(u�
    Reset the SELinux context on a given path

    CLI Example:

    .. code-block:: bash

         salt '*' file.restorecon /home/user/.ssh/authorized_keys
    u
restoreconu-FRu-Fucmd.retcodeRA(R8R(Rt	recursiveRK((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt
restorecon�s
cC@setddd|gdt�}ytjd|�jd�}Wn tk
r`dj|�}nX|S(u�
    Get an SELinux context from a given path

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_selinux_context /etc/hosts
    ucmd.runulsu-ZRAu\w+:\w+:\w+:\w+iu3No selinux context information is available for {0}(R8RRERFRIR�Rw(RRVR.((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytget_selinux_contexts

cC@s�t||||f�stSdg}|rA|jd|g�n|r]|jd|g�n|ry|jd|g�n|r�|jd|g�n|j|�td|dt�}|r�t|�S|SdS(	u
    Set a specific SELinux label on a given path

    CLI Example:

    .. code-block:: bash

        salt '*' file.set_selinux_context path <user> <role> <type> <range>
        salt '*' file.set_selinux_context /etc/yum.repos.d/epel.repo system_u object_r system_conf_t s0
    uchconu-uu-ru-tu-lucmd.retcodeRAN(R(RR�R<R8R�(RRntrolettypeRRKR.((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytset_selinux_contexts 	

c	C@sdj|||�}|tkr)t|St|t�r�gtd|�D]}||f^qI}gtd|�D]}||f^qr}x�|D]�}t|t�r�tt|��}ntj	j
j|�\}	}
|
r�|gtd|
�D]}||
f^q�7}|gtd|
�D]}||
f^q7}q�q�Wd}x�|D]~}t|t�r4t
|�dkrwqJntt|��}||r�||n|}
t|�}tj	jj�r�|jj�tjkr�td|�}q�n|j}|dkretj	j
j|�\}	}
|
s.|}
n|	|f|ksR|	|f|kr1||
f}Pq1q�|jd�s�|dkr�||
f}Pq�|d	kr�tjj|j�s�tjj|j�s�tjjtjj|j|j��r�||
f}Pq�|jtj�r�tjj|�r�||
f}Pq�qJt|tj�rJtj	j
j|�\}	}
|
sp|}
n|	|
f|ks�|	|
f|kr�||f}Pnt|�}tj	jj�r�|jj�tjkr�td|�}q�n|j}|d	krftjj|j�sVtjj|j�sVtjjtjj|j|j��rf||f}Pq�|jd�s�|dkr�||f}Pq�|jtj�r�tjj|�r�||f}Pq�qJqJW|dkr�td
��q�n||f}|t|<|S(u�
    Check the source list and return the source to use

    CLI Example:

    .. code-block:: bash

        salt '*' file.source_list salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' base
    u{0}_|-{1}_|-{2}ucp.list_masterucp.list_master_dirsiufile://usaltuhttpuftpufileu(none of the specified sources were foundN(Rwt__context__R`R�R8R�tnexttiterRRturltparseRDR�R�RRR�R�R�tascii_lowercaseRRRR)tnetlocRR�RR�R(R�R�R�t
contextkeytftmfilestdtmdirstsingleRtsenvR.t
single_srctsingle_hashturlparsed_single_srcR�t
urlparsed_src((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytsource_list=s�
))
-4
		$$	$	$
cC@s|tjjjkr�|r!|ni}|r=|j|�ntjjj||dtdtd|d|dtddtdtd	t�d
}t	j
r�|jd�}q�t	jr�t
|t�r�|jd�}q�n'i}t|d<d
j|�|d<|S|S(u(
    Return the contents after applying the templating engine

    contents
        template string

    template
        template format

    context
        Overrides default context variables passed to the template.

    defaults
        Default context passed to the template.

    CLI Example:

    .. code-block:: bash

        salt '*' file.apply_template_on_contents \
            contents='This is a {{ template }} string.' \
            template=jinja \
            "context={}" "defaults={'template': 'cool'}" \
            saltenv=base
    tfrom_strRHtcontextR�tgrainsugrainstpillarRtoptsudatauutf-8uresultu.Specified template format {0} is not supporteducomment(RRt	templatestTEMPLATE_REGISTRYtupdateRR't
__pillar__R8RR�tencodetPY3R`tbytestdecodeRRw(R�ttemplateRtdefaultsR�tcontext_dictR.((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytapply_template_on_contents�s0

	

c
$K@sd}i}d�}|rKt|�}|jtjjjkrK|j}nd}tjj|j	|j�j
tj�}|d$k}|dkr�|}}tjj|�sdj
|�}di|fSnC|dkr|}tjj|�sdj
|�}di|fSn|rG|j�tjkrGdj||g�}d}n|dkr�td||	�}|sHdidj
||	�fSqK|r�|r�||�}qK|r�|jtj�r�||�}qK|sK|ryt|||||	�}WqEtk
r}di|jfSXqHd	j
tjjj|��}di|fSqKn|r|sl|tjjjkrt}td
||	�}|r|s�|r|jdd�}t|d
|�}|r�|}i|d6|d6}q||jdtd�krt}q|}n|s|r�y&td||	d|jd��}Wq�tk
r}tjjj|�}didj
||�fSXn|s�tjj|�r�tjjj|�}|idj
|�fS||kr�td��n|r|tjj j!kr�|r
|ni}|
r&|j"|
�ntjj j!||d|d|d|d|d|d|d|	d|dtdt#dtdd t|
�}n|id!j
|�fS|d"r�|d#}t|d
d�}idd6|d6}qt$|�|i|d#fSqn||dfS(%u�
    Return the managed file data for file.managed

    name
        location where the file lives on the server

    template
        template format

    source
        managed source file

    source_hash
        hash of the source file

    source_hash_name
        When ``source_hash`` refers to a remote file, this specifies the
        filename to look for in that file.

        .. versionadded:: 2016.3.5

    user
        Owner of file

    group
        Group owner of file

    mode
        Permissions of file

    attrs
        Attributes of file

        .. versionadded:: 2018.3.0

    context
        Variables to add to the template context

    defaults
        Default values of for context_dict

    skip_verify
        If ``True``, hash verification of remote file sources (``http://``,
        ``https://``, ``ftp://``) will be skipped, and the ``source_hash``
        argument will be ignored.

        .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_managed /etc/httpd/conf.d/httpd.conf jinja salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' None root root '755' base None None
    ucS@sit|dd�d6dd6S(ua
        DRY helper for getting the source_sum value from a locally cached
        path.
        R�usha256uhsumu	hash_type(R�(R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_get_local_file_source_sum0sufileu$Local file source {0} does not existu:usaltucp.hash_fileu*Source file {0} not found in saltenv '{1}'udUnable to verify upstream hash of source file {0}, please set source_hash or set skip_verify to Trueucp.is_cachedu	hash_typeusha256R�uhsumu
cp.cache_fileR�uFailed to cache {0}: {1}uSource file '{0}' not foundu-Source file cannot be the same as destinationR�R�RnRIRzR�R�RRRRugrainsRu.Specified template format {0} is not supporteduresultudata(ufileu(%R�R�RRR!R�RRRR	R�R�R)RwR�R�RR8RR�RR�Rtredact_http_basic_autht
REMOTE_PROTOSRRfR�R'RRyR
RRRRR-(R�R#R�R�R�RnRIRzR�R�RR$tskip_verifyR�Rt
source_sumR'turlparsed_sourcet
parsed_schemetparsed_pathtunix_local_sourceR*Rt
cache_refetchtcached_destthtypet
cached_sumt_sourceR%R;thsum((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytget_managed�s�F		
	

!		







cC@sctj|�}|dkr[|r:tjd|�d}ndjtt�tt��}nt	j
|�}tjd}|r�t
|t	j�s�t	j
|�}nt|�dd}tjd|s�dn||�n|r*t
|t	j�st	j
|�}ntjj|�}	t|	�dd}
n|r�t
|t	j�sTt	j
|�}nt|�}tjj|jpx|j�}t|�dd}
ng||fD]}|r�|^q�}|rtjd	|r�d
nd|s�dn|t|�dkr�dndd
j|��nd}i}tjjj|d��!}x|D]}tjjj|j��}d|d}tj||�}d}|r�|j d�}|dk	r�tjt|��}|dkr�d}q�i|d6|d6}q�n|dkr$tjd||sdn|d�qCn|dkr9|}nd�}t!}|r�|j"|�r�y6||tjkr�|||d||�t#}nWq�t$k
r�q�Xq�tj%tj&|�d|�r�|||d||�t#}q�n|r�|j"|	�rJy3||
|kr2|||d||�t#}nWq�t$k
rFq�Xq�tj%tj&|�d|�r�|||d||�t#}q�n|r+|j"|�r�y3||
|kr�|||d||�t#}nWq(t$k
r�q(Xq+tj%tj&|�d|�r+|||d||�t#}q+n|sCtjd||d|d�qCqCWWdQXx�d|fd|fd|ffD]�\}}||kr~t||�dkr�tjd||d
jg||D] }dj|d|d�^q���n||d}tjd|d|d|�|Sq~W|rRtjd |d|d�|Stjd!�dS("u0	
    .. versionchanged:: 2016.3.5
        Prior to this version, only the ``file_name`` argument was considered
        for filename matches in the hash file. This would be problematic for
        cases in which the user was relying on a remote checksum file that they
        do not control, and they wished to use a different name for that file
        on the minion from the filename on the remote server (and in the
        checksum file). For example, managing ``/tmp/myfile.tar.gz`` when the
        remote file was at ``https://mydomain.tld/different_name.tar.gz``. The
        :py:func:`file.managed <salt.states.file.managed>` state now also
        passes this function the source URI as well as the ``source_hash_name``
        (if specified). In cases where ``source_hash_name`` is specified, it
        takes precedence over both the ``file_name`` and ``source``. When it is
        not specified, ``file_name`` takes precedence over ``source``. This
        allows for better capability for matching hashes.
    .. versionchanged:: 2016.11.0
        File name and source URI matches are no longer disregarded when
        ``source_hash_name`` is specified. They will be used as fallback
        matches if there is no match to the ``source_hash_name`` value.

    This routine is called from the :mod:`file.managed
    <salt.states.file.managed>` state to pull a hash from a remote file.
    Regular expressions are used line by line on the ``source_hash`` file, to
    find a potential candidate of the indicated hash type. This avoids many
    problems of arbitrary file layout rules. It specifically permits pulling
    hash codes from debian ``*.dsc`` files.

    If no exact match of a hash and filename are found, then the first hash
    found (if any) will be returned. If no hashes at all are found, then
    ``None`` will be returned.

    For example:

    .. code-block:: yaml

        openerp_7.0-latest-1.tar.gz:
          file.managed:
            - name: /tmp/openerp_7.0-20121227-075624-1_all.deb
            - source: http://nightly.openerp.com/7.0/nightly/deb/openerp_7.0-20121227-075624-1.tar.gz
            - source_hash: http://nightly.openerp.com/7.0/nightly/deb/openerp_7.0-20121227-075624-1.dsc

    CLI Example:

    .. code-block:: bash

        salt '*' file.extract_hash /path/to/hash/file sha512 /etc/foo
    u_file.extract_hash: Unsupported hash_type '%s', falling back to matching any supported hash_typeuu{0},{1}u\/ii����uMfile.extract_hash: Extracting %s hash for file matching source_hash_name '%s'u
any supportedu5file.extract_hash: %s %s hash for file matching%s: %su0If no source_hash_name match found, will extractu
Extractingu either of the followingu, uru(?i)(?<![a-z0-9])([a-f0-9]{u})(?![a-z0-9])uhsumu	hash_typeu0file.extract_hash: In line '%s', no %shash foundu cS@s3tjd|||�|j|g�j|�dS(Nu,file.extract_hash: Line '%s' matches %s '%s'(RCR�t
setdefaultR<(R�R�t
match_typetvaluetmatched((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_add_to_matches@s
usource_hash_nameu\s+u	file_nameusourceu]file.extract_hash: Line '%s' contains %s hash '%s', but line did not meet the search criteriaNu1file.extract_hash: Multiple %s matches for %s: %su	{0} ({1})iu:file.extract_hash: Returning %s hash '%s' as a match of %suBfile.extract_hash: Returning the partially identified %s hash '%s'u-file.extract_hash: No matches, returning None('RRfRDRCRDRwtminRtmaxRRuR�t
whitespaceR`R�R�R�RRtbasenameR�R	RRRR!R�RGR�R�RERFRIRR;Rt
IndexErrorRMRg(R�R�R�R�R�R�t
hash_len_exprtfilename_separatorstsource_hash_name_idxtfile_name_basenamet
file_name_idxR,tsource_basenamet
source_idxR�tbasename_searchestpartialR�RSR�thash_ret
hash_matchR:tmatched_hsumtmatched_typeR;thash_matchedt
found_typet	found_strR.((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR��s4	!

	%
	
		


	







"	5
cC@s�tjj|�}|sCi|d6id6gd6td6}d}n|d}g|d<i}t|d|�}	|	d|d<|	d	|d
<tjjj|	d�|d<tjj	|�}
tjj
|�}|rQt|t�r�t
|�}ntjjj�rt|�t|d�ksAtjjj�rQ||dkrQ||d
<qQn|r�t|t�rut|�}ntjjj�r�t|�t|d
�ks�tjjj�r�||d
kr�||d<q�nd
|ks�d|kr�tds�tjj
|�r|rt}nt}|dkr9|d}n|dkrR|d
}ny!||||�t||�Wq�tk
r�t|d<q�Xq�n|r�t|t�r�t
|�}ntjjj�r�t|�tt|d|��kr�|dks4tjjj�r||t|d|�kr||dkr|tdtkrU||dd<q�t|d<|djdj|��q�d
|kr�|dkr�||dd<q�n|r�t|t�r�t|�}ntjjj�rt|�tt|d|��kr|dksEtjjj�r�|t|d|�kr�|dkr�tdtkrf||dd	<q�t|d<|djdj|��q�d|kr�|dkr�||dd	<q�n|dk	r�tjj
|�r�|r�q�tjjj|�}||dkr�tdtkr'||dd<q�t||�|tjjjt|��kr|t|d<|djdj|��q�||dd<q�n|dk	r|
rtjj
|�r�|r�qt||�}
|
rt d�|
D��ridj!t"|�|�d6dd6}tdtkr.||d<n�|
j#rSt$|ddd|
j#�n|
j%rxt$|ddd|
j%�nt||�}t d�|D��r�t|d<|djdj|��dj!t"|�|�|d<n
||d<|d|dkr||dd<qqnt|t&j'�r_|rE|dj(d|�ndj!|d�|d<ntdtkr�|dr�d|d<n||fS( uN
    Check the permissions on files, modify attributes and chown if needed. File
    attributes are only verified if lsattr(1) is installed.

    CLI Example:

    .. code-block:: bash

        salt '*' file.check_perms /etc/sudoers '{}' root root 400 ai

    .. versionchanged:: 2014.1.3
        ``follow_symlinks`` option added
    unameuchangesucommenturesultuRcuuseruluserugroupulgroupumodeulmodeucuserucgrouputestuFailed to change user to {0}uFailed to change group to {0}uFailed to change mode to {0}cs@s|]}|VqdS(N((Rtattr((s5/usr/lib/python2.7/site-packages/salt/modules/file.pys	<genexpr>1suoldunewR�uaddR�uremovecs@s|]}|VqdS(N((RRQ((s5/usr/lib/python2.7/site-packages/salt/modules/file.pys	<genexpr>Fsu"Failed to change attributes to {0}uattrsiu; N()RRReRRdRRR!R�R�R�R`RVRmRRRrR_RXR'R|RRDR{R~RRoR<RwRhRtR�R(RR�R�R�R�RR�R4(R�R.RnRIRzR�Rctorig_commentR�tcurtis_dirR`t
chown_funct
diff_attrstchangest	cmp_attrs((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR��s�

	

##
	







!



	
	


 

cK@s^t|||�\}}d}d}|dkr�t|||||||||||	|
|
|�
\}}}|r�t|�t|fSnt||||||||||�
}|jtj��r�x*dddgD]}|j	|d�q�Wnt|�|rKt
j|�dg}|jd�t
j|�D��ddj|�fStdj|�fS(	u
    Check to see what changes need to be made for a file

    CLI Example:

    .. code-block:: bash

        salt '*' file.check_managed /etc/httpd/conf.d/httpd.conf salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' root, root, '755' jinja True None None base
    uuuserugroupumodeu,The following values are set to be changed:
cs@s'|]\}}dj||�VqdS(u	{0}: {1}
N(Rw(RR�tval((s5/usr/lib/python2.7/site-packages/salt/modules/file.pys	<genexpr>�su$The file {0} is in the correct stateN(RRDR6R-Rtcheck_file_metaRRR R�RCtinfoR�Rt	iteritemsRRRw(R�R�R�R�RnRIRzR�R#RR$R�R�R*R�RR+tcommentsRWR�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt
check_managed`sJ



	cK@slt|||�\}}d}d
}|d
kr7t|||||||||||	|
|
|�
\}}}|r�d|kr�|dj�|d<n|r�t|�t|fS|r7|r7|r7t|�jdks�|jd�r4y t	d|d|dt
�}Wq1tk
r-}tj
d	||�q1Xq4q7nt||||||||||�
}t|�|S(u(
    Return a dictionary of what changes need to be made for a file

    CLI Example:

    .. code-block:: bash

        salt '*' file.check_managed_changes /etc/httpd/conf.d/httpd.conf salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' root, root, '755' jinja True None None base
    uuhsumusaltufileu/ucp.stat_fileR�toctaluUnable to stat %s: %sN(usaltufile(RRDR6R�R-RR�R�RR8RRyRCRDRZ(R�R�R�R�RnRIRzR�R#RR$R�R�R*t	keep_modeR�RR+R]RRW((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytcheck_managed_changes�sJ

  
c
C@s�i}
|st�}ny(t|d|jdd�dt�}Wntk
rYi}nX|sn||
d<|
Sd|kr|d|dkr|r�|r�td||d|d�}n|r
y#t||d	td
t�|
d<Wqtk
r}|j	|
d<qXqd|
d<qn|	dk	rBt
jjj
d
t
jjjdt�}
t
jjj�rztjjt|	��}	nt
jjj|
d��#}|jt
jjj|	��WdQXyt||
d
t�}Wn2tk
r}tjdj|��|j	}nXt|
�|rBtdd�r2d|
d<q?||
d<qBnt
jjj�s||dk	r�||dkr�||dkr�||
d<n|dk	r�||dkr�||dkr�||
d<nt
jjj|d�}t
jjj|�}|dk	r||kr||
d<n|r|t||�}|dk	ry|dk	rv|ddk	sf|ddk	rv||
d<qvqyq|n|
S(u�
    Check for the changes in the file metadata.

    CLI Example:

    .. code-block:: bash

        salt '*' file.check_file_meta /etc/httpd/conf.d/httpd.conf salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' root, root, '755' base

    .. note::

        Supported hash types include sha512, sha384, sha256, sha224, sha1, and
        md5.

    name
        Path to file destination

    sfn
        Template-processed source file contents

    source
        URL to file source

    source_sum
        File checksum information as a dictionary

        .. code-block:: yaml

            {hash_type: md5, hsum: <md5sum>}

    user
        Destination file user owner

    group
        Destination file group owner

    mode
        Destination file permissions mode

    attrs
        Destination file attributes

        .. versionadded:: 2018.3.0

    saltenv
        Salt environment used to resolve source files

    contents
        File contents
    R�u	hash_typeRcunewfileuhsumusumu
cp.cache_fileR�R#tshow_filenamesudiffuChecksum differsRR�uwNuFailed to diff files: {0}u
config.optionuobfuscate_templatesu<Obfuscated Template>uuseruuidugroupugidumodeiiuattrs(R�RdRfRDRRR8tget_diffRR�RRR!RR"RRRR1RR?R�R�RGRHRCReRwR-R�R�(R�RR�R+RnRIRzR�R�R�RWtlstatsRttmpttmp_R{tsmodeRV((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyRZ�s�=




 		"





cC@s||f}||f}	g}
g}x�t||	�D]�\}}
yatd||d|
�}|tkr�|jdjtjjj|���w4n|
j|�Wq4t	k
r�}|jtjjj|j
���q4q4Xq4W|r�tdd|��ng}x�|
D]�}y8tjjj
|d��}|j|j��WdQXWqttfk
r�}tdjtjjj|�|j���qXqW|d	|d
kr|r�tdd�r�d
}nP|s�d}nAt|
�}|r�|}n&|r|j|
�ntd|�}|SdS(uX
    Return unified diff of two files

    file1
        The first file to feed into the diff utility

        .. versionchanged:: 2018.3.0
            Can now be either a local or remote file. In earlier releases,
            thuis had to be a file local to the minion.

    file2
        The second file to feed into the diff utility

        .. versionchanged:: 2018.3.0
            Can now be either a local or remote file. In earlier releases, this
            had to be a file on the salt fileserver (i.e.
            ``salt://somefile.txt``)

    show_filenames : True
        Set to ``False`` to hide the filenames in the top two lines of the
        diff.

    show_changes : True
        If set to ``False``, and there are differences, then instead of a diff
        a simple message stating that show_changes is set to ``False`` will be
        returned.

    template : False
        Set to ``True`` if two templates are being compared. This is not useful
        except for within states, with the ``obfuscate_templates`` option set
        to ``True``.

        .. versionadded:: 2018.3.0

    source_hash_file1
        If ``file1`` is an http(s)/ftp URL and the file exists in the minion's
        file cache, this option can be passed to keep the minion from
        re-downloading the archive if the cached copy matches the specified
        hash.

        .. versionadded:: 2018.3.0

    source_hash_file2
        If ``file2`` is an http(s)/ftp URL and the file exists in the minion's
        file cache, this option can be passed to keep the minion from
        re-downloading the archive if the cached copy matches the specified
        hash.

        .. versionadded:: 2018.3.0

    CLI Examples:

    .. code-block:: bash

        salt '*' file.get_diff /home/fred/.vimrc salt://users/fred/.vimrc
        salt '*' file.get_diff /tmp/foo.txt /tmp/bar.txt
    u
cp.cache_fileR�uFile {0} not foundu!Failed to cache one or more filesR[urbNuFailed to read {0}: {1}iiu
config.optionuobfuscate_templatesu<Obfuscated Template>u<show_changes=False>ustringutils.get_diffu(R	R8RR<RwRRRGR�Rt__str__RR!R�R=R�R~R�R7R�R1(tfile1tfile2R�RbRPR#tsource_hash_file1tsource_hash_file2R!t
source_hashestpathsterrorstfilenameR�tcached_pathRR�RSR.tbdiff((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyRc}sZA
	"
			ustrictc#@s�tjj|�}�s=i|d6id6dd6td6�n|rfd|krf|dj�|d<n|rG�s�td||	���s�t�dj|��S|jd	t	d	�}i|d	6t
�d
|�d6}n|rGt|�jdFkrDy td
|d|	dt�}WqAt
k
r=}tjd�|�qAXqDqGntjj|�sktjj|�r�tjj|�r�|r�tjj|�}n|}|r�|o�tjj|�r�t
||jd	t	d	��}nd!}|r�|d!ks|jdt	d	�|kr��s0td||	��n�sLt�dj|��S|r�t|�jdkr�t
�|d	�}||dkr�dj|d	||d|��d<t�d<�Sntdd�r�d�dd<n_|
s�d�dd<nHy!t|�dt��dd<Wn$tk
r?}|j�dd<nXy.tjjj�|td|
�t	d�Wq�tk
r�}t��t�dj|��SXn|d!k	rdtjjjdtjjjdt�}tjj j!�rtj"j#t$|��}ntjjj%|d��[}|rWtj&d|�|j'|j(d|d |��n|j'tjj)j*|��Wd!QXy%t||dtd"|
d#t�}Wn>tk
r�}�j+d$g�j,d%j|j��d}nX|rW|�dd<y.tjjj||td|
�t	d�WqWtk
rS}t|�t�dj|��SXnt|�ntjj|�r�|r��s�td||	��n�s�t�dj|��S|r)t|�jdkr)t
�|d	�}||dkr)d&j|d	||d|��d<t�d<�Sny.tjjj�|td|
�t	d�Wn0tk
r�}t��t�dj|��SXd'�dd<ntjj j!�rt-d(|d)�d*�jd+�d,�jd-�d.�jd/�d0�jd1t�d2�jd3t���n$t-|�|||||�\�}�drid4jtjj.j/|���d<n:�dr��dr�d5jtjj.j/|���d<n�r�t��n�Stjj0|�} ���fd6�}!|r	�std||	��n�st�dj|��S|r�t|�jdkr�t
�|d	�}||dkr�d&j|d	||d|��d<t�d<�Snd7�dd<tjj1| �s,
|r�|!|||||�q	t���dj2dd!�t�d8�Sq,
n)tjj1| �sb	|r4	|!|||||�qb	t���dj2dd!�t�d8�Sntjjj3|rz	d9nd!���|d!kr�	t	d:s&
t4|�r�	d;j|��dd<<d=�d<q�	t�d>j|��Sq&
n@t	d:s&
t4|�r
d7�dd<q&
t�d?j|��SnWd!QX|d!k	r8tjjjdtjjjdt�}tjjj%|d���}|r�
tjj j!�r�
tj"j#t$|��}ntj&d|�|j'|j(d|d |��n|j'tjj)j*|��Wd!QXtjjj||td|
�t	d�t|�n=�rutjjj�|td|
�t	d�t��n|d!kr�tjj j!�r�tjjj5�}"t6d@|"AdA@�}ntjj j!�r8t-d(|d)�d*�jd+�d,�jd-�d.�jd/�d0�jd1t�d2�jd3t���n!t-|�||||�\�}�dsxdB|dC�d<nt	d:r�dB|dD�d<n*�dr��dr�dB|dE�d<n�r�t��n�Sd!S(Gu�
    Checks the destination against what was retrieved with get_managed and
    makes the appropriate modifications (if necessary).

    name
        location to place the file

    sfn
        location of cached file on the minion

        This is the path to the file stored on the minion. This file is placed
        on the minion using cp.cache_file.  If the hash sum of that file
        matches the source_sum, we do not transfer the file to the minion
        again.

        This file is then grabbed and if it has template set, it renders the
        file to be placed into the correct place on the system using
        salt.files.utils.copyfile()

    ret
        The initial state return data structure. Pass in ``None`` to use the
        default structure.

    source
        file reference on the master

    source_sum
        sum hash for source

    user
        user owner

    group
        group owner

    backup
        backup_mode

    attrs
        attributes to be set on file: '' means remove all of them

        .. versionadded:: 2018.3.0

    makedirs
        make directories if they do not exist

    template
        format of templating

    show_changes
        Include diff in state return

    contents:
        contents to be placed in the file

    dir_mode
        mode for directories created with makedirs

    skip_verify : False
        If ``True``, hash verification of remote file sources (``http://``,
        ``https://``, ``ftp://``) will be skipped, and the ``source_hash``
        argument will be ignored.

        .. versionadded:: 2016.3.0

    keep_mode : False
        If ``True``, and the ``source`` is a file from the Salt fileserver (or
        a local file on the minion), the mode of the destination file will be
        set to the mode of the source file.

        .. note:: keep_mode does not work with salt-ssh.

            As a consequence of how the files are transferred to the minion, and
            the inability to connect back to the master with salt-ssh, salt is
            unable to stat the file as it exists on the fileserver and thus
            cannot mirror the mode on the salt-ssh minion

    encoding
        If specified, then the specified encoding will be used. Otherwise, the
        file will be encoded using the system locale (usually UTF-8). See
        https://docs.python.org/3/library/codecs.html#standard-encodings for
        the list of available encodings.

        .. versionadded:: 2017.7.0

    encoding_errors : 'strict'
        Default is ```'strict'```.
        See https://docs.python.org/2/library/codecs.html#codec-base-classes
        for the error handling schemes.

        .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' file.manage_file /etc/httpd/conf.d/httpd.conf '' '{}' salt://http/httpd.conf '{hash_type: 'md5', 'hsum': <md5sum>}' root root '755' '' base ''

    .. versionchanged:: 2014.7.0
        ``follow_symlinks`` option added

    unameuchangesuucommenturesultuhsumu
cp.cache_fileuSource file '{0}' not foundu	hash_typeR�usaltufileucp.stat_fileR�R_uUnable to stat %s: %su�Specified {0} checksum for {1} ({2}) does not match actual checksum ({3}). If the 'source_hash' value refers to a remote file with multiple possible matches, then it may be necessary to set 'source_hash_name'.u
config.optionuobfuscate_templatesu<Obfuscated Template>udiffu<show_changes=False>Rbuconfig.backup_modeucachediruFailed to commit change: {0}RR�uwbuFile will be encoded with %sR�RoNRPR#uwarningsu%Failed to detect changes to file: {0}uISpecified {0} checksum for {1} ({2}) does not match actual checksum ({3})u'Replace symbolic link with regular fileRR.R�u	win_ownertgrant_permsu	win_permst
deny_permsuwin_deny_permstinheritanceuwin_inheritancetresetuwin_perms_resetuFile {0} updatedu File {0} is in the correct statec
@s�tjjj�rftjj|�\}}|rftjj|�rft��t	�dj
|��Sn|dkr|dk	rgtj
|�D]}|^q�d}xNtt|��D]:}	||	dkr�tj
t||	�dB�||	<q�q�Wdj|�}ntjjj�rztd|d�jd�d	�jd
�d�jd�d
�jdt�d�jdt��nt|d|d|d|�dS(Nu{0} drive not presenti����u0iuRR�u	win_ownerRsu	win_permsRtuwin_deny_permsRuuwin_inheritanceRvuwin_perms_resetRnRIRz(RRRRRRt
splitdriveR)R-R0RwRDRRuRR�RVRt	makedirs_RfRR(
R�tdir_modeRzRnRItdrivet_R�t	mode_listR (R�R.R(s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt_set_mode_and_make_dirsCs*
&(uNew fileuParent directory not presenti?utestufile {0} createdunewu
Empty fileuEmpty file {0} not createduFile {0} not createdi�i�uFile u updatedu not updatedu is in the correct state(usaltufileu(7RRReRR�R8R0RwRfR'R�R�R�RyRCRDR�R�R�RDRRcRR�RRR!R�R�R-RR"RRR1RR?R�R�R�RRGR�R7R<R�R;R"tdirnameR�R�t	set_umaskR�t	get_umaskR�(#R�RR.R�R+RnRIRzR�R�R�tmakedirsR#RPR�RyRcR*R`R�tencoding_errorsR�R2Rt	real_nametname_sumtdl_sumtio_errorReRfR{R{tcontain_dirR}tmask((R�R.Rs5/usr/lib/python2.7/site-packages/salt/modules/file.pytmanage_file�s�|

  $ ".



		""







$

"



"


		""



!


cC@sPtjj|�}tjj|�}tjj|�sLt||||�ntS(u�
    Ensure that a directory is available.

    CLI Example:

    .. code-block:: bash

        salt '*' file.mkdir /opt/jetty/context
    (RRReR�R�tmakedirs_permsR(tdir_pathRnRIRzt	directory((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytmkdir�s

c		C@sotjj|�}|r0tjjj|�}ntjjtjj|��}tjj	|�r�dj
|�}tj|�|Stjj
|�r�dj
|�}tj|�|Sg}xitr#tjj	|�r�Pn|j|�|}tjj|�}||kr�tdj
|���q�q�W|j�x:|D]2}tjd|�t|d|d|d|�q5WdS(	u
    Ensure that the directory containing this path is available.

    .. note::

        The path must end with a trailing slash otherwise the directory/directories
        will be created up to the parent directory. For example if path is
        ``/opt/code``, then it would be treated as ``/opt/`` but if the path
        ends with a trailing slash like ``/opt/code/``, then it would be
        treated as ``/opt/code/``.

    CLI Example:

    .. code-block:: bash

        salt '*' file.makedirs /opt/code/
    uDirectory '{0}' already existsu4The path '{0}' already exists and is not a directoryu`Recursive creation for path '{0}' would result in an infinite loop. Please use an absolute path.uCreating directory: %sRnRIRzN(RRReRRR!R�R�R~R�RwRCR�R)RR<R
treverseR�(	RRnRIRzR~R*tdirectories_to_createtcurrent_dirnametdirectory_to_create((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyRxs8
	
	


u0755c
C@stjj|�}tj}|j|�\}}|sN|j|�\}}n|r�|r�|j|�r�yt||||�Wn+tk
r�}|jtjkr��q�nX|tj	kr�dSntj
|�t|d|||r�t
dj|��nd�dS(u�
    Taken and modified from os.makedirs to set user, group and mode for each
    directory created.

    CLI Example:

    .. code-block:: bash

        salt '*' file.makedirs_perms /opt/code
    Nu{0}(RRReR�R)R�R~R�tEEXISTtcurdirR�R�RDRVRw(R�RnRIRzRtheadttailR((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�Ds&	

cC@sctjj|�}t|�s*t|�r[tj|�}tj|j�tj|j�fSdSdS(u�
    Get major/minor info from a device

    CLI Example:

    .. code-block:: bash

       salt '*' file.get_devmm /dev/chr
    iN(ii(	RRRet	is_chrdevt	is_blkdevRAtmajortst_rdevtminor(R�tstat_structure((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt	get_devmmis
cC@sjtjj|�}d}ytj|�}Wn,tk
rY}|jtjkrStS�nXtj	|j
�S(u�
    Check if a file exists and is a character device.

    CLI Example:

    .. code-block:: bash

       salt '*' file.is_chrdev /dev/chr
    N(RRReRDRAR~R�tENOENTRR�R�(R�R�R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�~s
u0660cC@sntjj|�}i|d6id6dd6td6}tjdj||||��y�tdr�idj|�d	6|d<d|d<nptj	|t
tj|�j
d
�d�tjBtj||��dkr�idj|�d	6|d<t|d<nWn>tk
r8}|jtjkr"�q9dj|�|d<nXt|d|||rct
d
j|��nd�|S(u�
    .. versionadded:: 0.17.0

    Create a character device.

    CLI Example:

    .. code-block:: bash

       salt '*' file.mknod_chrdev /dev/chr 180 31
    unameuchangesuucommenturesultu?Creating character device name:{0} major:{1} minor:{2} mode:{3}utestuCharacter device {0} created.unewu0Ooiu)File {0} exists and cannot be overwrittenu{0}N(RRReRRCR�RwR'RDtmknodRVRRuRvRAtS_IFCHRtmakedevRR~R�R�R�(R�R�R�RnRIRzR.R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytmknod_chrdev�s4



	%"cC@sjtjj|�}d}ytj|�}Wn,tk
rY}|jtjkrStS�nXtj	|j
�S(u�
    Check if a file exists and is a block device.

    CLI Example:

    .. code-block:: bash

       salt '*' file.is_blkdev /dev/blk
    N(RRReRDRAR~R�R�RR�R�(R�R�R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR��s
cC@sntjj|�}i|d6id6dd6td6}tjdj||||��y�tdr�idj|�d	6|d<d|d<nptj	|t
tj|�j
d
�d�tjBtj||��dkr�idj|�d	6|d<t|d<nWn>tk
r8}|jtjkr"�q9dj|�|d<nXt|d|||rct
d
j|��nd�|S(u�
    .. versionadded:: 0.17.0

    Create a block device.

    CLI Example:

    .. code-block:: bash

       salt '*' file.mknod_blkdev /dev/blk 8 999
    unameuchangesuucommenturesultu;Creating block device name:{0} major:{1} minor:{2} mode:{3}utestuBlock device {0} created.unewu0Ooiu)File {0} exists and cannot be overwrittenu{0}N(RRReRRCR�RwR'RDR�RVRRuRvRAtS_IFBLKR�RR~R�R�R�(R�R�R�RnRIRzR.R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytmknod_blkdev�s4



	%"cC@sjtjj|�}d}ytj|�}Wn,tk
rY}|jtjkrStS�nXtj	|j
�S(u�
    Check if a file exists and is a FIFO.

    CLI Example:

    .. code-block:: bash

       salt '*' file.is_fifo /dev/fifo
    N(RRReRDRAR~R�R�RR�R�(R�R�R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytis_fifos
cC@sOtjj|�}i|d6id6dd6td6}tjdj|��y�tdr~idj|�d	6|d<d|d<nZtj	|t
tj|�j
d
�d��dkr�idj|�d	6|d<t|d<nWn>tk
r}|jtjkr�qdj|�|d<nXt|d|||rDt
d
j|��nd�|S(u�
    .. versionadded:: 0.17.0

    Create a FIFO pipe.

    CLI Example:

    .. code-block:: bash

       salt '*' file.mknod_fifo /dev/fifo
    unameuchangesuucommenturesultuCreating FIFO name: {0}utestuFifo pipe {0} created.unewu0Ooiu)File {0} exists and cannot be overwrittenu{0}N(RRReRRCR�RwR'RDtmkfifoRVRRuRvRR~R�R�R�(R�RnRIRzR.R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt
mknod_fifo,s.



3"u0600cC@s�t}t|||�|dkr@t||||||�}nc|dkrjt||||||�}n9|dkr�t||||�}ntdj|���|S(u/
    .. versionadded:: 0.17.0

    Create a block device, character device, or fifo pipe.
    Identical to the gnu mknod.

    CLI Examples:

    .. code-block:: bash

        salt '*' file.mknod /dev/chr c 180 31
        salt '*' file.mknod /dev/blk b 8 999
        salt '*' file.nknod /dev/fifo p
    ucubupudNode type unavailable: '{0}'. Available node types are character ('c'), block ('b'), and pipe ('p').(RRxR�R�R�R
Rw(R�tntypeR�R�RnRIRzR.((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�Ysc	C@s\tjj|�}yt|�}Wn4tk
r5n$tk
rXtjd�d
}nXt	�}tjj
|�\}}tjj
j�r�|jdd�}n
|d}tjj||�}tjj|�s�iSi}x+gtj|�D]-}tjjtjj||��r�|^q�D]�}	tjj
j�rJdj|�}
ndj|�}
ytjj|	|
�}Wntk
r�q nXtjj
j�r�d}nd}|j|�|j|i�d	<tjj||	�}
tj|
�j||d
<|
||d<q Wtttttt|���gt |dt!�| D]}||^q?���S(u�
    .. versionadded:: 0.17.0

    Lists the previous versions of a file backed up using Salt's :ref:`file
    state backup <file-state-backups>` system.

    path
        The path on the minion to check for backups
    limit
        Limit the number of results to the most recent N backups

    CLI Example:

    .. code-block:: bash

        salt '*' file.list_backups /foo/bar/baz.txt
    u0file.list_backups: 'limit' value must be numericu:u_iu{0}_%a_%b_%d_%H-%M-%S_%f_%Yu{0}_%a_%b_%d_%H:%M:%S_%f_%Yu%a %b %d %Y %H-%M-%S.%fu%a %b %d %Y %H:%M:%S.%fuBackup TimeuSizeuLocationR�N("RRReRVR�RWRCReRDR9R�RRRRR�RR�R�R�RwtdatetimetstrptimeRHR7RARBR�R�R	RR�R�R(RR�tbkroott
parent_dirR?tsrc_dirtbkdirR!R�tfnametstrpfmtt	timestampt
str_formatRO((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytlist_backups~sH



	
1
		ulist_backupc
C@s�tjj|�}yt|�}Wn4tk
r5n$tk
rXtjd�d}nXt	�}tjj
|�\}}tjj||d�}tjj|�s�iSi}t
gtjgttj|��D]}|j
d�d^q��D]$\}}	|tt|	��f^q��}
tj|�}x_tj|
�D]N\}}	i}x�t|�D]�}|j
d�d}||kr\dj|�}
ytjj||
�}Wntk
r�q\nX|jd�|j|i�d<tjj||�}tj|�j||d<|||d	<q\q\Wt
tttt|	��gt|d
t�| D]}||^qR���}i||6}|j |�q=W|S(uu
    Lists the previous versions of a directory backed up using Salt's :ref:`file
    state backup <file-state-backups>` system.

    path
        The directory on the minion to check for backups
    limit
        Limit the number of results to the most recent N backups

    CLI Example:

    .. code-block:: bash

        salt '*' file.list_backups_dir /foo/bar/baz/
    u4file.list_backups_dir: 'limit' value must be numericiu_iu{0}_%a_%b_%d_%H:%M:%S_%f_%Yu%a %b %d %Y %H:%M:%S.%fuBackup TimeuSizeuLocationR�N(!RRReRVR�RWRCReRDR9R�RR�R�R#tgroupbyR�R�R�R�RR\RwR�R�RHR7RARBR	RRR(RR�R�R�R?R�R!R�R�tnRtfftssfileR�R�ROtsfilestsefiles((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytlist_backups_dir�sD



	o
N
cC@s�tjj|�}itd6dj|�d6}yQttj|��ttjt|���kr{t	|�t|�}n|SWn9t
k
r�|Stk
r�dj||�|d<|SXtj
jj|t��ytj|d|�Wn1tk
r }dj|d||�|d<|SXt|d<dj|d|�|d<tj
jj�s�ytj|�}Wn'ttfk
r�|dcd7<q�Xtj||j|j�n|S(	u�
    .. versionadded:: 0.17.0

    Restore a previous version of a file that was backed up using Salt's
    :ref:`file state backup <file-state-backups>` system.

    path
        The path on the minion to check for backups
    backup_id
        The numeric id for the backup you wish to restore, as found using
        :mod:`file.list_backups <salt.modules.file.list_backups>`

    CLI Example:

    .. code-block:: bash

        salt '*' file.restore_backup /foo/bar/baz.txt 0
    uresultuInvalid backup_id '{0}'ucommentu&backup_id '{0}' does not exist for {1}uLocationu!Unable to restore {0} to {1}: {2}u Successfully restored {0} to {1}u!, but was unable to set ownership(RRReRRwR�RRuRVR�RWR\RRR!t
backup_minionR9R�R�R�RRRRAR~RR�R�(Rt	backup_idR.R�Rtfstat((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytrestore_backups<
0


cC@s&tjj|�}itd6dj|�d6}yQttj|��ttjt|���kr{t	|�t|�}n|SWn9t
k
r�|Stk
r�dj||�|d<|SXytj|d�Wn-t
k
r}dj|d|�|d<n"Xt|d<dj|d�|d<|S(u
    .. versionadded:: 0.17.0

    Delete a previous version of a file that was backed up using Salt's
    :ref:`file state backup <file-state-backups>` system.

    path
        The path on the minion to check for backups
    backup_id
        The numeric id for the backup you wish to delete, as found using
        :mod:`file.list_backups <salt.modules.file.list_backups>`

    CLI Example:

    .. code-block:: bash

        salt '*' file.delete_backup /var/cache/salt/minion/file_backup/home/foo/bar/baz.txt 0
    uresultuInvalid backup_id '{0}'ucommentu&backup_id '{0}' does not exist for {1}uLocationuUnable to remove {0}: {1}uSuccessfully removed {0}(RRReRRwR�RRuRVR�RWR\R*R�R(RR�R.R�R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt
delete_backupCs*
0



u
remove_backupc
G@sYtjj|�}|}tj|�}|s6|}ng}x�|D]�}ytjjj|�}Wn/tk
r�tjjjt	j
|��}nXt|�dkr�tdj
|���n|j|�qCWt|t�r�dg||g|}ndg|||g}ytd|dt�}Wn(ttfk
rT}	t|	j��nX|S(u�
    Grep for a string in the specified file

    .. note::
        This function's return value is slated for refinement in future
        versions of Salt

    path
        Path to the file to be searched

        .. note::
            Globbing is supported (i.e. ``/var/log/foo/*.log``, but if globbing
            is being used then the path should be quoted to keep the shell from
            attempting to expand the glob expression.

    pattern
        Pattern to match. For example: ``test``, or ``a[0-5]``

    opts
        Additional command-line flags to pass to the grep command. For example:
        ``-v``, or ``-i -B2``

        .. note::
            The options should come after a double-dash (as shown in the
            examples below) to keep Salt's own argument parser from
            interpreting them.

    CLI Example:

    .. code-block:: bash

        salt '*' file.grep /etc/passwd nobody
        salt '*' file.grep /etc/sysconfig/network-scripts/ifcfg-eth0 ipaddr -- -i
        salt '*' file.grep /etc/sysconfig/network-scripts/ifcfg-eth0 ipaddr -- -i -B2
        salt '*' file.grep "/etc/sysconfig/network-scripts/*" ipaddr -- -i -l
    iu�Passing multiple command line arguments in a single string is not supported, please pass the following arguments separately: {0}ugrepucmd.run_allRA(RRReR�RRR�R�R�RRuR�R
RwR�R`R�R8RR�R~RR�(
RR�Rt_patht
split_optstoptR�RKR.R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pytgrepus0'	

"cC@sYi}tjd�}x6|D].}yg|t|�<Wqtk
rIqXqWi}x�|D]�}dj|�}ytjdj|��}Wntk
r�q[nXg}x9tjdj|��D]}	|jdj||	��q�Wx�|D]�}
y)|jtjjdj||
���Wntk
r1q�nXx?tjdj||
��D]"}|jdj||
|��qNWq�Wt	t
|��}x�|D]�}y#tjj|�}
tj|
�Wntk
r�q�nX|
|kr�|g||
<n+||
j|�t	t
||
��||
<||j|
�t	t
||��||<q�Wq[W|rU|S|S(	u�
    Return a list of all physical open files on the system.

    CLI Examples:

    .. code-block:: bash

        salt '*' file.open_files
        salt '*' file.open_files by_pid=True
    u/proc/u	/proc/{0}u{0}/tasku{0}/fdu
{0}/fd/{1}u{0}/task/{1}/exeu{0}/task/{1}/fdu{0}/task/{1}/fd/{2}(RR�RVRWRwR~R<RR�R�R�RA(tby_pidtpidstprocfstpfileR!tpidtppathttidstfd_tfpathttidttpathtfdpathR�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt
open_files�sR




#
"$

"cC@s
tjjS(u�
    Return the relative parent directory path symbol for underlying OS

    .. versionadded:: 2014.7.0

    This can be useful when constructing Salt Formulas.

    .. code-block:: jinja

        {% set pardir = salt['file.pardir']() %}
        {% set final_path = salt['file.join']('subdir', pardir, 'confdir') %}

    CLI Example:

    .. code-block:: bash

        salt '*' file.pardir
    (RRtpardir(((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�scC@stjj|�S(uy
    Returns Normalize path, eliminating double slashes, etc.

    .. versionadded:: 2015.5.0

    This can be useful at the CLI but is frequently useful when scripting.

    .. code-block:: jinja

        {%- from salt['file.normpath'](tpldir + '/../vars.jinja') import parent_vars %}

    CLI Example:

    .. code-block:: bash

        salt '*' file.normpath 'a/b/c/..'
    (RRR�(R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR�(scC@stjj|�S(u[
    Returns the final component of a pathname

    .. versionadded:: 2015.5.0

    This can be useful at the CLI but is frequently useful when scripting.

    .. code-block:: jinja

        {%- set filename = salt['file.basename'](source_file) %}

    CLI Example:

    .. code-block:: bash

        salt '*' file.basename 'test/test.config'
    (RRR?(R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR?=scC@stjj|�S(uz
    Returns the directory component of a pathname

    .. versionadded:: 2015.5.0

    This can be useful at the CLI but is frequently useful when scripting.

    .. code-block:: jinja

        {%- from salt['file.dirname'](tpldir) + '/vars.jinja' import parent_vars %}

    CLI Example:

    .. code-block:: bash

        salt '*' file.dirname 'test/path/filename.config'
    (RRR~(R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR~RscG@stjj|�S(u
    Return a normalized file system path for the underlying OS

    .. versionadded:: 2014.7.0

    This can be useful at the CLI but is frequently useful when scripting
    combining path variables:

    .. code-block:: jinja

        {% set www_root = '/var' %}
        {% set app_dir = 'myapp' %}

        myapp_config:
          file:
            - managed
            - name: {{ salt['file.join'](www_root, app_dir, 'config.yaml') }}

    CLI Example:

    .. code-block:: bash

        salt '*' file.join '/' 'usr' 'local' 'bin'
    (RRR(R�((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyRgscC@s�tjj|�}tjj|�}tjj|�sEtd��ntjj|�sftd��nitd6dj||�d6}ytj||�Wn4t	t
fk
r�}tdj|||���nX|S(u�
    Move a file or directory

    CLI Example:

    .. code-block:: bash

        salt '*' file.move /path/to/src /path/to/dst
    uSource path must be absolute.u"Destination path must be absolute.uresultu'{0}' moved to '{1}'ucommentu"Unable to move '{0}' to '{1}': {2}(RRReR�R
RRwR�R�R~R�R(RR�R.R((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyR��s
c
C@s�d}t�}tjj|�r=tj|�}|j}|Sx�tjjj|�D]�\}}}x|D]w}tjj	||�}	ytj|	�}Wnt
k
r�qinX|j|kr�qin|j|j�||j7}qiWqSW|}|S(u�
    Recursively calculate disk usage of path and return it
    in bytes

    CLI Example:

    .. code-block:: bash

        salt '*' file.diskusage /path/to/check
    i(
R�RRR�RARBRRtos_walkRR~R�tadd(
Rt
total_sizetseenR�R.tdirpathtdirnamest	filenamesRtfp((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt	diskusage�s&		%

(�t__doc__t
__future__RRRR�R�R�R�R#tloggingR�RRER�RAR�R�RRGR�R>RbtcollectionsRRRt	functoolsRtsalt.extRtsalt.ext.six.movesRR	tsalt.ext.six.moves.urllib.parseR
R�RYRitImportErrortsalt.utils.argsRtsalt.utils.atomicfiletsalt.utils.datatsalt.utils.filebuffertsalt.utils.filestsalt.utils.findtsalt.utils.functoolstsalt.utils.hashutilstsalt.utils.itertoolstsalt.utils.pathtsalt.utils.platformtsalt.utils.stringutilstsalt.utils.templatestsalt.utils.urltsalt.utils.usertsalt.utils.versionstsalt.exceptionsRRR
RR$RRt	getLoggert__name__RCt__func_alias__R�RR-R0R7R9R?RORUR_RXRRgRhRmRrRsRoRtR{R|RR�R�R�R�R�R�RDR�R�R�RR�R�R�R�tItLtMtStUtXR�R�R�R�R�RRR�R"R&R+R/R0R3R8R:R�R�R�RFR�R�R�R�R<R�R�R�R�R�R�R�R`RhR�R�R�R_R�RaR�R�RdR�R*R�R�R�R�R�RRR&R6R�R�R^RaRZRcR�R�RxR�R�R�R�R�R�R�R�R�R�Rtalias_functiontlist_backupR�R�R�t
remove_backupR�R�R�R�R?R~RR�R�(((s5/usr/lib/python2.7/site-packages/salt/modules/file.pyt<module>s
"
															'	.		$	+	A�	9	�P/^





	$)�	'	
5)							��q�+(R	#		H	:	0/		 					@		'		=						 	n	I���EC����@"		.	.	,G=	>	/	MP						"

Zerion Mini Shell 1.0