diff options
| author | jvoisin | 2018-05-16 22:00:37 +0200 |
|---|---|---|
| committer | jvoisin | 2018-05-16 22:00:37 +0200 |
| commit | effe68f08f19ff26c37ede5a7a92d5d4452434fe (patch) | |
| tree | dec62d6d94236380cf2597fc083ea3f450d56f46 /src | |
| parent | 7afff93e9c5f04b72725c0008cbf5657a0497be0 (diff) | |
The CLI shouldn't display unsupported file extensions
Diffstat (limited to 'src')
| -rw-r--r-- | src/__init__.py | 6 | ||||
| -rw-r--r-- | src/parser_factory.py | 7 |
2 files changed, 7 insertions, 6 deletions
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 @@ | |||
| 1 | #!/bin/env python3 \ No newline at end of file | 1 | #!/bin/env python3 |
| 2 | |||
| 3 | # A set of extension that aren't supported, despite matching a supported mimetype | ||
| 4 | unsupported_extensions = set(['bat', 'c', 'h', 'ksh', 'pl', 'txt', 'asc', | ||
| 5 | '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 | |||
| 3 | import importlib | 3 | import importlib |
| 4 | import pkgutil | 4 | import pkgutil |
| 5 | 5 | ||
| 6 | from . import abstract | 6 | from . import abstract, unsupported_extensions |
| 7 | 7 | ||
| 8 | from typing import TypeVar | 8 | from typing import TypeVar |
| 9 | 9 | ||
| @@ -27,13 +27,10 @@ def _get_parsers() -> list: | |||
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | def get_parser(filename: str) -> (T, str): | 29 | def get_parser(filename: str) -> (T, str): |
| 30 | # A set of extension that aren't supported, despite matching a known mimetype | ||
| 31 | unknown_extensions = set(['bat', 'c', 'h', 'ksh', 'pl', 'txt', 'asc', | ||
| 32 | 'text', 'pot', 'brf', 'srt', 'rdf', 'wsdl', 'xpdl', 'xsl', 'xsd']) | ||
| 33 | mtype, _ = mimetypes.guess_type(filename) | 30 | mtype, _ = mimetypes.guess_type(filename) |
| 34 | 31 | ||
| 35 | _, extension = os.path.splitext(filename) | 32 | _, extension = os.path.splitext(filename) |
| 36 | if extension in unknown_extensions: | 33 | if extension in unsupported_extensions: |
| 37 | return None, mtype | 34 | return None, mtype |
| 38 | 35 | ||
| 39 | for c in _get_parsers(): | 36 | for c in _get_parsers(): |
