Move the handling of the cfile arguments to a separate generator function to avoid redundancy.
Unified · Split
| @@ -49,6 +49,14 @@ def print_compat(filename, compatibles): · 48 unmodified lines | |||
| 49 | else: | 49 | else: |
| 50 | print(*compatibles, sep='\n') | 50 | print(*compatibles, sep='\n') |
| 51 | 51 | ||
| 52 | def files_to_parse(path_args): | ||
| 53 | for f in path_args: | ||
| 54 | if os.path.isdir(f): | ||
| 55 | for filename in glob.iglob(f + "/**/*.c", recursive=True): | ||
| 56 | yield filename | ||
| 57 | else: | ||
| 58 | yield f | ||
| 59 | |||
| 52 | show_filename = False | 60 | show_filename = False |
| 53 | 61 | ||
| 54 | if __name__ == "__main__": | 62 | if __name__ == "__main__": |
| @@ -59,11 +67,6 @@ if __name__ == "__main__": · 4 unmodified lines | |||
| 59 | 67 | ||
| 60 | show_filename = args.with_filename | 68 | show_filename = args.with_filename |
| 61 | 69 | ||
| 62 | for f in args.cfile: | 70 | for f in files_to_parse(args.cfile): |
| 63 | if os.path.isdir(f): | 71 | compat_list = parse_compatibles(f) |
| 64 | for filename in glob.iglob(f + "/**/*.c", recursive=True): | 72 | print_compat(f, compat_list) |
| 65 | compat_list = parse_compatibles(filename) | ||
| 66 | print_compat(filename, compat_list) | ||
| 67 | else: | ||
| 68 | compat_list = parse_compatibles(f) | ||
| 69 | print_compat(f, compat_list) | ||