Merge "Enhance notification doc generation with samples"
This commit is contained in:
@@ -27,14 +27,19 @@ from nova.notifications.objects import base as notification
|
|||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
|
|
||||||
|
|
||||||
def full_name(cls):
|
|
||||||
return cls.__module__ + '.' + cls.__name__
|
|
||||||
|
|
||||||
|
|
||||||
class VersionedNotificationDirective(Directive):
|
class VersionedNotificationDirective(Directive):
|
||||||
|
|
||||||
LINK_PREFIX = 'https://git.openstack.org/cgit/openstack/nova/plain/'
|
|
||||||
SAMPLE_ROOT = 'doc/notification_samples/'
|
SAMPLE_ROOT = 'doc/notification_samples/'
|
||||||
|
TOGGLE_SCRIPT = """
|
||||||
|
<script>
|
||||||
|
jQuery(document).ready(function(){
|
||||||
|
jQuery('#%s-div').toggle('show');
|
||||||
|
jQuery('#%s-hideshow').on('click', function(event) {
|
||||||
|
jQuery('#%s-div').toggle('show');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
"""
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
notifications = self._collect_notifications()
|
notifications = self._collect_notifications()
|
||||||
@@ -52,14 +57,14 @@ class VersionedNotificationDirective(Directive):
|
|||||||
payload_name = cls.fields['payload'].objname
|
payload_name = cls.fields['payload'].objname
|
||||||
payload_cls = ovos[payload_name][0]
|
payload_cls = ovos[payload_name][0]
|
||||||
for sample in cls.samples:
|
for sample in cls.samples:
|
||||||
notifications.append((full_name(cls),
|
notifications.append((cls.__name__,
|
||||||
full_name(payload_cls),
|
payload_cls.__name__,
|
||||||
sample))
|
sample))
|
||||||
return notifications
|
return sorted(notifications)
|
||||||
|
|
||||||
def _build_markup(self, notifications):
|
def _build_markup(self, notifications):
|
||||||
content = []
|
content = []
|
||||||
cols = ['Notification class', 'Payload class', 'Sample file link']
|
cols = ['Event type', 'Notification class', 'Payload class', 'Sample']
|
||||||
table = nodes.table()
|
table = nodes.table()
|
||||||
content.append(table)
|
content.append(table)
|
||||||
group = nodes.tgroup(cols=len(cols))
|
group = nodes.tgroup(cols=len(cols))
|
||||||
@@ -68,7 +73,7 @@ class VersionedNotificationDirective(Directive):
|
|||||||
head = nodes.thead()
|
head = nodes.thead()
|
||||||
group.append(head)
|
group.append(head)
|
||||||
|
|
||||||
for i in range(len(cols)):
|
for _ in cols:
|
||||||
group.append(nodes.colspec(colwidth=1))
|
group.append(nodes.colspec(colwidth=1))
|
||||||
|
|
||||||
body = nodes.tbody()
|
body = nodes.tbody()
|
||||||
@@ -84,9 +89,16 @@ class VersionedNotificationDirective(Directive):
|
|||||||
col.append(text)
|
col.append(text)
|
||||||
|
|
||||||
# fill the table content, one notification per row
|
# fill the table content, one notification per row
|
||||||
for name, payload, sample in notifications:
|
for name, payload, sample_file in notifications:
|
||||||
|
event_type = sample_file[0: -5].replace('-', '.')
|
||||||
|
|
||||||
row = nodes.row()
|
row = nodes.row()
|
||||||
body.append(row)
|
body.append(row)
|
||||||
|
col = nodes.entry()
|
||||||
|
row.append(col)
|
||||||
|
text = nodes.literal(text=event_type)
|
||||||
|
col.append(text)
|
||||||
|
|
||||||
col = nodes.entry()
|
col = nodes.entry()
|
||||||
row.append(col)
|
row.append(col)
|
||||||
text = nodes.literal(text=name)
|
text = nodes.literal(text=name)
|
||||||
@@ -99,12 +111,19 @@ class VersionedNotificationDirective(Directive):
|
|||||||
|
|
||||||
col = nodes.entry()
|
col = nodes.entry()
|
||||||
row.append(col)
|
row.append(col)
|
||||||
ref = nodes.reference(refuri=self.LINK_PREFIX +
|
|
||||||
self.SAMPLE_ROOT + sample)
|
with open(self.SAMPLE_ROOT + sample_file, 'r') as f:
|
||||||
txt = nodes.inline()
|
sample_content = f.read()
|
||||||
col.append(txt)
|
|
||||||
txt.append(ref)
|
event_type = sample_file[0: -5]
|
||||||
ref.append(nodes.literal(text=sample))
|
html_str = self.TOGGLE_SCRIPT % ((event_type, ) * 3)
|
||||||
|
html_str += ("<input type='button' id='%s-hideshow' "
|
||||||
|
"value='hide/show sample'>" % event_type)
|
||||||
|
html_str += ("<div id='%s-div'><pre>%s</pre></div>"
|
||||||
|
% (event_type, sample_content))
|
||||||
|
|
||||||
|
raw = nodes.raw('', html_str, format="html")
|
||||||
|
col.append(raw)
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user