forked from Azure/azure-cli-extensions
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate_extension_list.py
More file actions
90 lines (73 loc) · 3.75 KB
/
update_extension_list.py
File metadata and controls
90 lines (73 loc) · 3.75 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
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
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
"""
This script must be run at the root of repo folder, which is azure-cli-extensions/
It's used to update a file "azure-cli-extensions-list.md" of MicrosoftDocs/azure-cli-docs.
The file content is list of all available latest extensions.
"""
import os
import sys
import collections
import datetime
from pkg_resources import parse_version
from jinja2 import Template # pylint: disable=import-error
import requests
# After migration to OneBranch, clone azure-cli-extensions repo and azure-docs-cli repo are required.
# Also standardizes the directory structure:
# - $(System.DefaultWorkingDirectory)
# - azure-cli-extensions
# - azure-docs-cli
AZURE_CLI_EXTENSIONS_REPO_PATH = os.path.abspath(os.path.join('.', 'azure-cli-extensions'))
AZURE_DOCS_CLI_REPO_PATH = os.path.abspath(os.path.join('.', 'azure-docs-cli'))
AVAILABLE_EXTENSIONS_DOC = os.path.join(AZURE_DOCS_CLI_REPO_PATH, 'docs-ref-conceptual', 'Latest-version', 'azure-cli-extensions-list.md')
TEMPLATE_FILE = os.path.join(AZURE_CLI_EXTENSIONS_REPO_PATH, 'scripts', 'ci', 'avail-ext-doc', 'list-template.md')
sys.path.insert(0, os.path.join(AZURE_CLI_EXTENSIONS_REPO_PATH, 'scripts'))
from ci.util import get_index_data, INDEX_PATH
def get_extensions():
extensions = []
index_extensions = collections.OrderedDict(sorted(get_index_data()['extensions'].items()))
for _, exts in index_extensions.items():
# Get latest version
exts = sorted(exts, key=lambda c: parse_version(c['metadata']['version']), reverse=True)
# some extension modules may not include 'HISTORY.rst'
# setup.py
if 'project_urls' in exts[0]['metadata']['extensions']['python.details']:
project_url = exts[0]['metadata']['extensions']['python.details']['project_urls']['Home']
# pyproject.toml
elif 'project_url' in exts[0]['metadata']:
project_url = exts[0]['metadata']['project_url'].replace('homepage,', '').strip()
print(f"Warning: extension {exts[0]['metadata']['name']} has migrated to pyproject.toml.")
else:
project_url = ''
print(f"Warning: No project_url found for extension {exts[0]['metadata']['name']}")
history_tmp = project_url + '/HISTORY.rst'
history = project_url if str(requests.get(history_tmp).status_code) == '404' else history_tmp
if exts[0]['metadata'].get('azext.isPreview'):
status = 'Preview'
elif exts[0]['metadata'].get('azext.isExperimental'):
status = 'Experimental'
else:
status = 'GA'
extensions.append({
'name': exts[0]['metadata']['name'],
'desc': exts[0]['metadata']['summary'],
'min_cli_core_version': exts[0]['metadata']['azext.minCliCoreVersion'],
'version': exts[0]['metadata']['version'],
'project_url': project_url,
'history': history,
'status': status
})
return extensions
def update_extensions_list(output_file):
with open(TEMPLATE_FILE, 'r') as doc_template:
template = Template(doc_template.read())
if template is None:
raise RuntimeError("Failed to read template file {}".format(TEMPLATE_FILE))
with open(output_file, 'w') as output:
output.write(template.render(extensions=get_extensions(), date=datetime.date.today().strftime("%m/%d/%Y")))
def main():
update_extensions_list(AVAILABLE_EXTENSIONS_DOC)
if __name__ == '__main__':
main()