changed so regexes and shell globs work transparently
This commit is contained in:
parent
fdd88863d4
commit
e603b1bb69
1 changed files with 19 additions and 8 deletions
|
@ -50,9 +50,9 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: '*'
|
default: '*'
|
||||||
description:
|
description:
|
||||||
- One or more (shell type) patterns, which restrict the list of files to be returned to
|
- One or more (shell or regex) patterns, which restrict the list of files to be returned to
|
||||||
those whose basenames match at least one of the patterns specified. Multiple patterns can be
|
those whose basenames match at least one of the patterns specified. Multiple patterns can be
|
||||||
specified using a list. The patterns can be simple shell globs or a python regex prefixed by a '~'.
|
specified using a list.
|
||||||
aliases: ['pattern']
|
aliases: ['pattern']
|
||||||
contains:
|
contains:
|
||||||
required: false
|
required: false
|
||||||
|
@ -123,7 +123,7 @@ EXAMPLES = '''
|
||||||
- find: paths="/var/tmp" age="3600" age_stamp=atime recurse=yes
|
- find: paths="/var/tmp" age="3600" age_stamp=atime recurse=yes
|
||||||
|
|
||||||
# find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz via regex
|
# find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz via regex
|
||||||
- find: paths="/var/tmp" patterns="~.*\.(?:old|log\.gz)$" size="10m"
|
- find: paths="/var/tmp" patterns="^.*?\.(?:old|log\.gz)$" size="10m"
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -156,14 +156,25 @@ examined:
|
||||||
|
|
||||||
def pfilter(f, patterns=None):
|
def pfilter(f, patterns=None):
|
||||||
'''filter using glob patterns'''
|
'''filter using glob patterns'''
|
||||||
|
|
||||||
if patterns is None:
|
if patterns is None:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
match = False
|
||||||
for p in patterns:
|
for p in patterns:
|
||||||
if p.startswith('~'):
|
try:
|
||||||
r = re.compile(p[1:])
|
r = re.compile(p)
|
||||||
return r.match(f)
|
match = r.match(f)
|
||||||
else:
|
except:
|
||||||
return fnmatch.fnmatch(f, p)
|
pass
|
||||||
|
|
||||||
|
if not match:
|
||||||
|
match = fnmatch.fnmatch(f, p)
|
||||||
|
|
||||||
|
if match:
|
||||||
|
break
|
||||||
|
|
||||||
|
return match
|
||||||
|
|
||||||
|
|
||||||
def agefilter(st, now, age, timestamp):
|
def agefilter(st, now, age, timestamp):
|
||||||
|
|
Loading…
Reference in a new issue