Skip to content

Commit

Permalink
Support older pythons
Browse files Browse the repository at this point in the history
  • Loading branch information
singiamtel committed Nov 22, 2024
1 parent f56a6fd commit f6473d7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions alibuild_helpers/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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"
Expand Down

0 comments on commit f6473d7

Please sign in to comment.