summaryrefslogtreecommitdiff
path: root/libmat2/__init__.py
diff options
context:
space:
mode:
authorAntoine Tenart2019-05-11 11:20:05 +0200
committerjvoisin2019-05-13 23:35:26 +0200
commitf19f6ed8b6ded81d2a1cc9d2fe606f71fcd0e27a (patch)
treed5982c72a91f2cd6a6d10e466b4b86e9937ff143 /libmat2/__init__.py
parent51ab2db2793e290f8df4791bf552e3a2531de8d4 (diff)
Rework the dependency checks to distinguish required/optional ones
Rework the dependencies definition to include a 'required' flags, which is passed by the check_dependencies helper to the callers, so that they can distinguish between required and optional dependencies. This help in two ways: - The unit test for the dependencies was now failing when an optional one was missing, due to a previous rework. - Mat2's --check-dependencies was referring to "required dependencies" and was misleading for the user as some of them could be optional. Signed-off-by: Antoine Tenart <antoine.tenart@ack.tf>
Diffstat (limited to 'libmat2/__init__.py')
-rw-r--r--libmat2/__init__.py64
1 files changed, 47 insertions, 17 deletions
diff --git a/libmat2/__init__.py b/libmat2/__init__.py
index 41c2395..501baaa 100644
--- a/libmat2/__init__.py
+++ b/libmat2/__init__.py
@@ -30,35 +30,65 @@ UNSUPPORTED_EXTENSIONS = {
30 } 30 }
31 31
32DEPENDENCIES = { 32DEPENDENCIES = {
33 'Cairo': 'cairo', 33 'Cairo': {
34 'PyGobject': 'gi', 34 'module': 'cairo',
35 'GdkPixbuf from PyGobject': 'gi.repository.GdkPixbuf', 35 'required': True,
36 'Poppler from PyGobject': 'gi.repository.Poppler', 36 },
37 'GLib from PyGobject': 'gi.repository.GLib', 37 'PyGobject': {
38 'Mutagen': 'mutagen', 38 'module': 'gi',
39 } 39 'required': True,
40 },
41 'GdkPixbuf from PyGobject': {
42 'module': 'gi.repository.GdkPixbuf',
43 'required': True,
44 },
45 'Poppler from PyGobject': {
46 'module': 'gi.repository.Poppler',
47 'required': True,
48 },
49 'GLib from PyGobject': {
50 'module': 'gi.repository.GLib',
51 'required': True,
52 },
53 'Mutagen': {
54 'module': 'mutagen',
55 'required': True,
56 },
57}
40 58
41CMD_DEPENDENCIES = { 59CMD_DEPENDENCIES = {
42 'Exiftool': exiftool._get_exiftool_path, 60 'Exiftool': {
43 'Ffmpeg': video._get_ffmpeg_path, 61 'cmd': exiftool._get_exiftool_path,
44 } 62 'required': False,
63 },
64 'Ffmpeg': {
65 'cmd': video._get_ffmpeg_path,
66 'required': False,
67 },
68}
45 69
46def check_dependencies() -> Dict[str, bool]: 70def check_dependencies() -> Dict[str, Dict[str, bool]]:
47 ret = collections.defaultdict(bool) # type: Dict[str, bool] 71 ret = collections.defaultdict(bool) # type: Dict[str, bool]
48 72
49 for key, value in DEPENDENCIES.items(): 73 for key, value in DEPENDENCIES.items():
50 ret[key] = True 74 ret[key] = {
75 'found': True,
76 'required': value['required'],
77 }
51 try: 78 try:
52 importlib.import_module(value) 79 importlib.import_module(value['module'])
53 except ImportError: # pragma: no cover 80 except ImportError: # pragma: no cover
54 ret[key] = False # pragma: no cover 81 ret[key]['found'] = False
55 82
56 for k, v in CMD_DEPENDENCIES.items(): 83 for k, v in CMD_DEPENDENCIES.items():
57 ret[k] = True 84 ret[k] = {
85 'found': True,
86 'required': v['required'],
87 }
58 try: 88 try:
59 v() 89 v['cmd']()
60 except RuntimeError: # pragma: no cover 90 except RuntimeError: # pragma: no cover
61 ret[k] = False 91 ret[k]['found'] = False
62 92
63 return ret 93 return ret
64 94