mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 22:37:41 -02:30
Support recursive mode on the file scanner
This commit is contained in:
@@ -16,6 +16,10 @@ options:
|
|||||||
description: The path containing files to be analyzed
|
description: The path containing files to be analyzed
|
||||||
required: true
|
required: true
|
||||||
default: null
|
default: null
|
||||||
|
recursive:
|
||||||
|
description: scan this directory and all subdirectories
|
||||||
|
required: false
|
||||||
|
default: no
|
||||||
get_checksum:
|
get_checksum:
|
||||||
description: Checksum files that you can access
|
description: Checksum files that you can access
|
||||||
required: false
|
required: false
|
||||||
@@ -98,6 +102,7 @@ EXAMPLES = '''
|
|||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(path=dict(required=True),
|
argument_spec = dict(path=dict(required=True),
|
||||||
|
recursive=dict(required=False, default='no', type='bool'),
|
||||||
get_checksum=dict(required=False, default='no', type='bool')))
|
get_checksum=dict(required=False, default='no', type='bool')))
|
||||||
files = []
|
files = []
|
||||||
path = module.params.get('path')
|
path = module.params.get('path')
|
||||||
@@ -106,10 +111,15 @@ def main():
|
|||||||
module.fail_json(msg = "Given path must exist and be a directory")
|
module.fail_json(msg = "Given path must exist and be a directory")
|
||||||
|
|
||||||
get_checksum = module.params.get('get_checksum')
|
get_checksum = module.params.get('get_checksum')
|
||||||
for filepath in [os.path.join(w_path, f) for w_path, w_names, w_file in os.walk(path) for f in w_file]:
|
should_recurse = module.params.get('recursive')
|
||||||
|
if not should_recurse:
|
||||||
|
path_list = [os.path.join(path, subpath) for subpath in os.listdir(path)]
|
||||||
|
else:
|
||||||
|
path_list = [os.path.join(w_path, f) for w_path, w_names, w_file in os.walk(path) for f in w_file]
|
||||||
|
for filepath in path_list:
|
||||||
try:
|
try:
|
||||||
st = os.stat(filepath)
|
st = os.stat(filepath)
|
||||||
except OSError, e:
|
except OSError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
mode = st.st_mode
|
mode = st.st_mode
|
||||||
|
|||||||
Reference in New Issue
Block a user