Repository navigation
Expand file tree
/
Copy pathbuild-all.py
More file actions
executable file
·198 lines (176 loc) · 6.05 KB
/
Copy pathbuild-all.py
File metadata and controls
executable file
·198 lines (176 loc) · 6.05 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env python3
#
# Calls the docker build for each spec
# builds an index.html that links to them all
# reports any that fail
# exits with appropriate success / failure return code
import glob
import json
import os
import re
import sys
import subprocess
from datetime import date
dirs_exclude = [
".git",
".idea",
"cds-spec-analysis"
]
# This list is currently a list of files that fail to process
# Some of them we likely don't care about, but some of them should be fixed and removed from the list
files_exclude = [
'./Financial_API_Lodging_Intent.md',
'./Financial_API_Simple_HTTP_Message_Integrity_Protocol.md',
'./TR-Cross_browser_payment_initiation_attack.md',
'./FAPI_1.0/changes-between-id2-and-final.md'
]
fapi1_files = [
'./FAPI_1.0/openid-financial-api-part-1-1_0.md',
'./FAPI_1.0/openid-financial-api-part-2-1_0.md'
]
# Pinned by digest so the rendering is reproducible: an untagged/:latest image
# could silently change the output between identical commits. Regenerate the
# digest with `docker buildx imagetools inspect danielfett/markdown2rfc:latest`.
MD2RFC_IMAGE = 'danielfett/markdown2rfc@sha256:7b4412559d6ba5db45a14174a28da5b240512e7c2a886a5e4adb44e5e67f34ca'
failed = []
files_generated = []
# source .md -> generated .html, written to manifest.json for CI to link the
# drafts changed in a pull request from the preview comment
manifest = {}
def get_output_filename(fname):
# get the output filename, i.e. do what https://github.com/oauthstuff/markdown2rfc/blob/master/make.sh#L18 does
# and find the line like: value = "fapi-2_0-baseline-01"
regex = r'^value[\W]*=[\W]*"(.*)"'
return get_output_filename_impl(fname, regex)
def get_fapi1_output_filename(fname):
# get the fapi1 output filename, i.e. do what https://github.com/oauthstuff/markdown2rfc/blob/master/make.sh#L18 does
# and find the line like: value: openid-financial-api-part-2-1_0-01
regex = r'^[\W]*value[\W]*:[\W]*(.*)$'
return get_output_filename_impl(fname, regex)
def get_output_filename_impl(fname, regex):
with open(fname, 'r') as f:
for line in f:
matches = re.search(regex, line)
if matches:
return matches.group(1)
def execute_command(cmd, fname, outputfname):
retcode = subprocess.call(cmd)
if retcode != 0:
failed.append(fname)
print("docker run returned failure for "+fname)
return
if not os.path.isfile(outputfname):
print("expected output file of "+outputfname+" not found for "+fname)
failed.append(fname)
return
# the generated html contains a version number that we don't want to end up in the url; remove it
m = re.search(r'^(.*)-\d\d\.html$', outputfname)
if m:
newoutputfname = m.group(1)+".html"
os.rename(outputfname, newoutputfname)
outputfname = newoutputfname
print("Renamed output to "+outputfname)
files_generated.append(outputfname)
manifest[fname[2:] if fname.startswith('./') else fname] = outputfname
print()
def process_spec(fname):
currentdir = os.getcwd()
cmd = [ 'docker', 'run', '-v', currentdir+':/data', MD2RFC_IMAGE, fname ]
print("Running: " + ' '.join(cmd))
outputfname = get_output_filename(fname)
outputfname += ".html"
execute_command(cmd, fname, outputfname)
def process_fapi1_spec(fname):
outputfname = get_fapi1_output_filename(fname)
outputfname += ".html"
formatted_date = date.today().strftime('%B %d, %Y')
currentdir = os.getcwd()
cmd = [ './pandoc-3.1.9/bin/pandoc', '-V', 'current_date=' + formatted_date, '--toc', '--embed-resources', '-c', './FAPI_1.0/templates/site.css', '--template=./FAPI_1.0/templates/draft-template.html', '-f', 'markdown', '-t', 'html', '--section-divs', '--standalone', '--verbose', '-o', outputfname, fname ]
print("Running: " + ' '.join(cmd))
execute_command(cmd, fname, outputfname)
def walk_tree():
for root, dirs, files in os.walk("."):
dirs[:] = [d for d in dirs if d not in dirs_exclude]
for file in sorted(files):
if not file.endswith(".md"):
continue
if file.casefold() == "readme.md".casefold():
continue
fullfname = os.path.join(root, file)
if fullfname in files_exclude:
continue
if fullfname in fapi1_files:
process_fapi1_spec(fullfname)
else:
process_spec(fullfname)
def generate_index():
print("Creating index.html")
header = '''
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>OpenID Foundation FAPI Working Group Drafts</title>
<style type="text/css">
<!--
body {
font-family: sans-serif;
margin: 2em;
}
.navigation li {
display: inline;
margin-right: 1.5em;
}
.style1 {
color: #FF0000;
font-weight: bold;
}
.logo {
max-width: 10%;
max-height: auto;
float: left;
margin-right: 2em;
}
.not-active {
pointer-events: none;
cursor: default;
color: #aF0000;
}
-->
</style>
</head>
<body>
<div id="nav" class="column span-18 append-1 prepend-1">
<ul class="navigation">
<li><a href='https://openid.net/wg/fapi/'>About</a></li>
<li><a href='https://github.com/openid/fapi'>Repository</a></li>
<li><a href='https://github.com/openid/fapi/issues'>Issues</a></li>
</ul>
</div>
<div id="content">
<h1>OpenID Foundation FAPI Working Group Drafts</h1>
<h2>List of Draft Specifications</h2>
<p>Below are links to the HTML versions of the working groups draft documents:</p>
<ul>
'''
footer = '''
</ul>
</div>
</body>
</html>
'''
with open('index.html', 'w') as f:
print(header, file = f)
for fname in files_generated:
print(' <li><a href="{}">{}</a></li>'.format(fname, os.path.splitext(fname)[0]), file = f)
print(footer, file = f)
return
walk_tree()
generate_index()
with open('manifest.json', 'w') as f:
json.dump(manifest, f, indent=2, sort_keys=True)
if failed:
print("The processing of some specifications failed:")
for f in failed:
print(f)
sys.exit(1)
sys.exit(0)