-
Notifications
You must be signed in to change notification settings - Fork 1
/
ci_update_session_record.py
68 lines (53 loc) · 2.36 KB
/
ci_update_session_record.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
68
import os
import re
import logging
SDK_REPO = "c:/github/azure-sdk-for-java/sdk/resourcemanager"
# SDK_REPO = 'c:/github/azure-libraries-for-java'
RESOURCE_PROVIDER = "Microsoft.Storage"
VERSION_CHANGES = {"2021-09-01": "2022-05-01"}
def main():
logging.basicConfig(level=logging.INFO)
process_session_records()
def process_session_records():
for root, dirs, files in os.walk(SDK_REPO):
for name in files:
filepath = os.path.join(root, name)
if os.path.splitext(filepath)[1] == ".json" and "session-records" in filepath and "target" not in filepath:
update(filepath)
def update(filepath: str):
with open(filepath, encoding="utf-8") as f:
lines = f.readlines()
modified = False
out_lines = []
for line in lines:
if "http://localhost:" in line and f"/providers/{RESOURCE_PROVIDER}/" in line:
for before, after in VERSION_CHANGES.items():
if f"api-version={before}" in line:
modified = True
line = line.replace(f"api-version={before}", f"api-version={after}")
elif RESOURCE_PROVIDER == "Microsoft.Resources":
# resource groups
if (
re.match(
r' {4}"Uri" : "http://localhost:1234/subscriptions/00000000-0000-0000-0000-000000000000/resource[Gg]roups/[-\w._()]+\?api-version=[-0-9]+",',
line,
)
or re.match(
r' {4}"Uri" : "http://localhost:1234/subscriptions/00000000-0000-0000-0000-000000000000/resource[Gg]roups\?api-version=[-0-9]+",',
line,
)
or re.match(
r' {4}"Uri" : "http://localhost:1234/subscriptions/00000000-0000-0000-0000-000000000000/resource[Gg]roups/[-\w._()]+/resources\?api-version=[-0-9]+",',
line,
)
):
for before, after in VERSION_CHANGES.items():
if f"api-version={before}" in line:
modified = True
line = line.replace(f"api-version={before}", f"api-version={after}")
out_lines.append(line)
if modified:
logging.info(f"update session record {filepath}")
with open(filepath, "w", encoding="utf-8") as f:
f.write("".join(out_lines))
main()