-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_java_packages.py
91 lines (70 loc) · 2.85 KB
/
update_java_packages.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import logging
import csv
from typing import List
from typing import Dict
from urllib.request import urlopen
SDK_REPO = "c:/github/azure-sdk"
CSV_PATH = "_data/releases/latest/java-packages.csv"
def main():
logging.basicConfig(level=logging.INFO)
process_java_packages_csv()
def process_java_packages_csv():
csv_filename = os.path.join(SDK_REPO, CSV_PATH)
with open(csv_filename, newline="") as f:
csv_reader = csv.DictReader(f, delimiter=",", quotechar='"')
fieldnames = csv_reader.fieldnames
rows_all = []
for row in csv_reader:
rows_all.append(row)
rows = collect_new_arm_packages(rows_all)
update_new_arm_packages(rows, rows_all)
# rows_all = update_support(rows_all)
with open(csv_filename, "w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=fieldnames, delimiter=",", quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
writer.writeheader()
for row in rows_all:
writer.writerow(row)
def update_support(rows_all: List[Dict]) -> List[Dict]:
rows = []
for row in rows_all:
if row["Support"] == "":
sdk_name = row["Package"]
if sdk_name.startswith("azure-mgmt-"):
row["Support"] = "maintenance"
elif sdk_name.startswith("azure-resourcemanager"):
row["Support"] = "preview" if row["VersionGA"] == "" else "active"
rows.append(row)
return rows
def collect_new_arm_packages(rows_all: List[Dict]) -> List[Dict]:
rows = []
for row in rows_all:
# if row['GroupId'] == 'com.azure.resourcemanager' and row['New'] == 'false' and row['Hide'] == '':
if row["GroupId"] == "com.azure.resourcemanager" and row["DisplayName"].startswith("azure-resourcemanager-"):
rows.append(row)
return rows
def update_new_arm_packages(rows: List[Dict], rows_all: List[Dict]):
for row in rows:
sdk_name = row["Package"][len("azure-resourcemanager-") :]
row["New"] = "true"
row["Hide"] = "false"
row["Type"] = "mgmt"
if row["RepoPath"] == "NA":
row["RepoPath"] = sdk_name
try:
readme_data = urlopen(
f"https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/{sdk_name}/resource-manager/readme.md"
).read()
readme_str = readme_data.decode("utf-8")
lines = readme_str.split("\n")
for line in lines:
if line.startswith("# "):
service_name = line[2:]
break
except Exception as e:
logging.exception(e)
service_name = sdk_name
row["ServiceName"] = service_name
row["DisplayName"] = "Resource Management - " + service_name
row["Support"] = "preview" if row["VersionGA"] == "" else "active"
main()