From c0364b5bd133655a7755032694d4caee9cb3b36a Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 27 Mar 2015 16:51:03 -0400 Subject: [PATCH] Support recursive mode on the file scanner --- awx/plugins/library/scan_files.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/awx/plugins/library/scan_files.py b/awx/plugins/library/scan_files.py index 014987ef2c..44d0956470 100644 --- a/awx/plugins/library/scan_files.py +++ b/awx/plugins/library/scan_files.py @@ -16,6 +16,10 @@ options: description: The path containing files to be analyzed required: true default: null + recursive: + description: scan this directory and all subdirectories + required: false + default: no get_checksum: description: Checksum files that you can access required: false @@ -98,6 +102,7 @@ EXAMPLES = ''' def main(): module = AnsibleModule( argument_spec = dict(path=dict(required=True), + recursive=dict(required=False, default='no', type='bool'), get_checksum=dict(required=False, default='no', type='bool'))) files = [] path = module.params.get('path') @@ -106,10 +111,15 @@ def main(): module.fail_json(msg = "Given path must exist and be a directory") 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: st = os.stat(filepath) - except OSError, e: + except OSError: continue mode = st.st_mode