1
0
Fork 0

The CLI shouldn't display unsupported file extensions

This commit is contained in:
jvoisin 2018-05-16 22:00:37 +02:00
parent 7afff93e9c
commit effe68f08f
3 changed files with 17 additions and 9 deletions

13
main.py
View File

@ -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):

View File

@ -1 +1,5 @@
#!/bin/env python3
#!/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'])

View File

@ -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():