1
0
mirror of synced 2024-11-22 09:14:23 +01:00

Improve a bit how we're handling "problematic" files in the CLI

This commit is contained in:
jvoisin 2018-06-10 00:07:49 +02:00
parent 3cba2944d7
commit 0079b4e8e9

15
mat2
View File

@ -13,7 +13,10 @@ from libmat2 import parser_factory, unsupported_extensions
__version__ = '0.1.1' __version__ = '0.1.1'
def __check_file(filename: str, mode: int = os.R_OK) -> bool: def __check_file(filename: str, mode: int = os.R_OK) -> bool:
if not os.path.isfile(filename): if not os.path.exists(filename):
print("[-] %s is doesn't exist." % filename)
return False
elif not os.path.isfile(filename):
print("[-] %s is not a regular file." % filename) print("[-] %s is not a regular file." % filename)
return False return False
elif not os.access(filename, mode): elif not os.access(filename, mode):
@ -89,12 +92,14 @@ def show_parsers():
def __get_files_recursively(files): def __get_files_recursively(files):
for f in files: for f in files:
if os.path.isfile(f): if os.path.isdir(f):
yield f
else:
for path, _, _files in os.walk(f): for path, _, _files in os.walk(f):
for _f in _files: for _f in _files:
yield os.path.join(path, _f) fname = os.path.join(path, _f)
if __check_file(fname):
yield fname
elif __check_file(f):
yield f
def main(): def main():
arg_parser = create_arg_parser() arg_parser = create_arg_parser()