Skip to content

Instantly share code, notes, and snippets.

@gs-niteesh
Created June 28, 2021 17:17
Show Gist options
  • Save gs-niteesh/7f8b7121ca8601bab2de699ebff6656e to your computer and use it in GitHub Desktop.
Save gs-niteesh/7f8b7121ca8601bab2de699ebff6656e to your computer and use it in GitHub Desktop.
qmp_show_doc.py
"""
Simple visitor
"""
import sys
from .schema import QAPISchema, QAPISchemaVisitor
class SimpleVisitor(QAPISchemaVisitor):
"""
Not used currently
"""
def visit_command(self, name, info, ifcond, features,
arg_type, ret_type, gen, success_response, boxed,
allow_oob, allow_preconfig, coroutine):
print("visit_command: name: {0},\n\tinfo: {1}, \n\tifcond: {2},\n\tfeatures: {3},\n\targ_type:{4}\
\n\tret_type: {5}".format(name, info, ifcond, features, arg_type, ret_type))
def visit_event(self, name, info, ifcond, features, arg_type, boxed):
print("visit_event: name: {0},\n\tinfo: {1}, \n\tifcond: {2},\n\tfeatures: {3},\n\targ_type:{4}\
\n\tboxed: {5}".format(name, info, ifcond, features, arg_type, boxed))
def visit_enum_type(self, name, info, ifcond, features, members, prefix):
print("visit_enum_type: name: {0},\n\tinfo: {1}, \n\tifcond: {2},\n\tfeatures: {3},\n\tmembers:{4}\
\n\tprefix: {5}".format(name, info, ifcond, features, members, prefix))
if __name__ == '__main__':
if len(sys.argv) != 2:
print ("Usage: python3 simple_visitor.py <file_name>")
sys.exit(0)
fname = sys.argv[1]
schema = QAPISchema(fname)
print("Visiting {0}".format(fname))
for i,doc in enumerate(schema.docs):
if doc.symbol:
print ('-----------------------------------------------------')
print('symbol: {0}'.format(doc.symbol))
print('Info: {0}'.format(doc.body.text))
print('Arguments')
for (key, value) in doc.args.items():
print('-- \t"{0}" - {1}'.format(key, value.text.replace('\n', ' ')))
for section in doc.sections:
if section.name == 'Example':
print ('{0}:\n{1}'.format(section.name, section.text))
else: print ('{0}: {1}'.format(section.name, section.text))
# schema.visit(SimpleVisitor())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment