Coverage for functions \ flipdare \ util \ process_util.py: 91%
22 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
1#!/usr/bin/env python
2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
3#
4# This file is part of Flipdare's proprietary software and contains
5# confidential and copyrighted material. Unauthorised copying,
6# modification, distribution, or use of this file is strictly
7# prohibited without prior written permission from Flipdare Pty Ltd.
8#
9# This software includes third-party components licensed under MIT,
10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
11#
14from flipdare.app_log import LOG
17class ProcessUtil:
19 def __init__(self, command_args: list[str]) -> None:
20 self._command_args = command_args
22 @property
23 def command_args(self) -> list[str]:
24 return self._command_args
26 @property
27 def command_str(self) -> str:
28 if len(self._command_args) == 1:
29 return self._command_args[0]
31 return " ".join(self._command_args)
33 def run(self) -> tuple[int, str, str]:
34 """Run the process and return a tuple of (return_code, stdout, stderr)."""
35 import subprocess
37 try:
38 process = subprocess.Popen( # noqa: S603
39 self._command_args,
40 stdout=subprocess.PIPE,
41 stderr=subprocess.PIPE,
42 text=True,
43 )
44 stdout, stderr = process.communicate()
45 return_code = process.returncode
46 # LOG().debug(f"Process '{self.command_str}' finished with "
47 # f"return code {return_code}:\n"
48 # "----------------------------------------"
49 # f" STDOUT:\n"
50 # f"{stdout}\n"
51 # "----------------------------------------"
52 # f"STDERR:\n"
53 # f"{stderr}\n"
54 # "----------------------------------------"
55 # )
57 return return_code, stdout, stderr
58 except Exception as e:
59 LOG().error(f"Error running process with command '{self.command_str}': {e!s}")
60 return -1, "", str(e)