From 56d2c4aa5fea506abb15d71b53aea23b9dd3398b Mon Sep 17 00:00:00 2001
From: tguinot <thomas.guinot@gmail.com>
Date: Mon, 10 Feb 2020 03:31:07 +0100
Subject: [PATCH] Add which pathfinding for executables

---
 README.md             |  6 ++++++
 libmat2/bubblewrap.py |  7 +++----
 libmat2/exiftool.py   | 15 +++++++--------
 libmat2/video.py      |  9 ++++-----
 4 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/README.md b/README.md
index 2aeb493..4e6a696 100644
--- a/README.md
+++ b/README.md
@@ -41,6 +41,12 @@ Nautilus, the default file manager of GNOME.
 
 Please note that mat2 requires at least Python3.5.
 
+# Requirements setup on macOS (OS X) using [Homebrew](https://brew.sh/)
+
+```bash
+brew install exiftool cairo pygobject3 poppler gdk-pixbuf librsvg ffmpeg
+```
+
 # Running the test suite
 
 ```bash
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
 
 
 def _get_bwrap_path() -> str:
-    bwrap_path = '/usr/bin/bwrap'
-    if os.path.isfile(bwrap_path):
-        if os.access(bwrap_path, os.X_OK):
-            return bwrap_path
+    which_path = shutil.which('bwrap')
+    if which_path:
+        return which_path
 
     raise RuntimeError("Unable to find bwrap")  # pragma: no cover
 
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
 import json
 import logging
 import os
+import shutil
 import subprocess
 from typing import Dict, Union, Set
 
@@ -71,14 +72,12 @@ class ExiftoolParser(abstract.AbstractParser):
 
 @functools.lru_cache()
 def _get_exiftool_path() -> str:  # pragma: no cover
-    possible_pathes = {
-        '/usr/bin/exiftool',              # debian/fedora
-        '/usr/bin/vendor_perl/exiftool',  # archlinux
-    }
+    which_path = shutil.which('exiftool')
+    if which_path:
+        return which_path
 
-    for possible_path in possible_pathes:
-        if os.path.isfile(possible_path):
-            if os.access(possible_path, os.X_OK):
-                return possible_path
+    # Exiftool on Arch Linux has a weird path
+    if os.access('/usr/bin/vendor_perl/exiftool', os.X_OK):
+        return '/usr/bin/vendor_perl/exiftool'
 
     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 @@
 import subprocess
 import functools
-import os
+import shutil
 import logging
 
 from typing import Dict, Union
@@ -137,9 +137,8 @@ class MP4Parser(AbstractFFmpegParser):
 
 @functools.lru_cache()
 def _get_ffmpeg_path() -> str:  # pragma: no cover
-    ffmpeg_path = '/usr/bin/ffmpeg'
-    if os.path.isfile(ffmpeg_path):
-        if os.access(ffmpeg_path, os.X_OK):
-            return ffmpeg_path
+    which_path = shutil.which('ffmpeg')
+    if which_path:
+        return which_path
 
     raise RuntimeError("Unable to find ffmpeg")
-- 
GitLab