-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
executable file
·203 lines (172 loc) · 7.63 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
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
199
200
201
202
203
#!/usr/bin/python3
import json
from xml.dom import minidom
import os
import jinja2 # Debian: python3-jinja2
from datetime import datetime
BOOL = {
'true': True,
'false': False,
}
def filter_active(highlightpath, currentpath):
if highlightpath == currentpath:
return 'active'
else:
return ''
def render(out, template_name, **kwargs):
env = jinja2.Environment(
loader=jinja2.FileSystemLoader('templates'),
autoescape=True)
env.filters['active'] = filter_active
template = env.get_template(template_name)
html = template.render(base='.', assets='..', **kwargs)
open(out, 'w', encoding='utf-8').write(html)
def getText(element):
strings = []
for node in element.childNodes:
if node.nodeType == node.TEXT_NODE:
strings.append(node.data)
return ''.join(strings)
def getTime(element):
return format(datetime.fromtimestamp(int(getText(element))), '%Y-%m-%d %H:%M:%S')
def translated(element):
strings = {}
for child in element.childNodes:
if child.nodeType != child.ELEMENT_NODE:
continue
strings[child.nodeName] = getText(child)
return strings
def readAttribute(xml, credential):
name = xml.getElementsByTagName('Name')
desc = xml.getElementsByTagName('Description')
attribute = {
'id': xml.getAttribute('id'),
'optional': len(xml.getAttribute('optional')) > 0,
'revocation': len(xml.getAttribute('revocation')) > 0,
'randomblind': len(xml.getAttribute('randomblind')) > 0,
'name': translated(name[0]) if len(name) > 0 else None,
'description': translated(desc[0]) if len(desc) > 0 else None,
}
attribute['identifier'] = '%s.%s' % (credential['identifier'], attribute['id'])
return attribute
def readCredential(path):
xml = minidom.parse(path + '/description.xml')
deprecated = xml.getElementsByTagName('DeprecatedSince')
credential = {
'schememgr': getText(xml.getElementsByTagName('SchemeManager')[0]),
'issuer': getText(xml.getElementsByTagName('IssuerID')[0]),
'id': getText(xml.getElementsByTagName('CredentialID')[0]),
'name': translated(xml.getElementsByTagName('Name')[0]),
'shortName': translated(xml.getElementsByTagName('ShortName')[0]),
'description': translated(xml.getElementsByTagName('Description')[0]),
'revocation': xml.getElementsByTagName('RevocationServers').length > 0,
'deprecated': getTime(deprecated[0]) if len(deprecated) > 0 else None,
'logo': path + '/logo.png',
'shouldBeSingleton': False,
'attributes': [],
}
credential['identifier'] = '%s.%s.%s' % (credential['schememgr'], credential['issuer'], credential['id'])
singletonElements = xml.getElementsByTagName('ShouldBeSingleton')
if singletonElements:
# Not all credential descriptions have a ShouldBeSingleton element.
credential['shouldBeSingleton'] = BOOL[getText(singletonElements[0])]
for attribute in xml.getElementsByTagName('Attributes')[0].childNodes:
if attribute.nodeType != attribute.ELEMENT_NODE:
continue
credentialAttr = readAttribute(attribute, credential)
if credentialAttr['revocation']:
continue
credential['attributes'].append(credentialAttr)
return credential
def readIssuer(path):
xml = minidom.parse(path + '/description.xml')
issuer = {
'id': getText(xml.getElementsByTagName('ID')[0]),
'schememgr': getText(xml.getElementsByTagName('SchemeManager')[0]),
'shortName': translated(xml.getElementsByTagName('ShortName')[0]),
'name': translated(xml.getElementsByTagName('Name')[0]),
'contactEmail': getText(xml.getElementsByTagName('ContactEMail')[0]),
'logo': path + '/logo.png',
'credentials': {},
}
issuer['identifier'] = '%s.%s' % (issuer['schememgr'], issuer['id'])
for fn in sorted(os.listdir(path + '/Issues')):
issuer['credentials'][fn] = readCredential(path + '/Issues/' + fn)
return issuer
def readSchemeManager(path, githubURL):
schememgr = {}
xml = minidom.parse(path + '/description.xml')
schememgr = {
'id': getText(xml.getElementsByTagName('Id')[0]),
'name': translated(xml.getElementsByTagName('Name')[0]),
'description': translated(xml.getElementsByTagName('Description')[0]),
'url': getText(xml.getElementsByTagName('Url')[0]),
'github': githubURL,
'contact': getText(xml.getElementsByTagName('Contact')[0]),
'keyshareServer': None,
'keyshareWebsite': None,
'keyshareAttribute': None,
'issuers': {},
}
schememgr['identifier'] = schememgr['id'] # for consistency
schememgr['test'] = bool(os.path.exists(path + '/sk.pem'))
keyshareServerElements = xml.getElementsByTagName('KeyshareServer')
if keyshareServerElements:
schememgr['keyshareServer'] = getText(keyshareServerElements[0])
keyshareWebsiteElements = xml.getElementsByTagName('KeyshareWebsite')
if keyshareWebsiteElements:
schememgr['keyshareWebsite'] = getText(keyshareWebsiteElements[0])
keyshareAttributeElements = xml.getElementsByTagName('KeyshareAttribute')
if keyshareAttributeElements:
schememgr['keyshareAttribute'] = getText(keyshareAttributeElements[0])
for fn in sorted(os.listdir(path)):
issuerPath = path + '/' + fn
if os.path.exists(issuerPath + '/description.xml'):
schememgr['issuers'][fn] = readIssuer(issuerPath)
return schememgr
def generateHTML(index, out, lang):
os.makedirs(out, exist_ok=True)
render(out + '/index.html', 'about.html',
index=index,
LANG=lang,
identifier='')
render(out + '/glossary.html', 'glossary.html',
index=index,
LANG=lang,
identifier='glossary')
for schememgr in index:
render(out + '/' + schememgr['identifier'] + '.html', 'schememgr.html',
index=index,
schememgr=schememgr,
LANG=lang,
identifier=schememgr['identifier'])
for issuerId, issuer in sorted(schememgr['issuers'].items()):
render(out + '/' + issuer['identifier'] + '.html', 'issuer.html',
index=index,
schememgr=schememgr,
issuer=issuer,
LANG=lang,
identifier=issuer['identifier'])
for credentialId, credential in sorted(issuer['credentials'].items()):
render(out + '/' + credential['identifier'] + '.html', 'credential.html',
index=index,
schememgr=schememgr,
issuer=issuer,
credential=credential,
LANG=lang,
identifier=credential['identifier'])
if __name__ == '__main__':
# TODO: put this in a config file?
schememanagers = [{
'source': 'pbdf-schememanager',
'github': 'https://github.com/privacybydesign/pbdf-schememanager/blob/master'
}, {
'source': 'irma-demo-schememanager',
'github': 'https://github.com/privacybydesign/irma-demo-schememanager/blob/master',
}]
index = []
for info in schememanagers:
index.append(readSchemeManager(info['source'], info['github']))
json.dump(index, open('index.json', 'w'))
generateHTML(index, 'en', 'en')
generateHTML(index, 'nl', 'nl')