Commit ab3cd274 authored by Federico Sismondi's avatar Federico Sismondi

fix doc automatic gen for buiding Core API events doc in different sections

parent ca3764c7
......@@ -7,9 +7,9 @@ from messages import *
gitlab_url = 'https://gitlab.f-interop.eu/f-interop-contributors/utils/blob/master/messages.py'
doc_parser = 'https://gitlab.f-interop.eu/f-interop-contributors/utils/blob/master/messages_doc.py'
header = """Messages format
header = """CORE API Events
This section describes the format of the messages used by the testing tool.
This section describes the format of the messages used in F-Interop.
This section of the documentation is autogenerated by
[tool](%s)
......@@ -124,98 +124,140 @@ TBD listens and consumes the following messages from the bus:
print(table_row(e._type))
if __name__ == '__main__':
def generate_doc_section_into_file(file_to_write, section, list_of_message_classes):
f = file_to_write
f.write('\n\n## %s' % (section))
with open('_messages.md', "w+") as f:
for msg_class in list_of_message_classes:
# Message Type
f.write('# %s' % (header))
msg_type = msg_class()._type
print('generating doc for %s,%s' % (msg_type, msg_class))
for msg_type, msg_class in sorted(message_types_dict.items()):
# Message Type
f.write('\n\n\n### %s' % (msg_type))
# Message Type
f.write('\n\n\n## %s' % (msg_type))
# Header
#f.write('\n\n#### Description:\n\n')
# Header
f.write('\n\n### Description:\n\n')
# markdown table header
f.write("\n| []() | |\n| --- | --- |\n")
# markdown table header
f.write("\n| []() | |\n| --- | --- |\n")
try:
# add routing key in table
f.write("|Routing key|{0}|\n".format(msg_class().routing_key))
except TypeError as te:
print("No routing key found for %s" % repr(msg_class))
md_bullet_list = ''
unknown = ''
md_bullet_list = ''
unknown = ''
# Message class docstring to table
for line in msg_class.__doc__.splitlines():
if line and not line.isspace():
# Message class docstring to table
for line in msg_class.__doc__.splitlines():
if line and not line.isspace():
if "description:" in str(line).lower():
sp_line = line.split(':')
if len(sp_line) > 1:
f.write("|Description:|{0}|\n".format(sp_line[1].strip()))
elif len(sp_line) == 1:
f.write("|Description:||\n")
else:
raise NotImplementedError()
if "description:" in str(line).lower():
sp_line = line.split(':')
if len(sp_line) > 1:
f.write("|Description:|{0}|\n".format(sp_line[1].strip()))
elif len(sp_line) == 1:
f.write("|Description:||\n")
else:
raise NotImplementedError()
elif '- ' in line:
md_bullet_list += "||{0}|\n".format(line.strip())
elif '- ' in line:
md_bullet_list += "||{0}|\n".format(line.strip())
elif "Type:" in line:
sp_line = line.split(':')
f.write('|{0}|{1}|\n'.format(sp_line[0].strip(), sp_line[1].strip()))
elif "Type:" in line:
sp_line = line.split(':')
f.write('|{0}|{1}|\n'.format(sp_line[0].strip(), sp_line[1].strip()))
elif "Requirements:" in line:
sp_line = line.split(':')
f.write('|{0}|{1}|\n'.format(sp_line[0].strip(), sp_line[1].strip()))
elif "Requirements:" in line:
sp_line = line.split(':')
f.write('|{0}|{1}|\n'.format(sp_line[0].strip(), sp_line[1].strip()))
elif "Pub/Sub:" in line:
sp_line = line.split(':')
f.write('|{0}|{1}|\n'.format(sp_line[0].strip(), sp_line[1].strip()))
elif "Pub/Sub:" in line or "Typical_use:" in line:
sp_line = line.split(':')
f.write('|{0}|{1}|\n'.format(sp_line[0].strip(), sp_line[1].strip()))
else:
if md_bullet_list is not '':
md_bullet_list += '||{0}|\n'.format(line)
else:
if md_bullet_list is not '':
md_bullet_list += '||{0}|\n'.format(line)
else:
unknown += '||{0}|\n'.format(line)
unknown += '||{0}|\n'.format(line)
f.write(md_bullet_list)
f.write(unknown)
f.write(md_bullet_list)
f.write(unknown)
# Message code source:
line_number = (inspect.findsource(msg_class)[1])
url = gitlab_url + "#L%s" % line_number
f.write('\n\n### Source code: \n[%s](%s)\n' % (msg_class.__name__, url))
# Message code source:
line_number = (inspect.findsource(msg_class)[1])
url = gitlab_url + "#L%s" % line_number
f.write('\n\nSource code: [%s](%s)\n' % (msg_class.__name__, url))
msg_instance = None
msg_instance = None
# Messages's example AMQP + JSON
if 'reply' not in msg_class.__name__.lower(): # Message is not a reply
msg_instance = msg_class()
# Messages's example AMQP + JSON
if 'reply' not in msg_class.__name__.lower(): # Message is not a reply
msg_instance = msg_class()
else: # Message is a reply -> we need to generate it using a request
reply_class_name = msg_class.__name__
request_class_name = ''
else: # Message is a reply -> we need to generate it using a request
reply_class_name = msg_class.__name__
request_class_name = ''
if 'reply' in msg_class.__name__:
request_class_name = reply_class_name.replace("reply", '')
elif 'Reply' in msg_class.__name__:
request_class_name = reply_class_name.replace("Reply", '')
else:
raise Exception('cannot process message event: %s' % msg_type)
if 'reply' in msg_class.__name__:
request_class_name = reply_class_name.replace("reply", '')
elif 'Reply' in msg_class.__name__:
request_class_name = reply_class_name.replace("Reply", '')
else:
raise Exception('cannot process message event: %s' % msg_type)
request_instance = globals()[request_class_name]()
msg_instance = msg_class(request_message=request_instance)
request_instance = globals()[request_class_name]()
msg_instance = msg_class(request_message=request_instance)
# add the amqo + json section
message_amqp_section(f, msg_instance)
message_json_section(f, msg_instance)
# add the amqo + json section
message_amqp_section(f, msg_instance)
message_json_section(f, msg_instance)
try:
if 'service' in msg_instance.routing_key:
services.append(msg_instance)
else:
events.append(msg_instance)
except TypeError as te:
print("error found trying to document %s, \nerror %s" % (msg_instance, te))
if __name__ == '__main__':
tt_messages = [
MsgTestingToolReady,
MsgSessionConfiguration,
MsgTestingToolConfigured,
MsgTestSuiteStart,
MsgTestSuiteReport,
MsgTestingToolTerminate,
]
so_messages = [
MsgOrchestratorVersionReq
]
ui_messages = [
MsgUiRequestTextInput
]
results_repo_messages = [
]
resurces_repo_messages = [
]
with open('_messages.md', "w+") as f:
# Message Type
f.write('# %s' % (header))
generate_doc_section_into_file(f, 'Orchestrator events', so_messages)
generate_doc_section_into_file(f, 'User interface events', ui_messages)
generate_doc_section_into_file(f, 'Testing Tool events', tt_messages)
generate_doc_section_into_file(f, 'Results Repository events', results_repo_messages)
generate_doc_section_into_file(f, 'Resources Repository events', resurces_repo_messages)
print_doc_tables(services, events)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment