Line data Source code
1 : /*
2 : * Copyright (C) 2017 Red Hat, Inc.
3 : * SPDX-License-Identifier: LGPL-2.1-or-later
4 : */
5 :
6 290 : import cockpit, { BasicError } from "cockpit";
7 :
8 290 : const pyinvoke = ["sh", "-ec", "exec $(command -v /usr/libexec/platform-python || command -v python3) -c \"$@\"", "--"];
9 :
10 : export interface PythonExitStatus extends BasicError {
11 : exit_status: number | null,
12 : exit_signal: number | null,
13 : }
14 :
15 : // only declare the string variant for the time being; we don't use the binary variant
16 276 : export function spawn (
17 276 : script_pieces: string | string[],
18 276 : args?: string[],
19 276 : options?: cockpit.SpawnOptions & { binary?: false; }
20 276 : ): cockpit.Spawn<string> {
21 276 : const script = (typeof script_pieces == "string")
22 270 : ? script_pieces
23 144 : : script_pieces.join("\n");
24 :
25 92 : return cockpit.spawn(pyinvoke.concat([script]).concat(args ?? []), options);
26 276 : }
|