#!/usr/bin/python3 import os import operator import sys files = {} for x in os.listdir(sys.argv[1]): if x.endswith(".doxy"): with open(sys.argv[1]+x, "r", encoding="utf-8") as fin: for line in fin.readlines(): if "\page" in line: line = line.replace("/*! \page ", "").strip() files[x] = line[0:line.index(" ")]+".html" sfiles= dict(sorted(files.items(), key=operator.itemgetter(0))) htmlfiles = ["index.html"] htmlfiles.extend(sfiles.values()) htmldir=sys.argv[2]+"/" chapter=0 for x in htmlfiles: chapter+=1 section=0 with open(htmldir+x, "r", encoding="utf-8") as fin: with open(htmldir+x+".count.html", "w", encoding="utf-8") as fout: for line in fin.readlines(): if "
" in line: line = line.replace("
", "
"+str(chapter)+". ") if "

" in line: section += 1 line = line.replace("

", "

" + str(chapter) + "." + str(section)) subsection = 0 if "

" in line: subsection += 1 line = line.replace("

", "

" + str(chapter) + "." + str(section) + "." + str(subsection)) subsubsection = 0 if "

" in line: subsubsection += 1 line = line.replace("

", "

" + str(chapter) + "." + str(section) + "." + str(subsection) + "." + str(subsubsection)) fout.write(line) os.rename(htmldir+x+".count.html", htmldir+x)