diff options
| author | jvoisin | 2018-06-10 00:07:49 +0200 |
|---|---|---|
| committer | jvoisin | 2018-06-10 00:07:49 +0200 |
| commit | 0079b4e8e92ea89a2ce692fa3ca0cedf51c002a1 (patch) | |
| tree | b95d0c2e4cc7e89308aa71974e7428645cd54dfe | |
| parent | 3cba2944d70b8f5675eeb1bc0f50b71ce4065548 (diff) | |
Improve a bit how we're handling "problematic" files in the CLI
| -rwxr-xr-x | mat2 | 15 |
1 files changed, 10 insertions, 5 deletions
| @@ -13,7 +13,10 @@ from libmat2 import parser_factory, unsupported_extensions | |||
| 13 | __version__ = '0.1.1' | 13 | __version__ = '0.1.1' |
| 14 | 14 | ||
| 15 | def __check_file(filename: str, mode: int = os.R_OK) -> bool: | 15 | def __check_file(filename: str, mode: int = os.R_OK) -> bool: |
| 16 | if not os.path.isfile(filename): | 16 | if not os.path.exists(filename): |
| 17 | print("[-] %s is doesn't exist." % filename) | ||
| 18 | return False | ||
| 19 | elif not os.path.isfile(filename): | ||
| 17 | print("[-] %s is not a regular file." % filename) | 20 | print("[-] %s is not a regular file." % filename) |
| 18 | return False | 21 | return False |
| 19 | elif not os.access(filename, mode): | 22 | elif not os.access(filename, mode): |
| @@ -89,12 +92,14 @@ def show_parsers(): | |||
| 89 | 92 | ||
| 90 | def __get_files_recursively(files): | 93 | def __get_files_recursively(files): |
| 91 | for f in files: | 94 | for f in files: |
| 92 | if os.path.isfile(f): | 95 | if os.path.isdir(f): |
| 93 | yield f | ||
| 94 | else: | ||
| 95 | for path, _, _files in os.walk(f): | 96 | for path, _, _files in os.walk(f): |
| 96 | for _f in _files: | 97 | for _f in _files: |
| 97 | yield os.path.join(path, _f) | 98 | fname = os.path.join(path, _f) |
| 99 | if __check_file(fname): | ||
| 100 | yield fname | ||
| 101 | elif __check_file(f): | ||
| 102 | yield f | ||
| 98 | 103 | ||
| 99 | def main(): | 104 | def main(): |
| 100 | arg_parser = create_arg_parser() | 105 | arg_parser = create_arg_parser() |
