build_jsonrpc.py
1 #!/usr/bin/env python3 2 from sys import argv 3 4 5 def main(path): 6 lines = [] 7 8 f = open(path, "r") 9 read_lines = f.readlines() 10 for line in read_lines: 11 lines.append(line.strip()) 12 13 parsing_method = False 14 15 methods = [] 16 method = "" 17 comment = "" 18 send = "" 19 recv = "" 20 21 for (idx, i) in enumerate(lines): 22 if not i.startswith("//"): 23 continue 24 25 if i == ("// RPCAPI:"): 26 parsing_method = True 27 continue 28 29 if parsing_method: 30 if i.startswith("// --> "): 31 method = i.split()[5][1:-2] 32 recv = i[3:] 33 continue 34 35 if i.startswith("// <-- "): 36 send = i[3:] 37 parsing_method = False 38 methods.append((method, comment.strip(), recv, send, idx + 2)) 39 comment = "" 40 continue 41 42 comment += i[3:] + "\n" 43 44 for i in methods: 45 print(f"* [`{i[0]}`](#{i[0].replace('.', '')})") 46 47 print("\n") 48 for i in methods: 49 print(f"### `{i[0]}`\n") 50 print(f"{i[1]}") 51 ghlink = "%s%s%s%d" % ( 52 "https://codeberg.org/darkrenaissance/darkfi/src/branch/master/", 53 path.replace("../", ""), 54 "#L", 55 i[4], 56 ) 57 print(f'<br><sup><a href="{ghlink}">[src]</a></sup>') 58 print("\n```json") 59 print(i[2]) 60 print(i[3]) 61 print("```") 62 63 64 if __name__ == "__main__": 65 main(argv[1])