build_jsonrpc.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. 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. ghlink = "%s%s%s%d" % (
  41. "https://github.com/darkrenaissance/darkfi/blob/master/",
  42. path.replace("../", ""),
  43. "#L",
  44. i[4],
  45. )
  46. print(f'<br><sup><a href="{ghlink}">[src]</a></sup>')
  47. print("\n```json")
  48. print(i[2])
  49. print(i[3])
  50. print("```")
  51. if __name__ == "__main__":
  52. main(argv[1])