forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmark-desktop-release-stable.py
More file actions
executable file
·64 lines (51 loc) · 1.87 KB
/
Copy pathmark-desktop-release-stable.py
File metadata and controls
executable file
·64 lines (51 loc) · 1.87 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
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
"""Rewrite the desktop release metadata block to channel: stable."""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from desktop_release_metadata import fail, normalize_metadata_line # noqa: E402
def mark_stable(body: str) -> str:
lines = body.splitlines()
output: list[str] = []
in_block = False
saw_block = False
saw_channel = False
for line in lines:
stripped = normalize_metadata_line(line)
if stripped == "KEY_VALUE_START":
in_block = True
saw_block = True
output.append(line)
continue
if stripped == "KEY_VALUE_END":
if not in_block:
fail("release body has KEY_VALUE_END without KEY_VALUE_START")
if not saw_channel:
output.append("channel: stable")
in_block = False
output.append(line)
continue
if in_block and stripped.startswith("channel:"):
output.append("channel: stable")
saw_channel = True
continue
output.append(line)
if in_block:
fail("release body metadata block is missing KEY_VALUE_END")
if not saw_block:
fail("release body is missing KEY_VALUE_START/KEY_VALUE_END metadata block")
trailing_newline = "\n" if body.endswith("\n") else ""
return "\n".join(output) + trailing_newline
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--input", required=True)
parser.add_argument("--output", required=True)
args = parser.parse_args()
body = Path(args.input).read_text()
Path(args.output).write_text(mark_stable(body))
print("desktop release metadata channel set to stable")
return 0
if __name__ == "__main__":
raise SystemExit(main())