From f6473d7cb322a6654a7e80ff24425e87d4aad8e7 Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 22 Nov 2024 13:43:03 +0100 Subject: [PATCH] Support older pythons --- alibuild_helpers/cmd.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/alibuild_helpers/cmd.py b/alibuild_helpers/cmd.py index 3687510c..4d5d0141 100644 --- a/alibuild_helpers/cmd.py +++ b/alibuild_helpers/cmd.py @@ -5,10 +5,11 @@ from textwrap import dedent from subprocess import TimeoutExpired from shlex import quote +from typing import Union, Tuple, List from alibuild_helpers.log import debug, warning, dieOnError -def decode_with_fallback(data : bytes | str) -> str: +def decode_with_fallback(data : Union[bytes, str]) -> str: """Try to decode DATA as utf-8; if that doesn't work, fall back to latin-1. This combination should cover every possible byte string, as latin-1 covers @@ -37,7 +38,7 @@ def getoutput(command:str, timeout=None) -> str: return decode_with_fallback(stdout) -def getstatusoutput(command:str, timeout: int | None = None) -> tuple[int, str]: +def getstatusoutput(command:str, timeout: Union[int, None] = None) -> Tuple[int, str]: """Run command and return its return code and output (stdout and stderr).""" proc = Popen(command, shell=isinstance(command, str), stdout=PIPE, stderr=STDOUT) try: @@ -54,7 +55,7 @@ def getstatusoutput(command:str, timeout: int | None = None) -> tuple[int, str]: return proc.returncode, merged_output -def execute(command: str | list[str], printer=debug, timeout:int | None =None) -> int: +def execute(command: Union[str, List[str]], printer=debug, timeout:Union[int, None] =None) -> int: popen = Popen(command, shell=isinstance(command, str), stdout=PIPE, stderr=STDOUT) start_time = time.time() assert popen.stdout is not None, "Could not open stdout for command"