-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
150 lines (117 loc) · 5.27 KB
/
update.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from datetime import datetime
import semver
import json
import subprocess
import re
import os
root_dir = os.getcwd()
GLOBAL_DATA_FILE = '_data/global_doc_info.json'
try:
with open(GLOBAL_DATA_FILE, 'r') as (f, err):
global_doc_info = json.loads(f.read())
except:
global_doc_info = {}
def save_global_doc_info():
with open(os.path.join(root_dir, GLOBAL_DATA_FILE), 'w') as f:
json.dump(global_doc_info, f, indent=2, sort_keys=True)
def make_crate_latest_md(crate):
os.makedirs(os.path.join(root_dir, "crate", name), exist_ok=True)
with open(os.path.join(root_dir, "crate", crate, "latest.md"), 'w') as f:
f.write("""---
layout: latest_redirect
crate: %s
---
""" % crate)
def make_eror_release_index_md(crate, version, error):
os.makedirs(os.path.join(root_dir, "crate", name, version), exist_ok=True)
with open(os.path.join(root_dir, "crate", crate, version, "index.md"), 'w') as f:
f.write("""---
layout: gnatdoc_error
crate: %s
version: %s
---
```
%s
```
""" % (crate, version, error))
def get_stdout(outcome):
return outcome.stdout.decode('utf-8', errors='replace')
output = subprocess.run(['alr', '--no-tty', '-n', 'search',
'--list'], stdout=subprocess.PIPE).stdout
crates = output.decode('utf-8').splitlines()
# crates = ["aaa 0.2.6 as a a a",
# "aaa 0.1.0 as a a a",
# "rp2040_hal 1.1.0 as a a a",
# "zlib_ada 1.3.0 a a a",
# "tash 8.7.0 a a a",
# "geste 1.0.0 a a a ",
# "geste 1.1.0 a a a "]
pattern = "^([a-z0-9_]*)[\s]+[UX]*[ ]*?([0-9][0-9.a-z+-]+)[\s]+(.*)$"
for line in crates:
print(line)
match = re.search (pattern, line)
if match:
# Go to our root directory
os.chdir(root_dir)
name = match.group (1)
version = match.group (2)
base_dir = os.path.join(name, version)
doc_output_dir = os.path.join(root_dir, "crate", base_dir)
tmp_dir = os.path.join(root_dir, "tmp", base_dir)
if name not in global_doc_info:
global_doc_info[name] = {'releases': {}}
if version in global_doc_info[name]['releases']:
print("Doc for %s %s already exists" % (name, version))
else:
release_doc_info = {}
print("Missing doc for %s %s..." % (name, version))
get_cmd = ['alr', '-n', 'get', name + "=" + version]
# Make and enter temp dir for the crate
os.makedirs(tmp_dir, exist_ok=True)
os.chdir(tmp_dir)
# Get the name of the directory where the crate will be downloaded
getdir = subprocess.run(get_cmd + ["--dirname"],
stdout=subprocess.PIPE).stdout.decode('utf-8').rstrip()
# Get the crate and dependencies
outcome = subprocess.run(get_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
if outcome.returncode != 0:
release_doc_info['status'] = "alr get failed"
release_doc_info['alr_get_error'] = get_stdout(outcome)
make_eror_release_index_md(name, version,
get_stdout(outcome))
else:
# Enter crate dir
os.chdir(getdir)
outcome = subprocess.run(['alr', '-n', 'show', '--jekyll'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
if outcome.returncode != 0:
release_doc_info['status'] = "alr show --jekyll FAIL"
release_doc_info['alr_show_error'] = get_stdout(outcome)
else:
os.makedirs(os.path.join(root_dir, "crate", name), exist_ok=True)
with open(os.path.join(root_dir, "crate", name, "index.md"), 'w') as f:
f.write(get_stdout(outcome))
outcome = subprocess.run(['alr', '-n', 'exec', "-P", "--", "gnatdoc4",
"--output-dir", doc_output_dir,
"--front-matter", "crate: " + name,
"--no-subprojects"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
if outcome.returncode != 0:
release_doc_info['status'] = "doc build FAIL"
release_doc_info['gnatdoc_error'] = get_stdout(outcome)
make_eror_release_index_md(name, version, get_stdout(outcome))
else:
release_doc_info['status'] = "doc build OK"
release_doc_info['date'] = datetime.now().strftime("%Y/%m/%d-%H:%M:%S")
global_doc_info[name]['releases'][version] = release_doc_info
if ('latest' not in global_doc_info[name]) or \
semver.compare(version, global_doc_info[name]['latest']) > 0:
global_doc_info[name]['latest'] = version
make_crate_latest_md(name)
save_global_doc_info()
print(str(global_doc_info))
save_global_doc_info()