-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.py
67 lines (50 loc) · 1.67 KB
/
version.py
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
# --------------------------------
# this script for change all workshop's version info
# include: Cargo.toml dependency
# usage: python3 version.py [version | null]
# --------------------------------
import sys
from os import path
from tomlkit import parse,dumps,inline_table
def to_local():
edit_all()
def to_version(version):
edit_all(version)
def edit_all(value = None):
# for karaty dir
karaty_cargo = path.join("karaty", "Cargo.toml")
edit_dependency(karaty_cargo, "karaty-blueprint", value)
template_value = inline_table()
if value is None:
template_value.update({"path": "../template", "template": True})
else:
template_value.update({"version": value, "template": True})
edit_dependency(karaty_cargo, "karaty-template", template_value)
# for docsite dir
docsite_cargo = path.join("docsite", "Cargo.toml")
edit_dependency(docsite_cargo, "karaty-blueprint", value)
# for template dir
template_cargo = path.join("template", "Cargo.toml")
edit_dependency(template_cargo, "karaty-blueprint", value)
def edit_dependency(path, name, value):
if value is None:
temp = "../{}".format(name.split("-")[1])
tab = inline_table()
tab.update({"path": temp})
value = tab
cargo = None
with open(path, "r") as file:
content = file.read()
cargo = parse(content)
dep = cargo.item("dependencies")
dep.value[name] = value
with open(path, "w") as file:
file.write(dumps(cargo))
def main():
argument = sys.argv
if len(argument) <= 1:
to_local()
else:
to_version(argument[1])
if __name__ == "__main__":
main()