forked from truenas/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzz.py
More file actions
65 lines (55 loc) · 1.97 KB
/
zz.py
File metadata and controls
65 lines (55 loc) · 1.97 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
# walk over ix-dev
import os
import yaml
import subprocess
def bump_version(data: dict, kind: str = "patch"):
version = data["version"]
parts = version.split(".")
if kind == "patch":
parts[2] = str(int(parts[2]) + 1)
elif kind == "minor":
parts[1] = str(int(parts[1]) + 1)
parts[2] = "0"
elif kind == "major":
parts[0] = str(int(parts[0]) + 1)
parts[1] = "0"
parts[2] = "0"
else:
raise Exception(f"invalid kind {kind}")
data["version"] = ".".join(parts)
data["maintainers"][0]["email"] = "dev@truenas.com"
return data
def get_yaml_data(file: str):
with open(file, "r") as f:
data = yaml.safe_load(f)
return data
def set_added_date(data: dict, app_yaml: str):
res = subprocess.run(f'git log --diff-filter=A --format="%as" -- {app_yaml}', shell=True, capture_output=True)
if res.returncode != 0:
raise Exception(f"failed to get git log for {app_yaml}")
git_log = res.stdout.decode("utf-8").strip()
if data["date_added"] == git_log:
return data, False
data["date_added"] = git_log
return data, True
for train in os.listdir("ix-dev"):
# if its not dir skip
if not os.path.isdir(os.path.join("ix-dev", train)):
continue
for app in os.listdir(os.path.join("ix-dev", train)):
# if its not dir skip
if not os.path.isdir(os.path.join("ix-dev", train, app)):
continue
file = os.path.join("ix-dev", train, app, "app.yaml")
data = get_yaml_data(file)
if not data:
print("no app.yaml", train, app)
continue
# if not data["lib_version"] == "2.1.65":
# print("wrong lib_version", train, app, data["lib_version"])
# continue
data, changed = set_added_date(data, file)
if changed or data["lib_version"] == "2.2.2":
data = bump_version(data, "patch")
with open(file, "w") as f:
yaml.safe_dump(data, f)