Standardized subprocess execution wrapper.
(
cmd: List[str],
cwd: Optional[str] = None,
capture_output: bool = False,
env: Optional[Mapping[str, str]] = None,
)
| 24 | |
| 25 | |
| 26 | def exec_command( |
| 27 | cmd: List[str], |
| 28 | cwd: Optional[str] = None, |
| 29 | capture_output: bool = False, |
| 30 | env: Optional[Mapping[str, str]] = None, |
| 31 | ) -> subprocess.CompletedProcess: |
| 32 | """Standardized subprocess execution wrapper.""" |
| 33 | log.debug("Executing command", hypothesisId="SYS", cmd=" ".join(cmd), cwd=cwd) |
| 34 | try: |
| 35 | # Merge current env with provided env if exists |
| 36 | full_env = os.environ.copy() |
| 37 | if env: |
| 38 | full_env.update(env) |
| 39 | |
| 40 | result = subprocess.run( |
| 41 | cmd, |
| 42 | cwd=cwd, |
| 43 | capture_output=capture_output, |
| 44 | text=True, |
| 45 | check=False, |
| 46 | env=full_env, |
| 47 | ) |
| 48 | if result.returncode != 0: |
| 49 | log.debug( |
| 50 | "Command failed", |
| 51 | hypothesisId="SYS", |
| 52 | cmd=" ".join(cmd), |
| 53 | exit_code=result.returncode, |
| 54 | stderr=result.stderr if capture_output else "Check container logs", |
| 55 | ) |
| 56 | return result |
| 57 | except Exception as e: |
| 58 | log.debug( |
| 59 | "Command execution error", |
| 60 | hypothesisId="SYS", |
| 61 | cmd=" ".join(cmd), |
| 62 | error=str(e), |
| 63 | ) |
| 64 | raise e |
| 65 | |
| 66 | |
| 67 | def csv_to_dict(filename: str) -> Dict[str, List[str]]: |
no test coverage detected