2018-10-03 20:38:28 +02:00
|
|
|
#!/usr/bin/env python3
|
2018-05-16 22:00:37 +02:00
|
|
|
|
2018-09-06 11:13:11 +02:00
|
|
|
import enum
|
2018-07-10 20:49:54 +02:00
|
|
|
import importlib
|
2022-08-28 22:29:06 +02:00
|
|
|
from typing import Optional, Union
|
2018-07-10 20:49:54 +02:00
|
|
|
|
2018-10-18 19:19:56 +02:00
|
|
|
from . import exiftool, video
|
|
|
|
|
2018-07-10 20:49:54 +02:00
|
|
|
# make pyflakes happy
|
2018-10-12 11:58:01 +02:00
|
|
|
assert Optional
|
2019-05-14 00:46:48 +02:00
|
|
|
assert Union
|
2018-07-10 20:49:54 +02:00
|
|
|
|
2018-05-16 22:00:37 +02:00
|
|
|
# A set of extension that aren't supported, despite matching a supported mimetype
|
2018-07-08 22:40:36 +02:00
|
|
|
UNSUPPORTED_EXTENSIONS = {
|
2018-06-10 00:28:43 +02:00
|
|
|
'.asc',
|
|
|
|
'.bat',
|
|
|
|
'.brf',
|
|
|
|
'.c',
|
|
|
|
'.h',
|
|
|
|
'.ksh',
|
|
|
|
'.pl',
|
|
|
|
'.pot',
|
|
|
|
'.rdf',
|
|
|
|
'.srt',
|
|
|
|
'.wsdl',
|
|
|
|
'.xpdl',
|
|
|
|
'.xsd',
|
|
|
|
'.xsl',
|
|
|
|
}
|
2018-07-10 20:49:54 +02:00
|
|
|
|
|
|
|
DEPENDENCIES = {
|
2019-05-11 11:20:05 +02:00
|
|
|
'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,
|
|
|
|
},
|
|
|
|
}
|
2018-07-10 20:49:54 +02:00
|
|
|
|
2019-03-27 18:53:18 +01:00
|
|
|
CMD_DEPENDENCIES = {
|
2019-05-11 11:20:05 +02:00
|
|
|
'Exiftool': {
|
|
|
|
'cmd': exiftool._get_exiftool_path,
|
|
|
|
'required': False,
|
|
|
|
},
|
|
|
|
'Ffmpeg': {
|
|
|
|
'cmd': video._get_ffmpeg_path,
|
|
|
|
'required': False,
|
|
|
|
},
|
|
|
|
}
|
2018-09-01 15:07:01 +02:00
|
|
|
|
2022-08-28 22:29:06 +02:00
|
|
|
def check_dependencies() -> dict[str, dict[str, bool]]:
|
|
|
|
ret = dict() # type: dict[str, dict]
|
2018-07-10 20:49:54 +02:00
|
|
|
|
|
|
|
for key, value in DEPENDENCIES.items():
|
2019-05-11 11:20:05 +02:00
|
|
|
ret[key] = {
|
|
|
|
'found': True,
|
|
|
|
'required': value['required'],
|
|
|
|
}
|
2018-07-10 20:49:54 +02:00
|
|
|
try:
|
2019-05-14 00:46:48 +02:00
|
|
|
importlib.import_module(value['module']) # type: ignore
|
2018-07-10 20:49:54 +02:00
|
|
|
except ImportError: # pragma: no cover
|
2019-05-11 11:20:05 +02:00
|
|
|
ret[key]['found'] = False
|
2018-07-10 20:49:54 +02:00
|
|
|
|
2019-03-30 10:31:50 +01:00
|
|
|
for k, v in CMD_DEPENDENCIES.items():
|
2019-05-11 11:20:05 +02:00
|
|
|
ret[k] = {
|
|
|
|
'found': True,
|
|
|
|
'required': v['required'],
|
|
|
|
}
|
2019-03-27 18:53:18 +01:00
|
|
|
try:
|
2019-05-14 00:46:48 +02:00
|
|
|
v['cmd']() # type: ignore
|
2019-03-27 18:53:18 +01:00
|
|
|
except RuntimeError: # pragma: no cover
|
2019-05-11 11:20:05 +02:00
|
|
|
ret[k]['found'] = False
|
2019-03-27 18:53:18 +01:00
|
|
|
|
2018-07-10 20:49:54 +02:00
|
|
|
return ret
|
2018-09-06 00:49:35 +02:00
|
|
|
|
2019-02-03 10:43:27 +01:00
|
|
|
|
2018-09-06 11:13:11 +02:00
|
|
|
@enum.unique
|
|
|
|
class UnknownMemberPolicy(enum.Enum):
|
2018-09-06 00:49:35 +02:00
|
|
|
ABORT = 'abort'
|
|
|
|
OMIT = 'omit'
|
|
|
|
KEEP = 'keep'
|