diff options
| author | jvoisin | 2018-04-03 23:57:13 +0200 |
|---|---|---|
| committer | jvoisin | 2018-04-03 23:57:13 +0200 |
| commit | afeb3753a80bfd43ae1419b77b15d318c709708d (patch) | |
| tree | ee90309e9c83dbd2154d0ce103b74e79b494ef76 /src/parser_factory.py | |
| parent | 1d6559596df74c8af8d699a6709f7155400b9f98 (diff) | |
Improve the cli
- Implement the `-l` option
- The help is now more awesome
Diffstat (limited to 'src/parser_factory.py')
| -rw-r--r-- | src/parser_factory.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/parser_factory.py b/src/parser_factory.py index 770f17c..7ce4246 100644 --- a/src/parser_factory.py +++ b/src/parser_factory.py | |||
| @@ -16,12 +16,17 @@ for module_loader, name, ispkg in pkgutil.walk_packages('.src'): | |||
| 16 | continue | 16 | continue |
| 17 | importlib.import_module(name) | 17 | importlib.import_module(name) |
| 18 | 18 | ||
| 19 | def _get_parsers() -> list: | ||
| 20 | """ Get all our parsers!""" | ||
| 21 | def __get_parsers(cls): | ||
| 22 | return cls.__subclasses__() + \ | ||
| 23 | [g for s in cls.__subclasses__() for g in __get_parsers(s)] | ||
| 24 | return __get_parsers(abstract.AbstractParser) | ||
| 25 | |||
| 19 | def get_parser(filename: str) -> (T, str): | 26 | def get_parser(filename: str) -> (T, str): |
| 20 | mtype, _ = mimetypes.guess_type(filename) | 27 | mtype, _ = mimetypes.guess_type(filename) |
| 21 | def get_subclasses(cls): | 28 | |
| 22 | return cls.__subclasses__() + \ | 29 | for c in _get_parsers(): |
| 23 | [g for s in cls.__subclasses__() for g in get_subclasses(s)] | ||
| 24 | for c in get_subclasses(abstract.AbstractParser): | ||
| 25 | if mtype in c.mimetypes: | 30 | if mtype in c.mimetypes: |
| 26 | return c(filename), mtype | 31 | return c(filename), mtype |
| 27 | return None, mtype | 32 | return None, mtype |
