| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- import shutil
- import os
- import requests
- #bsp.h文件列表
- bsp_header_list = [
- {"name":"Air780EPM","url":"https://github.com/openLuat/luatos-soc-2024/raw/master/project/luatos/inc/luat_conf_bsp_air780epm.h"},
- {"name":"Air780E","url":"https://github.com/openLuat/luatos-soc-2022/raw/master/project/luatos/inc/luat_conf_bsp.h"},
- {"name":"Air780EP","url":"https://github.com/openLuat/luatos-soc-2024/raw/master/project/luatos/inc/luat_conf_bsp_dft.h"},
- {"name":"Air780EPS","url":"https://github.com/openLuat/luatos-soc-2024/raw/master/project/luatos/inc/luat_conf_bsp_air780eps.h"},
- {"name":"Air201","url":"https://github.com/openLuat/luatos-soc-2024/raw/master/project/luatos/inc/luat_conf_bsp_air201.h"},
- ]
- print("getting bsp.h files...")
- for bsp in bsp_header_list:
- print("getting "+bsp["name"]+"...")
- res = ""
- #有时候获取不到完整的数据,报错的页面就是html
- retry = 0
- while len(res) < 200 or res.find("</title>") != -1:
- res = requests.get(bsp["url"]).text
- print(str(len(res)) + " bytes")
- retry = retry + 1
- if retry > 5:
- print("failed to get "+bsp["name"]+" bsp.h file")
- break
- bsp["url"] = res
- print("done "+ str(len(bsp["url"])) + " bytes")
- def is_supported(tag, bsp) :
- if bsp["url"].find(" "+tag+" ") >= 0 or bsp["url"].find(" "+tag+"\r") >= 0 or bsp["url"].find(" "+tag+"\n") >= 0:
- return True
- def get_tags(tag, is_api = False):
- if len(tag) == 0:
- if is_api:
- return ""
- else:
- return "{bdg-secondary}`适配状态未知`"
- r = []
- if is_api:
- r.append("{bdg-success}`本接口仅支持`")
- else:
- r.append("{bdg-success}`已适配`")
- for bsp in bsp_header_list:
- if bsp["url"].find(" "+tag+" ") >= 0 or bsp["url"].find(" "+tag+"\r") >= 0 or bsp["url"].find(" "+tag+"\n") >= 0:
- r.append("{bdg-primary}`" + bsp["name"] + "`")
- if len(r) > 1:
- return " ".join(r)
- else:
- return "{bdg-secondary}`适配状态未知`"
- def make(path,modules,index_text):
- try:
- shutil.rmtree(path)
- except:
- pass
- os.mkdir(path)
- is_api = str(path).endswith("api/")
- # 创建表格
- if is_api :
- doc = open(path+"supported.md", "w+",encoding='utf-8')
- doc.write("# 适配状态\n\n")
- doc.write("|BSP/库|简介")
- for bsp in bsp_header_list:
- doc.write("|" + bsp["name"])
- doc.write("|\n")
- doc.write("|---|---")
- for bsp in bsp_header_list:
- doc.write("|---")
- doc.write("|\n")
- for module in modules:
- name = module["module"]
- doc.write("|[{}]({}.md)|`{}`".format(name, name, module["summary"]))
- for bsp in bsp_header_list:
- if len(module["tag"]) == 0 :
- doc.write("|?")
- continue
- if is_supported(module["tag"], bsp) :
- doc.write("|Y")
- else:
- doc.write("|X")
- doc.write("|\n")
- doc.close()
- doc = open(path+"index.md", "a+",encoding='utf-8')
- doc.write(index_text)
- # 创建toctree
- doc.write("\n\n请点击左侧列表,查看各个接口。如需搜索,请使用F5进行搜索。\n\n"+
- "```{toctree}\n")
- if is_api:
- doc.write("supported\n")
- for module in modules:
- doc.write(module["module"]+"\n")
- doc.write("```\n")
- doc.close()
- for module in modules:
- mdoc = open(path+module["module"]+".md", "a+",encoding='utf-8')
- mdoc.write("# "+module["module"]+" - "+module["summary"]+"\n\n")
- #支持的芯片
- # mdoc.write(get_tags(module["tag"]))
- # mdoc.write("\n\n")
- # if len(module["url"]) > 0:
- # mdoc.write("```{note}\n本页文档由[这个文件]("+module["url"]+")自动生成。如有错误,请提交issue或帮忙修改后pr,谢谢!\n```\n\n")
- # if len(module["demo"]) > 0:
- # mdoc.write("```{tip}\n本库有专属demo,[点此链接查看"+module["module"]+"的demo例子]("+module["demo"]+")\n```\n")
- # if len(module["video"]) > 0:
- # mdoc.write("```{tip}\n本库还有视频教程,[点此链接查看]("+module["video"]+")\n```\n\n")
- # else:
- # mdoc.write("\n")
- if len(module["usage"]) > 0:
- mdoc.write("**示例**\n\n")
- mdoc.write("```lua\n"+module["usage"]+"\n```\n\n")
- if len(module["const"]) > 0:
- mdoc.write("## 常量\n\n")
- mdoc.write("|常量|类型|解释|\n|-|-|-|\n")
- for const in module["const"]:
- mdoc.write("|"+const["var"].replace("|","\|")+"|"+const["type"].replace("|","\|")+"|"+const["summary"].replace("|","\|")+"|\n")
- mdoc.write("\n\n")
-
- for api in module["api"]:
- mdoc.write("## "+api["api"]+"\n\n")
- #支持的芯片
- mdoc.write(get_tags(api["tag"], True))
- mdoc.write("\n\n")
- mdoc.write(api["summary"]+"\n\n")
- mdoc.write("**参数**\n\n")
- if len(api["args"]) > 0:
- mdoc.write("|传入值类型|解释|\n|-|-|\n")
- for arg in api["args"]:
- mdoc.write("|"+arg["type"].replace("|","\|")+"|"+arg["summary"].replace("|","\|")+"|\n")
- mdoc.write("\n")
- else:
- mdoc.write("无\n\n")
- mdoc.write("**返回值**\n\n")
- if len(api["return"]) > 0:
- mdoc.write("|返回值类型|解释|\n|-|-|\n")
- for arg in api["return"]:
- mdoc.write("|"+arg["type"].replace("|","\|")+"|"+arg["summary"].replace("|","\|")+"|\n")
- mdoc.write("\n")
- else:
- mdoc.write("无\n\n")
- mdoc.write("**例子**\n\n")
- if len(api["usage"]) == 0:
- mdoc.write("无\n\n")
- else:
- mdoc.write("```lua\n"+api["usage"]+"\n```\n\n")
- mdoc.write("---\n\n")
- mdoc.close()
- def get_description(api):
- s = api["api"]+" - "+api["summary"]+"\n"
- if len(api["args"]) > 0:
- s = s + "传入值:\n"
- for arg in api["args"]:
- s = s + arg["type"] + " " + arg["summary"]+"\n"
- if len(api["return"]) > 0:
- s = s + "返回值:\n"
- for arg in api["return"]:
- s = s + arg["type"] + " " + arg["summary"]+"\n"
- if len(api["usage"]) > 0:
- s = s + "例子:\n" + api["usage"]
- return s
|