mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #49837 from mchugh19/2747
Support list for include_pat/exclude_pat in file.recurse
This commit is contained in:
commit
c1b6706011
@ -3636,8 +3636,8 @@ def recurse(name,
|
|||||||
:ref:`backup_mode documentation <file-state-backups>` for more details.
|
:ref:`backup_mode documentation <file-state-backups>` for more details.
|
||||||
|
|
||||||
include_pat
|
include_pat
|
||||||
When copying, include only this pattern from the source. Default
|
When copying, include only this pattern, or list of patterns, from the
|
||||||
is glob match; if prefixed with 'E@', then regexp match.
|
source. Default is glob match; if prefixed with 'E@', then regexp match.
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
@ -3647,9 +3647,19 @@ def recurse(name,
|
|||||||
- include_pat: E@hello :: regexp matches 'otherhello',
|
- include_pat: E@hello :: regexp matches 'otherhello',
|
||||||
'hello01' ...
|
'hello01' ...
|
||||||
|
|
||||||
|
.. versionchanged:: Neon
|
||||||
|
|
||||||
|
List patterns are now supported
|
||||||
|
|
||||||
|
.. code-block:: text
|
||||||
|
|
||||||
|
- include_pat:
|
||||||
|
- hello01
|
||||||
|
- hello02
|
||||||
|
|
||||||
exclude_pat
|
exclude_pat
|
||||||
Exclude this pattern from the source when copying. If both
|
Exclude this pattern, or list of patterns, from the source when copying.
|
||||||
`include_pat` and `exclude_pat` are supplied, then it will apply
|
If both `include_pat` and `exclude_pat` are supplied, then it will apply
|
||||||
conditions cumulatively. i.e. first select based on include_pat, and
|
conditions cumulatively. i.e. first select based on include_pat, and
|
||||||
then within that result apply exclude_pat.
|
then within that result apply exclude_pat.
|
||||||
|
|
||||||
@ -3664,6 +3674,15 @@ def recurse(name,
|
|||||||
- exclude_pat: E@(APPDATA)|(TEMPDATA) :: regexp matches APPDATA
|
- exclude_pat: E@(APPDATA)|(TEMPDATA) :: regexp matches APPDATA
|
||||||
or TEMPDATA for exclusion
|
or TEMPDATA for exclusion
|
||||||
|
|
||||||
|
.. versionchanged:: Neon
|
||||||
|
List patterns are now supported
|
||||||
|
|
||||||
|
.. code-block:: text
|
||||||
|
|
||||||
|
- exclude_pat:
|
||||||
|
- APPDATA.01
|
||||||
|
- APPDATA.02
|
||||||
|
|
||||||
maxdepth
|
maxdepth
|
||||||
When copying, only copy paths which are of depth `maxdepth` from the
|
When copying, only copy paths which are of depth `maxdepth` from the
|
||||||
source path.
|
source path.
|
||||||
|
@ -450,31 +450,37 @@ def check_include_exclude(path_str, include_pat=None, exclude_pat=None):
|
|||||||
- If both include_pat and exclude_pat are supplied: return 'True' if
|
- If both include_pat and exclude_pat are supplied: return 'True' if
|
||||||
include_pat matches AND exclude_pat does not match
|
include_pat matches AND exclude_pat does not match
|
||||||
'''
|
'''
|
||||||
|
def _pat_check(path_str, check_pat):
|
||||||
|
if re.match('E@', check_pat):
|
||||||
|
return True if re.search(
|
||||||
|
check_pat[2:],
|
||||||
|
path_str
|
||||||
|
) else False
|
||||||
|
else:
|
||||||
|
return True if fnmatch.fnmatch(
|
||||||
|
path_str,
|
||||||
|
check_pat
|
||||||
|
) else False
|
||||||
|
|
||||||
ret = True # -- default true
|
ret = True # -- default true
|
||||||
# Before pattern match, check if it is regexp (E@'') or glob(default)
|
# Before pattern match, check if it is regexp (E@'') or glob(default)
|
||||||
if include_pat:
|
if include_pat:
|
||||||
if re.match('E@', include_pat):
|
if isinstance(include_pat, list):
|
||||||
retchk_include = True if re.search(
|
for include_line in include_pat:
|
||||||
include_pat[2:],
|
retchk_include = _pat_check(path_str, include_line)
|
||||||
path_str
|
if retchk_include:
|
||||||
) else False
|
break
|
||||||
else:
|
else:
|
||||||
retchk_include = True if fnmatch.fnmatch(
|
retchk_include = _pat_check(path_str, include_pat)
|
||||||
path_str,
|
|
||||||
include_pat
|
|
||||||
) else False
|
|
||||||
|
|
||||||
if exclude_pat:
|
if exclude_pat:
|
||||||
if re.match('E@', exclude_pat):
|
if isinstance(exclude_pat, list):
|
||||||
retchk_exclude = False if re.search(
|
for exclude_line in exclude_pat:
|
||||||
exclude_pat[2:],
|
retchk_exclude = not _pat_check(path_str, exclude_line)
|
||||||
path_str
|
if not retchk_exclude:
|
||||||
) else True
|
break
|
||||||
else:
|
else:
|
||||||
retchk_exclude = False if fnmatch.fnmatch(
|
retchk_exclude = not _pat_check(path_str, exclude_pat)
|
||||||
path_str,
|
|
||||||
exclude_pat
|
|
||||||
) else True
|
|
||||||
|
|
||||||
# Now apply include/exclude conditions
|
# Now apply include/exclude conditions
|
||||||
if include_pat and not exclude_pat:
|
if include_pat and not exclude_pat:
|
||||||
|
@ -548,3 +548,18 @@ class StringutilsTestCase(TestCase):
|
|||||||
salt.utils.stringutils.check_whitelist_blacklist,
|
salt.utils.stringutils.check_whitelist_blacklist,
|
||||||
'foo', blacklist=123
|
'foo', blacklist=123
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_check_include_exclude_empty(self):
|
||||||
|
self.assertTrue(salt.utils.stringutils.check_include_exclude("/some/test"))
|
||||||
|
|
||||||
|
def test_check_include_exclude_exclude(self):
|
||||||
|
self.assertFalse(salt.utils.stringutils.check_include_exclude("/some/test", None, "*test*"))
|
||||||
|
|
||||||
|
def test_check_include_exclude_exclude_list(self):
|
||||||
|
self.assertFalse(salt.utils.stringutils.check_include_exclude("/some/test", None, ["*test"]))
|
||||||
|
|
||||||
|
def test_check_include_exclude_exclude_include(self):
|
||||||
|
self.assertTrue(salt.utils.stringutils.check_include_exclude("/some/test", "*test*", "/some/"))
|
||||||
|
|
||||||
|
def test_check_include_exclude_regex(self):
|
||||||
|
self.assertFalse(salt.utils.stringutils.check_include_exclude("/some/test", None, "E@/some/(test|other)"))
|
||||||
|
Loading…
Reference in New Issue
Block a user