summaryrefslogtreecommitdiff
path: root/libmat2
diff options
context:
space:
mode:
authorjvoisin2019-10-12 16:13:49 -0700
committerjvoisin2019-10-12 16:13:49 -0700
commit5f0b3beb46d09af26107fe5f80e63ddccb127a59 (patch)
treef3d46e6e9dac60daa304d212bed62b17c019f7eb /libmat2
parent3cef7fe7fc81c1495a461a8594b1df69467536ea (diff)
Add a way to disable the sandbox
Due to bubblewrap's pickiness, mat2 can now be run without a sandbox, even if bubblewrap is installed.
Diffstat (limited to 'libmat2')
-rw-r--r--libmat2/abstract.py1
-rw-r--r--libmat2/bubblewrap.py (renamed from libmat2/subprocess.py)0
-rw-r--r--libmat2/exiftool.py22
-rw-r--r--libmat2/video.py12
4 files changed, 24 insertions, 11 deletions
diff --git a/libmat2/abstract.py b/libmat2/abstract.py
index 8861966..5cfd0f2 100644
--- a/libmat2/abstract.py
+++ b/libmat2/abstract.py
@@ -32,6 +32,7 @@ class AbstractParser(abc.ABC):
32 32
33 self.output_filename = fname + '.cleaned' + extension 33 self.output_filename = fname + '.cleaned' + extension
34 self.lightweight_cleaning = False 34 self.lightweight_cleaning = False
35 self.sandbox = True
35 36
36 @abc.abstractmethod 37 @abc.abstractmethod
37 def get_meta(self) -> Dict[str, Union[str, dict]]: 38 def get_meta(self) -> Dict[str, Union[str, dict]]:
diff --git a/libmat2/subprocess.py b/libmat2/bubblewrap.py
index fb6fc9d..fb6fc9d 100644
--- a/libmat2/subprocess.py
+++ b/libmat2/bubblewrap.py
diff --git a/libmat2/exiftool.py b/libmat2/exiftool.py
index 024f490..89081e2 100644
--- a/libmat2/exiftool.py
+++ b/libmat2/exiftool.py
@@ -2,10 +2,11 @@ import functools
2import json 2import json
3import logging 3import logging
4import os 4import os
5import subprocess
5from typing import Dict, Union, Set 6from typing import Dict, Union, Set
6 7
7from . import abstract 8from . import abstract
8from . import subprocess 9from . import bubblewrap
9 10
10# Make pyflakes happy 11# Make pyflakes happy
11assert Set 12assert Set
@@ -19,9 +20,13 @@ class ExiftoolParser(abstract.AbstractParser):
19 meta_allowlist = set() # type: Set[str] 20 meta_allowlist = set() # type: Set[str]
20 21
21 def get_meta(self) -> Dict[str, Union[str, dict]]: 22 def get_meta(self) -> Dict[str, Union[str, dict]]:
22 out = subprocess.run([_get_exiftool_path(), '-json', self.filename], 23 if self.sandbox:
23 input_filename=self.filename, 24 out = bubblewrap.run([_get_exiftool_path(), '-json', self.filename],
24 check=True, stdout=subprocess.PIPE).stdout 25 input_filename=self.filename,
26 check=True, stdout=subprocess.PIPE).stdout
27 else:
28 out = subprocess.run([_get_exiftool_path(), '-json', self.filename],
29 check=True, stdout=subprocess.PIPE).stdout
25 meta = json.loads(out.decode('utf-8'))[0] 30 meta = json.loads(out.decode('utf-8'))[0]
26 for key in self.meta_allowlist: 31 for key in self.meta_allowlist:
27 meta.pop(key, None) 32 meta.pop(key, None)
@@ -48,9 +53,12 @@ class ExiftoolParser(abstract.AbstractParser):
48 '-o', self.output_filename, 53 '-o', self.output_filename,
49 self.filename] 54 self.filename]
50 try: 55 try:
51 subprocess.run(cmd, check=True, 56 if self.sandbox:
52 input_filename=self.filename, 57 bubblewrap.run(cmd, check=True,
53 output_filename=self.output_filename) 58 input_filename=self.filename,
59 output_filename=self.output_filename)
60 else:
61 subprocess.run(cmd, check=True)
54 except subprocess.CalledProcessError as e: # pragma: no cover 62 except subprocess.CalledProcessError as e: # pragma: no cover
55 logging.error("Something went wrong during the processing of %s: %s", self.filename, e) 63 logging.error("Something went wrong during the processing of %s: %s", self.filename, e)
56 return False 64 return False
diff --git a/libmat2/video.py b/libmat2/video.py
index 1492ba1..2b33bc0 100644
--- a/libmat2/video.py
+++ b/libmat2/video.py
@@ -1,3 +1,4 @@
1import subprocess
1import functools 2import functools
2import os 3import os
3import logging 4import logging
@@ -5,7 +6,7 @@ import logging
5from typing import Dict, Union 6from typing import Dict, Union
6 7
7from . import exiftool 8from . import exiftool
8from . import subprocess 9from . import bubblewrap
9 10
10 11
11class AbstractFFmpegParser(exiftool.ExiftoolParser): 12class AbstractFFmpegParser(exiftool.ExiftoolParser):
@@ -33,9 +34,12 @@ class AbstractFFmpegParser(exiftool.ExiftoolParser):
33 '-flags:a', '+bitexact', # don't add any metadata 34 '-flags:a', '+bitexact', # don't add any metadata
34 self.output_filename] 35 self.output_filename]
35 try: 36 try:
36 subprocess.run(cmd, check=True, 37 if self.sandbox:
37 input_filename=self.filename, 38 bubblewrap.run(cmd, check=True,
38 output_filename=self.output_filename) 39 input_filename=self.filename,
40 output_filename=self.output_filename)
41 else:
42 subprocess.run(cmd, check=True)
39 except subprocess.CalledProcessError as e: 43 except subprocess.CalledProcessError as e:
40 logging.error("Something went wrong during the processing of %s: %s", self.filename, e) 44 logging.error("Something went wrong during the processing of %s: %s", self.filename, e)
41 return False 45 return False