diff options
| author | tguinot | 2020-02-10 03:31:07 +0100 |
|---|---|---|
| committer | jvoisin | 2020-02-11 17:23:11 +0100 |
| commit | 56d2c4aa5fea506abb15d71b53aea23b9dd3398b (patch) | |
| tree | 16a35a9e88694e227584513d7b0e4a3499844e67 /libmat2 | |
| parent | 12f23e0150906ccfac03254276a6af4bbe74f7c8 (diff) | |
Add which pathfinding for executables
Diffstat (limited to 'libmat2')
| -rw-r--r-- | libmat2/bubblewrap.py | 7 | ||||
| -rw-r--r-- | libmat2/exiftool.py | 15 | ||||
| -rw-r--r-- | libmat2/video.py | 9 |
3 files changed, 14 insertions, 17 deletions
diff --git a/libmat2/bubblewrap.py b/libmat2/bubblewrap.py index 7a70635..8033d0a 100644 --- a/libmat2/bubblewrap.py +++ b/libmat2/bubblewrap.py | |||
| @@ -22,10 +22,9 @@ CalledProcessError = subprocess.CalledProcessError | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | def _get_bwrap_path() -> str: | 24 | def _get_bwrap_path() -> str: |
| 25 | bwrap_path = '/usr/bin/bwrap' | 25 | which_path = shutil.which('bwrap') |
| 26 | if os.path.isfile(bwrap_path): | 26 | if which_path: |
| 27 | if os.access(bwrap_path, os.X_OK): | 27 | return which_path |
| 28 | return bwrap_path | ||
| 29 | 28 | ||
| 30 | raise RuntimeError("Unable to find bwrap") # pragma: no cover | 29 | raise RuntimeError("Unable to find bwrap") # pragma: no cover |
| 31 | 30 | ||
diff --git a/libmat2/exiftool.py b/libmat2/exiftool.py index 1ce60a1..eb65b2a 100644 --- a/libmat2/exiftool.py +++ b/libmat2/exiftool.py | |||
| @@ -2,6 +2,7 @@ import functools | |||
| 2 | import json | 2 | import json |
| 3 | import logging | 3 | import logging |
| 4 | import os | 4 | import os |
| 5 | import shutil | ||
| 5 | import subprocess | 6 | import subprocess |
| 6 | from typing import Dict, Union, Set | 7 | from typing import Dict, Union, Set |
| 7 | 8 | ||
| @@ -71,14 +72,12 @@ class ExiftoolParser(abstract.AbstractParser): | |||
| 71 | 72 | ||
| 72 | @functools.lru_cache() | 73 | @functools.lru_cache() |
| 73 | def _get_exiftool_path() -> str: # pragma: no cover | 74 | def _get_exiftool_path() -> str: # pragma: no cover |
| 74 | possible_pathes = { | 75 | which_path = shutil.which('exiftool') |
| 75 | '/usr/bin/exiftool', # debian/fedora | 76 | if which_path: |
| 76 | '/usr/bin/vendor_perl/exiftool', # archlinux | 77 | return which_path |
| 77 | } | ||
| 78 | 78 | ||
| 79 | for possible_path in possible_pathes: | 79 | # Exiftool on Arch Linux has a weird path |
| 80 | if os.path.isfile(possible_path): | 80 | if os.access('/usr/bin/vendor_perl/exiftool', os.X_OK): |
| 81 | if os.access(possible_path, os.X_OK): | 81 | return '/usr/bin/vendor_perl/exiftool' |
| 82 | return possible_path | ||
| 83 | 82 | ||
| 84 | raise RuntimeError("Unable to find exiftool") | 83 | raise RuntimeError("Unable to find exiftool") |
diff --git a/libmat2/video.py b/libmat2/video.py index 2b33bc0..b4a3232 100644 --- a/libmat2/video.py +++ b/libmat2/video.py | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | import subprocess | 1 | import subprocess |
| 2 | import functools | 2 | import functools |
| 3 | import os | 3 | import shutil |
| 4 | import logging | 4 | import logging |
| 5 | 5 | ||
| 6 | from typing import Dict, Union | 6 | from typing import Dict, Union |
| @@ -137,9 +137,8 @@ class MP4Parser(AbstractFFmpegParser): | |||
| 137 | 137 | ||
| 138 | @functools.lru_cache() | 138 | @functools.lru_cache() |
| 139 | def _get_ffmpeg_path() -> str: # pragma: no cover | 139 | def _get_ffmpeg_path() -> str: # pragma: no cover |
| 140 | ffmpeg_path = '/usr/bin/ffmpeg' | 140 | which_path = shutil.which('ffmpeg') |
| 141 | if os.path.isfile(ffmpeg_path): | 141 | if which_path: |
| 142 | if os.access(ffmpeg_path, os.X_OK): | 142 | return which_path |
| 143 | return ffmpeg_path | ||
| 144 | 143 | ||
| 145 | raise RuntimeError("Unable to find ffmpeg") | 144 | raise RuntimeError("Unable to find ffmpeg") |
