From d5861e46537f3e94abd26f63a3a7ad5b69d25e77 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 10 Jul 2018 20:49:54 +0200 Subject: Implement a check for dependencies in mat2 Example use: ``` $ mat2 -c Dependencies required for MAT2 0.1.3: - Cairo: yes - Exiftool: yes - GdkPixbuf from PyGobject: yes - Mutagen: yes - Poppler from PyGobject: yes - PyGobject: yes ``` This should close #35 --- libmat2/__init__.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'libmat2/__init__.py') diff --git a/libmat2/__init__.py b/libmat2/__init__.py index d910215..cd65bfc 100644 --- a/libmat2/__init__.py +++ b/libmat2/__init__.py @@ -1,5 +1,13 @@ #!/bin/env python3 +import os +import collections +import importlib +from typing import Dict + +# make pyflakes happy +assert Dict + # A set of extension that aren't supported, despite matching a supported mimetype UNSUPPORTED_EXTENSIONS = { '.asc', @@ -17,3 +25,28 @@ UNSUPPORTED_EXTENSIONS = { '.xsd', '.xsl', } + +DEPENDENCIES = { + 'cairo': 'Cairo', + 'gi': 'PyGobject', + 'gi.repository.GdkPixbuf': 'GdkPixbuf from PyGobject', + 'gi.repository.Poppler': 'Poppler from PyGobject', + 'mutagen': 'Mutagen', + } + +def check_dependencies() -> dict: + ret = collections.defaultdict(bool) # type: Dict[str, bool] + + exiftool = '/usr/bin/exiftool' + ret['Exiftool'] = False + if os.path.isfile(exiftool) and os.access(exiftool, os.X_OK): # pragma: no cover + ret['Exiftool'] = True + + for key, value in DEPENDENCIES.items(): + ret[value] = True + try: + importlib.import_module(key) + except ImportError: # pragma: no cover + ret[value] = False # pragma: no cover + + return ret -- cgit v1.3