1
0
mirror of synced 2024-11-22 09:14:23 +01:00
mat2/libmat2/__init__.py
Antoine Tenart d454ef5b8e libmat2: fix dependency checks for cmd line utilities
The command line checks for command line utilities are done by trying to
access the executables and by throwing an exception when not found. This
lead to:
- The mat2 cmd line --check-dependencies option failing.
- The ffmpeg unit tests failing when ffmpeg isn't installed (even though
  it's an optional dependency).

This patch fixes it.

Signed-off-by: Antoine Tenart <antoine.tenart@ack.tf>
2019-03-29 19:29:28 +01:00

71 lines
1.4 KiB
Python

#!/usr/bin/env python3
import collections
import enum
import importlib
from typing import Dict, Optional
from . import exiftool, video
# make pyflakes happy
assert Dict
assert Optional
# 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': 'cairo',
'PyGobject': 'gi',
'GdkPixbuf from PyGobject': 'gi.repository.GdkPixbuf',
'Poppler from PyGobject': 'gi.repository.Poppler',
'GLib from PyGobject': 'gi.repository.GLib',
'Mutagen': 'mutagen',
}
CMD_DEPENDENCIES = {
'Exiftool': exiftool._get_exiftool_path,
'Ffmpeg': video._get_ffmpeg_path,
}
def check_dependencies() -> Dict[str, bool]:
ret = collections.defaultdict(bool) # type: Dict[str, bool]
for key, value in DEPENDENCIES.items():
ret[key] = True
try:
importlib.import_module(value)
except ImportError: # pragma: no cover
ret[key] = False # pragma: no cover
for key, value in CMD_DEPENDENCIES.items():
ret[key] = True
try:
value()
except RuntimeError: # pragma: no cover
ret[key] = False
return ret
@enum.unique
class UnknownMemberPolicy(enum.Enum):
ABORT = 'abort'
OMIT = 'omit'
KEEP = 'keep'