Yield interesting Python script paths that have a name in `interesting_names` by walking the `location` directory recursively up to `max_depth` path segments extending from the root `location`.
(location, max_depth=1, interesting_names=())
| 2884 | |
| 2885 | |
| 2886 | def get_module_scripts(location, max_depth=1, interesting_names=()): |
| 2887 | """ |
| 2888 | Yield interesting Python script paths that have a name in |
| 2889 | `interesting_names` by walking the `location` directory recursively up to |
| 2890 | `max_depth` path segments extending from the root `location`. |
| 2891 | """ |
| 2892 | if TRACE: |
| 2893 | logger_debug( |
| 2894 | ' get_module_scripts():', |
| 2895 | 'location:', location, |
| 2896 | 'max_depth:', max_depth, |
| 2897 | 'interesting_names:', interesting_names |
| 2898 | ) |
| 2899 | |
| 2900 | location = location.rstrip(os.path.sep) |
| 2901 | if TRACE: logger_debug(' get_module_scripts:', 'location:', location) |
| 2902 | |
| 2903 | for top, _dirs, files in os.walk(location): |
| 2904 | current_depth = compute_path_depth(location, top) |
| 2905 | if TRACE: |
| 2906 | logger_debug(' get_module_scripts:', 'current_depth:', current_depth) |
| 2907 | logger_debug(' get_module_scripts:', 'top:', top, '_dirs:', _dirs, 'files:', files) |
| 2908 | if current_depth >= max_depth: |
| 2909 | break |
| 2910 | for f in files: |
| 2911 | if TRACE: logger_debug(' get_module_scripts:', 'file:', f) |
| 2912 | |
| 2913 | if f in interesting_names: |
| 2914 | path = os.path.join(top, f) |
| 2915 | if TRACE: logger_debug(' get_module_scripts:', 'path:', path) |
| 2916 | yield path |
| 2917 | |
| 2918 | |
| 2919 | def compute_path_depth(base, path): |
no test coverage detected