2018-10-03 20:38:28 +02:00
|
|
|
#!/usr/bin/env python3
|
2018-05-16 22:00:37 +02:00
|
|
|
|
2018-07-10 20:49:54 +02:00
|
|
|
import collections
|
2018-09-06 11:13:11 +02:00
|
|
|
import enum
|
2018-07-10 20:49:54 +02:00
|
|
|
import importlib
|
2018-09-01 15:07:01 +02:00
|
|
|
from typing import Dict, Optional
|
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
|
|
|
|
assert Dict
|
2018-10-12 11:58:01 +02:00
|
|
|
assert Optional
|
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-03-27 18:50:25 +01:00
|
|
|
'Cairo': 'cairo',
|
|
|
|
'PyGobject': 'gi',
|
|
|
|
'GdkPixbuf from PyGobject': 'gi.repository.GdkPixbuf',
|
|
|
|
'Poppler from PyGobject': 'gi.repository.Poppler',
|
|
|
|
'GLib from PyGobject': 'gi.repository.GLib',
|
|
|
|
'Mutagen': 'mutagen',
|
2018-07-10 20:49:54 +02:00
|
|
|
}
|
|
|
|
|
2019-03-27 18:53:18 +01:00
|
|
|
CMD_DEPENDENCIES = {
|
|
|
|
'Exiftool': exiftool._get_exiftool_path,
|
|
|
|
'Ffmpeg': video._get_ffmpeg_path,
|
|
|
|
}
|
2018-09-01 15:07:01 +02:00
|
|
|
|
2018-10-23 16:32:28 +02:00
|
|
|
def check_dependencies() -> Dict[str, bool]:
|
2018-07-10 20:49:54 +02:00
|
|
|
ret = collections.defaultdict(bool) # type: Dict[str, bool]
|
|
|
|
|
|
|
|
for key, value in DEPENDENCIES.items():
|
2019-03-27 18:50:25 +01:00
|
|
|
ret[key] = True
|
2018-07-10 20:49:54 +02:00
|
|
|
try:
|
2019-03-27 18:50:25 +01:00
|
|
|
importlib.import_module(value)
|
2018-07-10 20:49:54 +02:00
|
|
|
except ImportError: # pragma: no cover
|
2019-03-27 18:50:25 +01:00
|
|
|
ret[key] = False # pragma: no cover
|
2018-07-10 20:49:54 +02:00
|
|
|
|
2019-03-27 18:53:18 +01:00
|
|
|
for key, value in CMD_DEPENDENCIES.items():
|
|
|
|
ret[key] = True
|
|
|
|
try:
|
|
|
|
value()
|
|
|
|
except RuntimeError: # pragma: no cover
|
|
|
|
ret[key] = False
|
|
|
|
|
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'
|