summaryrefslogtreecommitdiff
path: root/libmat2/exiftool.py
diff options
context:
space:
mode:
authorintrigeri2019-02-03 09:43:27 +0000
committerjvoisin2019-02-03 19:18:41 +0100
commite8c1bb0e3c4cae579e81ce6a4b01b829900ff922 (patch)
treecd7146283c98f25544334cdd322b8c577ccc40d3 /libmat2/exiftool.py
parent8b5d0c286c91537b43eb3284aa93b382636e7ebf (diff)
Whenever possible, use bwrap for subprocesses
This should closes #90
Diffstat (limited to 'libmat2/exiftool.py')
-rw-r--r--libmat2/exiftool.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/libmat2/exiftool.py b/libmat2/exiftool.py
index adec28e..db92f60 100644
--- a/libmat2/exiftool.py
+++ b/libmat2/exiftool.py
@@ -1,10 +1,10 @@
1import json 1import json
2import logging 2import logging
3import os 3import os
4import subprocess
5from typing import Dict, Union, Set 4from typing import Dict, Union, Set
6 5
7from . import abstract 6from . import abstract
7from . import subprocess
8 8
9# Make pyflakes happy 9# Make pyflakes happy
10assert Set 10assert Set
@@ -18,7 +18,9 @@ class ExiftoolParser(abstract.AbstractParser):
18 meta_whitelist = set() # type: Set[str] 18 meta_whitelist = set() # type: Set[str]
19 19
20 def get_meta(self) -> Dict[str, Union[str, dict]]: 20 def get_meta(self) -> Dict[str, Union[str, dict]]:
21 out = subprocess.check_output([_get_exiftool_path(), '-json', self.filename]) 21 out = subprocess.run([_get_exiftool_path(), '-json', self.filename],
22 input_filename=self.filename,
23 check=True, stdout=subprocess.PIPE).stdout
22 meta = json.loads(out.decode('utf-8'))[0] 24 meta = json.loads(out.decode('utf-8'))[0]
23 for key in self.meta_whitelist: 25 for key in self.meta_whitelist:
24 meta.pop(key, None) 26 meta.pop(key, None)
@@ -46,7 +48,9 @@ class ExiftoolParser(abstract.AbstractParser):
46 '-o', self.output_filename, 48 '-o', self.output_filename,
47 self.filename] 49 self.filename]
48 try: 50 try:
49 subprocess.check_call(cmd) 51 subprocess.run(cmd, check=True,
52 input_filename=self.filename,
53 output_filename=self.output_filename)
50 except subprocess.CalledProcessError as e: # pragma: no cover 54 except subprocess.CalledProcessError as e: # pragma: no cover
51 logging.error("Something went wrong during the processing of %s: %s", self.filename, e) 55 logging.error("Something went wrong during the processing of %s: %s", self.filename, e)
52 return False 56 return False