Commit cee810bf97d6c8ea51eef0749742776a2049e29a

Authored by Miguel Barão
1 parent bee4a6e0
Exists in master and in 1 other branch dev

simplified run_script() function in tools.py

Showing 1 changed file with 5 additions and 10 deletions   Show diff stats
perguntations/tools.py
@@ -67,21 +67,16 @@ def run_script(script: str, @@ -67,21 +67,16 @@ def run_script(script: str,
67 stderr=subprocess.STDOUT, 67 stderr=subprocess.STDOUT,
68 universal_newlines=True, 68 universal_newlines=True,
69 timeout=timeout, 69 timeout=timeout,
70 - check=False, 70 + check=True,
71 ) 71 )
72 - except OSError:  
73 - logger.error('Can not execute script "%s".', script)  
74 - return output  
75 except subprocess.TimeoutExpired: 72 except subprocess.TimeoutExpired:
76 logger.error('Timeout %ds exceeded running "%s".', timeout, script) 73 logger.error('Timeout %ds exceeded running "%s".', timeout, script)
77 return output 74 return output
78 - except Exception:  
79 - logger.error('An Exception ocurred running "%s".', script) 75 + except subprocess.CalledProcessError as exc:
  76 + logger.error('Return code %d running "%s".', exc.returncode, script)
80 return output 77 return output
81 -  
82 - # --- check return code  
83 - if proc.returncode != 0:  
84 - logger.error('Return code %d running "%s".', proc.returncode, script) 78 + except OSError:
  79 + logger.error('Can not execute script "%s".', script)
85 return output 80 return output
86 81
87 # --- parse yaml 82 # --- parse yaml