-
Notifications
You must be signed in to change notification settings - Fork 2
/
PublicServiceUploader.py
70 lines (66 loc) · 2.93 KB
/
PublicServiceUploader.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
import Confluence, ServiceCatalographer, PublicServiceReporter
from config import confluenceHost, confluenceUser, confluencePass, serviceCatalographerURL
# The Wiki space and top-level page to index each service
# This page will be completely overwritten by the script!
confluenceSpaceKey = 'doc'
confluenceParentTitle = 'Supported Services'
updateServicePages = True # setting to False will only update index page
def upload():
confluence = Confluence.Server(confluenceHost, confluenceUser, confluencePass)
pageNameMap = {
# Any services that are not in BiodiversityCatalogue can be placed here.
# 'Service Name': 'Wiki Page Title'
'Rserve': 'Rserve service',
'WebDAV': 'WebDav_FileSharingService'
}
parentId = confluence.getPageId(confluenceSpaceKey, confluenceParentTitle)
bdc = ServiceCatalographer.ServiceCatalographer(serviceCatalographerURL)
services = bdc.getServices()
for service in services:
serviceId = service.self.split('/')[-1]
try:
if updateServicePages:
content = PublicServiceReporter.report(service)
except PublicServiceReporter.DoNotInclude:
pass
else:
pageName = 'BioVeL Service - %s' % service.name
print('Publishing %s' % pageName)
if updateServicePages:
confluence.publish(content, confluenceSpaceKey, pageName, parentId)
pageNameMap[service.name] = pageName
content = '<ac:layout>'
ncols = 3
assert ncols in (2,3), ncols
if ncols == 2:
content += '<ac:layout-section ac:type="two_equal">\n'
else:
content += '<ac:layout-section ac:type="three_equal">\n'
sortedKeys = sorted(pageNameMap, key=str.lower)
split = (len(pageNameMap) + ncols - 1) // ncols
for i in range(0, len(sortedKeys), split):
subKeys = sortedKeys[i:i+split]
content += '<ac:layout-cell>'
for serviceName in subKeys:
serviceLink = '''<p><b>
<ac:link>
<ri:page ri:content-title="%s" />
<ac:plain-text-link-body><![CDATA[%s]]></ac:plain-text-link-body>
</ac:link>
</b></p>''' % (pageNameMap[serviceName], serviceName)
content += PublicServiceReporter.panel(serviceLink, bgColor='#f3ffac')
content += '</ac:layout-cell>\n'
content += '</ac:layout-section>\n'
content += '''<ac:layout-section ac:type="single">
<ac:layout-cell>
<p>To find additional services, search in <ac:structured-macro ac:name="biodivcat"></ac:structured-macro>.</p>
</ac:layout-cell>
</ac:layout-section>
'''
content += '</ac:layout>\n'
print('Publishing %s' % confluenceParentTitle)
# Confluence detects if this page is identical to the previous version, and
# does not create a new revision.
confluence.publish(content, confluenceSpaceKey, confluenceParentTitle, confluence.getPageId(confluenceSpaceKey, 'BioVeL Wiki'))
if __name__ == '__main__':
upload()