Commit effe68f0 authored by jvoisin's avatar jvoisin

The CLI shouldn't display unsupported file extensions

parent 7afff93e
......@@ -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):
......
#!/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'])
......@@ -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():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment