Debian Codegraph @

pkg/lib/python.ts

raw
1 /*
2 * Copyright (C) 2017 Red Hat, Inc.
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6 import cockpit, { BasicError } from "cockpit";
7
8 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 export function spawn (
17 script_pieces: string | string[],
18 args?: string[],
19 options?: cockpit.SpawnOptions & { binary?: false; }
20 ): cockpit.Spawn<string> {
21 const script = (typeof script_pieces == "string")
22 ? script_pieces
23 : script_pieces.join("\n");
24
25 return cockpit.spawn(pyinvoke.concat([script]).concat(args ?? []), options);
26 }