diff options
| author | jvoisin | 2018-07-10 20:49:54 +0200 |
|---|---|---|
| committer | jvoisin | 2018-07-10 21:24:26 +0200 |
| commit | d5861e46537f3e94abd26f63a3a7ad5b69d25e77 (patch) | |
| tree | b7d01595ad77fd210142afaaa8de28dfd919db3c /libmat2/__init__.py | |
| parent | 22e3918f67b3b3517312406c70a1e71641afc7ae (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/__init__.py')
| -rw-r--r-- | libmat2/__init__.py | 33 |
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 | ||
| 3 | import os | ||
| 4 | import collections | ||
| 5 | import importlib | ||
| 6 | from typing import Dict | ||
| 7 | |||
| 8 | # make pyflakes happy | ||
| 9 | assert 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 |
| 4 | UNSUPPORTED_EXTENSIONS = { | 12 | UNSUPPORTED_EXTENSIONS = { |
| 5 | '.asc', | 13 | '.asc', |
| @@ -17,3 +25,28 @@ UNSUPPORTED_EXTENSIONS = { | |||
| 17 | '.xsd', | 25 | '.xsd', |
| 18 | '.xsl', | 26 | '.xsl', |
| 19 | } | 27 | } |
| 28 | |||
| 29 | DEPENDENCIES = { | ||
| 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 | |||
| 37 | def 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 | ||
