-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixer.py
More file actions
51 lines (42 loc) · 1.13 KB
/
Copy pathfixer.py
File metadata and controls
51 lines (42 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import annotations
import os
import shlex
import subprocess
from dataclasses import dataclass
from typing import List, Optional
@dataclass(frozen=True)
class FixRun:
command: str
exit_code: int
stdout: str
stderr: str
def _pick_shell() -> List[str]:
shell = os.environ.get("SHELL") or ""
if shell.endswith("zsh"):
return [shell, "-lc"]
if shell.endswith("bash"):
return [shell, "-lc"]
# fall back
return ["bash", "-lc"]
def run_fix_commands(commands: List[str]) -> List[FixRun]:
"""Execute commands sequentially. Stop on failure."""
results: List[FixRun] = []
shell_prefix = _pick_shell()
for cmd in commands:
cp = subprocess.run(
shell_prefix + [cmd],
text=True,
capture_output=True,
env=os.environ.copy(),
)
results.append(
FixRun(
command=cmd,
exit_code=int(cp.returncode),
stdout=cp.stdout or "",
stderr=cp.stderr or "",
)
)
if cp.returncode != 0:
break
return results