mirror of
https://github.com/containers/podman-compose.git
synced 2025-07-07 16:06:59 +02:00
Merge pull request #887 from baszoetekouw/fix-oldpython
Fix support for older python versions
This commit is contained in:
@ -1173,15 +1173,15 @@ class Podman:
|
||||
xargs = self.compose.get_podman_args(cmd) if cmd else []
|
||||
cmd_ls = [self.podman_path, *podman_args, cmd] + xargs + cmd_args
|
||||
log.info(str(cmd_ls))
|
||||
p = await asyncio.subprocess.create_subprocess_exec(
|
||||
p = await asyncio.create_subprocess_exec(
|
||||
*cmd_ls, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
|
||||
stdout_data, stderr_data = await p.communicate()
|
||||
if p.returncode == 0:
|
||||
return stdout_data
|
||||
else:
|
||||
raise subprocess.CalledProcessError(p.returncode, " ".join(cmd_ls), stderr_data)
|
||||
|
||||
raise subprocess.CalledProcessError(p.returncode, " ".join(cmd_ls), stderr_data)
|
||||
|
||||
def exec(
|
||||
self,
|
||||
@ -1195,7 +1195,7 @@ class Podman:
|
||||
log.info(" ".join([str(i) for i in cmd_ls]))
|
||||
os.execlp(self.podman_path, *cmd_ls)
|
||||
|
||||
async def run(
|
||||
async def run( # pylint: disable=dangerous-default-value
|
||||
self,
|
||||
podman_args,
|
||||
cmd="",
|
||||
@ -1223,7 +1223,7 @@ class Podman:
|
||||
if stdout.at_eof():
|
||||
break
|
||||
|
||||
p = await asyncio.subprocess.create_subprocess_exec(
|
||||
p = await asyncio.create_subprocess_exec(
|
||||
*cmd_ls, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||
) # pylint: disable=consider-using-with
|
||||
|
||||
@ -1238,7 +1238,7 @@ class Podman:
|
||||
err_t.add_done_callback(task_reference.discard)
|
||||
|
||||
else:
|
||||
p = await asyncio.subprocess.create_subprocess_exec(*cmd_ls) # pylint: disable=consider-using-with
|
||||
p = await asyncio.create_subprocess_exec(*cmd_ls) # pylint: disable=consider-using-with
|
||||
|
||||
try:
|
||||
exit_code = await p.wait()
|
||||
@ -1916,9 +1916,12 @@ class PodmanCompose:
|
||||
|
||||
podman_compose = PodmanCompose()
|
||||
|
||||
|
||||
###################
|
||||
# decorators to add commands and parse options
|
||||
###################
|
||||
class PodmanComposeError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class cmd_run: # pylint: disable=invalid-name,too-few-public-methods
|
||||
@ -1932,7 +1935,7 @@ class cmd_run: # pylint: disable=invalid-name,too-few-public-methods
|
||||
return func(*args, **kw)
|
||||
|
||||
if not asyncio.iscoroutinefunction(func):
|
||||
raise Exception("Command must be async")
|
||||
raise PodmanComposeError("Command must be async")
|
||||
wrapped._compose = self.compose
|
||||
# Trim extra indentation at start of multiline docstrings.
|
||||
wrapped.desc = self.cmd_desc or re.sub(r"^\s+", "", func.__doc__)
|
||||
@ -2014,8 +2017,8 @@ async def compose_systemd(compose, args):
|
||||
f.write(f"{k}={v}\n")
|
||||
log.debug("writing [%s]: done.", fn)
|
||||
log.info("\n\ncreating the pod without starting it: ...\n\n")
|
||||
process = await asyncio.subprocess.create_subprocess_exec(script, ["up", "--no-start"])
|
||||
log.info("\nfinal exit code is ", process)
|
||||
process = await asyncio.create_subprocess_exec(script, ["up", "--no-start"])
|
||||
log.info("\nfinal exit code is %d", process)
|
||||
username = getpass.getuser()
|
||||
print(
|
||||
f"""
|
||||
@ -2299,6 +2302,14 @@ async def compose_up(compose: PodmanCompose, args):
|
||||
)
|
||||
)
|
||||
|
||||
def _task_cancelled(task: Task) -> bool:
|
||||
if task.cancelled():
|
||||
return True
|
||||
# Task.cancelling() is new in python 3.11
|
||||
if sys.version_info >= (3, 11) and task.cancelling():
|
||||
return True
|
||||
return False
|
||||
|
||||
exit_code = 0
|
||||
exiting = False
|
||||
while tasks:
|
||||
@ -2309,7 +2320,9 @@ async def compose_up(compose: PodmanCompose, args):
|
||||
# cause the status to overwrite. Sleeping for 1 seems to fix this and make it match
|
||||
# docker-compose
|
||||
await asyncio.sleep(1)
|
||||
[_.cancel() for _ in tasks if not _.cancelling() and not _.cancelled()]
|
||||
for t in tasks:
|
||||
if not _task_cancelled(t):
|
||||
t.cancel()
|
||||
t: Task
|
||||
exiting = True
|
||||
for t in done:
|
||||
|
Reference in New Issue
Block a user