summaryrefslogtreecommitdiff
path: root/libmat2
diff options
context:
space:
mode:
authorjvoisin2018-07-10 20:49:54 +0200
committerjvoisin2018-07-10 21:24:26 +0200
commitd5861e46537f3e94abd26f63a3a7ad5b69d25e77 (patch)
treeb7d01595ad77fd210142afaaa8de28dfd919db3c /libmat2
parent22e3918f67b3b3517312406c70a1e71641afc7ae (diff)
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
Diffstat (limited to 'libmat2')
-rw-r--r--libmat2/__init__.py33
1 files changed, 33 insertions, 0 deletions
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 @@
1#!/bin/env python3 1#!/bin/env python3
2 2
3import os
4import collections
5import importlib
6from typing import Dict
7
8# make pyflakes happy
9assert Dict
10
3# A set of extension that aren't supported, despite matching a supported mimetype 11# A set of extension that aren't supported, despite matching a supported mimetype
4UNSUPPORTED_EXTENSIONS = { 12UNSUPPORTED_EXTENSIONS = {
5 '.asc', 13 '.asc',
@@ -17,3 +25,28 @@ UNSUPPORTED_EXTENSIONS = {
17 '.xsd', 25 '.xsd',
18 '.xsl', 26 '.xsl',
19 } 27 }
28
29DEPENDENCIES = {
30 'cairo': 'Cairo',
31 'gi': 'PyGobject',
32 'gi.repository.GdkPixbuf': 'GdkPixbuf from PyGobject',
33 'gi.repository.Poppler': 'Poppler from PyGobject',
34 'mutagen': 'Mutagen',
35 }
36
37def check_dependencies() -> dict:
38 ret = collections.defaultdict(bool) # type: Dict[str, bool]
39
40 exiftool = '/usr/bin/exiftool'
41 ret['Exiftool'] = False
42 if os.path.isfile(exiftool) and os.access(exiftool, os.X_OK): # pragma: no cover
43 ret['Exiftool'] = True
44
45 for key, value in DEPENDENCIES.items():
46 ret[value] = True
47 try:
48 importlib.import_module(key)
49 except ImportError: # pragma: no cover
50 ret[value] = False # pragma: no cover
51
52 return ret