diff --git a/main.py b/main.py index 0cda955..ab07641 100755 --- a/main.py +++ b/main.py @@ -8,7 +8,7 @@ import mimetypes import argparse import multiprocessing -from src import parser_factory +from src import parser_factory, unsupported_extensions __version__ = '0.1.0' @@ -74,8 +74,15 @@ def show_parsers(): print('[+] Supported formats:') for parser in parser_factory._get_parsers(): for mtype in parser.mimetypes: - extensions = ', '.join(mimetypes.guess_all_extensions(mtype)) - print(' - %s (%s)' % (mtype, extensions)) + extensions = set() + for extension in mimetypes.guess_all_extensions(mtype): + if extension[1:] not in unsupported_extensions: # skip the dot + extensions.add(extension) + if not extensions: + # we're not supporting a single extension in the current + # mimetype, so there is not point in showing the mimetype at all + continue + print(' - %s (%s)' % (mtype, ', '.join(extensions))) def __get_files_recursively(files): diff --git a/src/__init__.py b/src/__init__.py index 7557381..3f5c478 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1 +1,5 @@ -#!/bin/env python3 \ No newline at end of file +#!/bin/env python3 + +# A set of extension that aren't supported, despite matching a supported mimetype +unsupported_extensions = set(['bat', 'c', 'h', 'ksh', 'pl', 'txt', 'asc', + 'text', 'pot', 'brf', 'srt', 'rdf', 'wsdl', 'xpdl', 'xsl', 'xsd']) diff --git a/src/parser_factory.py b/src/parser_factory.py index a2ff384..2c30659 100644 --- a/src/parser_factory.py +++ b/src/parser_factory.py @@ -3,7 +3,7 @@ import mimetypes import importlib import pkgutil -from . import abstract +from . import abstract, unsupported_extensions from typing import TypeVar @@ -27,13 +27,10 @@ def _get_parsers() -> list: def get_parser(filename: str) -> (T, str): - # A set of extension that aren't supported, despite matching a known mimetype - unknown_extensions = set(['bat', 'c', 'h', 'ksh', 'pl', 'txt', 'asc', - 'text', 'pot', 'brf', 'srt', 'rdf', 'wsdl', 'xpdl', 'xsl', 'xsd']) mtype, _ = mimetypes.guess_type(filename) _, extension = os.path.splitext(filename) - if extension in unknown_extensions: + if extension in unsupported_extensions: return None, mtype for c in _get_parsers():