Last active
May 30, 2025 18:27
-
-
Save glimchb/58416b643df31b27332062d775017d85 to your computer and use it in GitHub Desktop.
SPDK doc/jsonrpc.md table formatter using tabulate package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################### | |
import re | |
from tabulate import tabulate | |
with open("doc/jsonrpc.md.out", "w") as wfile: | |
with open("doc/jsonrpc.md", "r") as rfile: | |
in_table = False | |
for line in rfile.readlines(): | |
if re.search("Name.+?\|.+?Optional.+?\|.+?Type.+?\|.+?Description", line): | |
# print(">>", line ) | |
in_table = True | |
params = [] | |
continue | |
if not in_table: | |
wfile.write(line) | |
continue | |
if in_table: | |
# print("<<", line ) | |
if "--------" in line: | |
# skip separator line | |
continue | |
if not line.strip(): | |
in_table = False | |
params = tabulate(params, headers="keys", tablefmt="presto").replace("-+-", " | ") | |
wfile.write(params) | |
params = [] | |
wfile.write("\n\n") | |
continue | |
fname, foptional, ftype, fdescription = line.split("|") | |
params.append(dict(Name=fname.strip(), Optional=foptional.strip(), Type=ftype.strip(), Description=fdescription.strip())) | |
################################################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment