2018-03-19 23:43:49 +01:00
|
|
|
import mimetypes
|
2018-03-20 01:20:11 +01:00
|
|
|
import importlib
|
|
|
|
import pkgutil
|
2018-03-19 23:43:49 +01:00
|
|
|
|
2018-03-31 15:46:17 +02:00
|
|
|
from . import abstract
|
2018-03-20 01:20:11 +01:00
|
|
|
|
2018-03-31 15:46:17 +02:00
|
|
|
for module_loader, name, ispkg in pkgutil.walk_packages('.src'):
|
|
|
|
if not name.startswith('src.'):
|
2018-03-20 01:20:11 +01:00
|
|
|
continue
|
2018-03-31 15:46:17 +02:00
|
|
|
elif name == 'src.abstract':
|
2018-03-20 01:20:11 +01:00
|
|
|
continue
|
|
|
|
importlib.import_module(name)
|
2018-03-19 23:43:49 +01:00
|
|
|
|
|
|
|
def get_parser(filename: str):
|
|
|
|
mtype, _ = mimetypes.guess_type(filename)
|
|
|
|
for c in abstract.AbstractParser.__subclasses__():
|
|
|
|
if mtype in c.mimetypes:
|
|
|
|
return c(filename)
|
2018-03-31 15:46:17 +02:00
|
|
|
print('factory: %s is not supported' % mtype)
|
|
|
|
return None
|