build_jsonrpc.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 (idx, i) in enumerate(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()[5][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, idx + 2))
  30. comment = ""
  31. continue
  32. comment += i[3:] + "\n"
  33. for i in methods:
  34. print(f"* [`{i[0]}`](#{i[0].replace('.', '')})")
  35. print("\n")
  36. for i in methods:
  37. print(f"### `{i[0]}`\n")
  38. print(f"{i[1]}")
  39. ghlink = "%s%s%s%d" % (
  40. "https://codeberg.org/darkrenaissance/darkfi/src/branch/master/",
  41. path.replace("../", ""),
  42. "#L",
  43. i[4],
  44. )
  45. print(f'<br><sup><a href="{ghlink}">[src]</a></sup>')
  46. print("\n```json")
  47. print(i[2])
  48. print(i[3])
  49. print("```")
  50. if __name__ == "__main__":
  51. main(argv[1])