1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
ROOT_PATH = os.path.abspath( os.path.join(os.path.dirname( __file__ ), ".."))
files = os.listdir(os.path.join(ROOT_PATH, "doc"))
index = []
for fname in sorted(files):
if not fname.endswith(".txt"):
continue
cmd_name = fname[:-4]
with open(os.path.join(ROOT_PATH, "doc", fname), "r") as f:
contents = f.read()
f.close()
out_file = os.path.join(ROOT_PATH, "temp-man-pages", "%s.md" % cmd_name)
with open(out_file, "w") as f:
s = "# %s {#%s}\n\n```\n%s\n```\n" % (cmd_name, cmd_name, contents)
f.write(s)
f.close()
index.append(cmd_name)
print(" wrote %s" % out_file)
out_file = os.path.join(ROOT_PATH, "temp-man-pages", "index.md")
s = "Man Pages {#man-pages}\n"
s += "=========================\n\n"
for page in index:
s += "- @subpage %s\n" % page
s += "\n"
with open(out_file, "w") as f:
f.write(s)
f.close()
|