1
0
mirror of synced 2024-11-22 17:24:23 +01:00
mat2/libmat2/__init__.py

101 lines
2.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2018-09-06 11:13:11 +02:00
import enum
import importlib
2019-05-14 00:46:48 +02:00
from typing import Dict, Optional, Union
from . import exiftool, video
# make pyflakes happy
assert Dict
2018-10-12 11:58:01 +02:00
assert Optional
2019-05-14 00:46:48 +02:00
assert Union
# A set of extension that aren't supported, despite matching a supported mimetype
UNSUPPORTED_EXTENSIONS = {
'.asc',
'.bat',
'.brf',
'.c',
'.h',
'.ksh',
'.pl',
'.pot',
'.rdf',
'.srt',
'.wsdl',
'.xpdl',
'.xsd',
'.xsl',
}
DEPENDENCIES = {
'Cairo': {
'module': 'cairo',
'required': True,
},
'PyGobject': {
'module': 'gi',
'required': True,
},
'GdkPixbuf from PyGobject': {
'module': 'gi.repository.GdkPixbuf',
'required': True,
},
'Poppler from PyGobject': {
'module': 'gi.repository.Poppler',
'required': True,
},
'GLib from PyGobject': {
'module': 'gi.repository.GLib',
'required': True,
},
'Mutagen': {
'module': 'mutagen',
'required': True,
},
}
CMD_DEPENDENCIES = {
'Exiftool': {
'cmd': exiftool._get_exiftool_path,
'required': False,
},
'Ffmpeg': {
'cmd': video._get_ffmpeg_path,
'required': False,
},
}
2018-09-01 15:07:01 +02:00
def check_dependencies() -> Dict[str, Dict[str, bool]]:
2019-05-14 00:46:48 +02:00
ret = dict() # type: Dict[str, dict]
for key, value in DEPENDENCIES.items():
ret[key] = {
'found': True,
'required': value['required'],
}
try:
2019-05-14 00:46:48 +02:00
importlib.import_module(value['module']) # type: ignore
except ImportError: # pragma: no cover
ret[key]['found'] = False
for k, v in CMD_DEPENDENCIES.items():
ret[k] = {
'found': True,
'required': v['required'],
}
try:
2019-05-14 00:46:48 +02:00
v['cmd']() # type: ignore
except RuntimeError: # pragma: no cover
ret[k]['found'] = False
return ret
2018-09-06 11:13:11 +02:00
@enum.unique
class UnknownMemberPolicy(enum.Enum):
ABORT = 'abort'
OMIT = 'omit'
KEEP = 'keep'