forked from saltstack/salt-vmtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-release-shasum.py
More file actions
49 lines (42 loc) · 1.47 KB
/
update-release-shasum.py
File metadata and controls
49 lines (42 loc) · 1.47 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
#!/usr/bin/env python
import sys
import pathlib
import subprocess
THIS_FILE = pathlib.Path(__file__).resolve()
CODE_ROOT = THIS_FILE.parent.parent.parent.parent
README_PATH = CODE_ROOT / "README.md"
def main(version, sha256sum):
in_contents = README_PATH.read_text()
if version in in_contents:
print(f"README file already contains an entry for version {version}")
sys.exit(1)
out_contents = ""
found_anchor = False
updated_version = False
if version not in in_contents:
for line in in_contents.splitlines(True):
if updated_version:
out_contents += line
continue
if found_anchor:
if not line.startswith("-"):
out_contents += line
continue
out_contents += "- {}: ``{}``\n".format(version, sha256sum)
out_contents += line
updated_version = True
continue
out_contents += line
if line.startswith("## _sha256sums"):
found_anchor = True
if in_contents != out_contents:
README_PATH.write_text(out_contents)
ret = subprocess.run(
["git", "diff", "--stat"], universal_newlines=True, capture_output=True
)
if "1 file changed, 1 insertion(+)" not in ret.stdout:
print("Too Many Changes to the readme file")
sys.exit(1)
sys.exit(0)
if __name__ == "__main__":
main(sys.argv[1], sys.argv[2])