build_jsonrpc.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python3
  2. from sys import argv
  3. def main(path):
  4. lines = []
  5. f = open(path, "r")
  6. read_lines = f.readlines()
  7. for line in read_lines:
  8. lines.append(line.strip())
  9. parsing_method = False
  10. methods = []
  11. method = ""
  12. comment = ""
  13. send = ""
  14. recv = ""
  15. for i in lines:
  16. if not i.startswith("//"):
  17. continue
  18. if i == ("// RPCAPI:"):
  19. parsing_method = True
  20. continue
  21. if parsing_method:
  22. if i.startswith("// --> "):
  23. method = i.split()[3][1:-2]
  24. recv = i[3:]
  25. continue
  26. if i.startswith("// <-- "):
  27. send = i[3:]
  28. parsing_method = False
  29. methods.append((method, comment.strip(), recv, send))
  30. comment = ""
  31. continue
  32. comment += i[3:] + "\n"
  33. print("\n## Methods")
  34. for i in methods:
  35. print(f"* [`{i[0]}`](#{i[0]})")
  36. print("\n")
  37. for i in methods:
  38. print(f"### `{i[0]}`\n")
  39. print(f"{i[1]}")
  40. print("\n```json")
  41. print(i[2])
  42. print(i[3])
  43. print("```")
  44. if __name__ == "__main__":
  45. main(argv[1])