import os import json import argparse def get_arch_data(repo): # fetch architecture and tools info from the settings file and write a temproary rst file # for inclusion in the "befire you start" section settingsFile = repo + '/settings.json' if os.path.isfile(settingsFile): with open(settingsFile) as infile: data = json.load(infile) try: return data['architectures'] except KeyError: print("No architecture or tools info available, no architeture_tools_info page created.") exit() else: print("No settings file found, no architeture_tools_info page created.") exit() def build_arch_tools_page(arch, rstFile): headingC0 = "Architecture" headingC1 = "Tools version" with open(rstFile, "w") as outFile: outFile.write("Supported xcore architectures and required tools\n") outFile.write("================================================\n") outFile.write("\n") a=0 a0=len(headingC0) b=0 b0=len(headingC1) for k in arch.keys(): a=max(len(k), a, a0) for v in arch[k]: b=max(len(v), b, b0) divc0="" for i in range(0,a+2): divc0+="-" divc1="" for i in range(0,b+2): divc1+="-" outFile.write(("+{}+{}+\n").format(divc0, divc1)) padc0="" for i in range(0,a-a0): padc0+=" " padc1="" for i in range(0,b-b0): padc1+=" " outFile.write(("| {}{} | {}{} |\n").format(headingC0, padc0, headingC1, padc1)) barc0="" for i in range(0,a+2): barc0+="=" barc1="" for i in range(0,b+2): barc1+="=" outFile.write(("+{}+{}+\n").format(barc0, barc1)) for k in arch.keys(): for v in arch[k]: pada="" for i in range(0,a-len(k)): pada+=" " padb="" for i in range(0,b-len(v)): padb+=" " outFile.write(("| {}{} | {}{} |\n").format(k, pada, v, padb)) outFile.write(("+{}+{}+\n").format(divc0, divc1)) outFile.close() if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-p", help='path to repo') parser.add_argument("-o", default='./_templates/architecture_tools_info.rst', help='optional path and filename of the resulting html file.') args = parser.parse_args() build_arch_tools_page(get_arch_data(args.p), args.o)