diff options
| author | jvoisin | 2018-04-04 23:15:00 +0200 |
|---|---|---|
| committer | jvoisin | 2018-04-04 23:15:00 +0200 |
| commit | 972de8469e8827f2c5c1e4350104411e322986e1 (patch) | |
| tree | ca67ad55b7da149af5e8934c72ca6c832591b041 /main.py | |
| parent | d3b1eabe075e5f972c85979e6da4630be2c15a83 (diff) | |
main.py is now correctly handling folders
Diffstat (limited to 'main.py')
| -rwxr-xr-x | main.py | 38 |
1 files changed, 27 insertions, 11 deletions
| @@ -1,4 +1,5 @@ | |||
| 1 | #!/usr/bin/python3 | 1 | #!/usr/bin/python3 |
| 2 | |||
| 2 | import os | 3 | import os |
| 3 | import sys | 4 | import sys |
| 4 | import mimetypes | 5 | import mimetypes |
| @@ -54,24 +55,39 @@ def clean_meta(filename:str): | |||
| 54 | return | 55 | return |
| 55 | p.remove_all() | 56 | p.remove_all() |
| 56 | 57 | ||
| 58 | def show_parsers(): | ||
| 59 | print('[+] Supported formats:') | ||
| 60 | for parser in parser_factory._get_parsers(): | ||
| 61 | for mtype in parser.mimetypes: | ||
| 62 | extensions = ', '.join(mimetypes.guess_all_extensions(mtype)) | ||
| 63 | print(' - %s (%s)' % (mtype, extensions)) | ||
| 64 | |||
| 65 | def __get_files_recursively(files): | ||
| 66 | for f in files: | ||
| 67 | if os.path.isfile(f): | ||
| 68 | yield f | ||
| 69 | else: | ||
| 70 | for path, _, _files in os.walk(f): | ||
| 71 | for _f in _files: | ||
| 72 | yield os.path.join(path, _f) | ||
| 73 | |||
| 74 | |||
| 57 | def main(): | 75 | def main(): |
| 58 | arg_parser = create_arg_parser() | 76 | arg_parser = create_arg_parser() |
| 59 | args = arg_parser.parse_args() | 77 | args = arg_parser.parse_args() |
| 60 | 78 | ||
| 79 | if not args.files: | ||
| 80 | if not args.list: | ||
| 81 | return arg_parser.print_help() | ||
| 82 | show_parsers() | ||
| 83 | return | ||
| 84 | |||
| 61 | if args.show: | 85 | if args.show: |
| 62 | for f in args.files: | 86 | for f in get_files_recursively(args.files): |
| 63 | show_meta(f) | 87 | show_meta(f) |
| 64 | elif args.list: | ||
| 65 | print('[+] Supported formats:') | ||
| 66 | for parser in parser_factory._get_parsers(): | ||
| 67 | for mtype in parser.mimetypes: | ||
| 68 | extensions = ', '.join(mimetypes.guess_all_extensions(mtype)) | ||
| 69 | print(' - %s (%s)' % (mtype, extensions)) | ||
| 70 | elif args.files: | ||
| 71 | for f in args.files: | ||
| 72 | clean_meta(f) | ||
| 73 | else: | 88 | else: |
| 74 | arg_parser.print_help() | 89 | for f in get_files_recursively(args.files): |
| 90 | clean_meta(f) | ||
| 75 | 91 | ||
| 76 | 92 | ||
| 77 | if __name__ == '__main__': | 93 | if __name__ == '__main__': |
