-
Notifications
You must be signed in to change notification settings - Fork 257
Expand file tree
/
Copy pathgenerate_xrefmap.py
More file actions
28 lines (24 loc) · 1.15 KB
/
generate_xrefmap.py
File metadata and controls
28 lines (24 loc) · 1.15 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
"""This module generates xrefmap from external links."""
import os
import urllib.request
import yaml
from sphinx.ext.intersphinx import read_inventory
EXTERNAL_LINKS = ['https://docs.python.org/3.5/',
'https://msrestazure.readthedocs.io/en/latest/',
'https://msrest.readthedocs.io/en/latest/']
xref_map = []
for external_Link in EXTERNAL_LINKS:
obj_link = os.path.join(external_Link, 'objects.inv')
stream = urllib.request.urlopen(obj_link)
inventory = read_inventory(stream, external_Link, os.path.join)
for role_key, role_value in inventory.items():
if role_key.startswith('py:'):
for ref_name, ref_value in role_value.items():
# Only use last element in ref_name
title_name = ref_name.split('.')[-1]
xref_map.append({'uid': ref_name,
'name': title_name,
'href': ref_value[2],
'fullName': ref_name})
with open('xrefmap.yml', 'w', encoding='utf8') as out_file:
yaml.dump({'references': xref_map}, out_file, default_flow_style=False, allow_unicode=True)