forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmark-desktop-release-beta.py
More file actions
executable file
·68 lines (57 loc) · 2.06 KB
/
Copy pathmark-desktop-release-beta.py
File metadata and controls
executable file
·68 lines (57 loc) · 2.06 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
65
66
67
68
#!/usr/bin/env python3
"""Rewrite desktop release metadata from candidate to live beta."""
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_beta(body: str) -> str:
lines = body.splitlines()
output: list[str] = []
in_block = False
saw_block = False
saw_channel = False
saw_live = 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_live:
output.append("isLive: true")
if not saw_channel:
output.append("channel: beta")
in_block = False
output.append(line)
continue
if in_block and stripped.startswith("isLive:"):
output.append("isLive: true")
saw_live = True
continue
if in_block and stripped.startswith("channel:"):
output.append("channel: beta")
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")
return "\n".join(output) + ("\n" if body.endswith("\n") else "")
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_beta(body))
print("desktop release metadata set to live beta")
return 0
if __name__ == "__main__":
raise SystemExit(main())