1
0
mirror of https://github.com/minetest-mods/3d_armor.git synced 2024-12-26 18:50:40 +01:00
3d_armor/.ldoc/parse_crafts.py
Jordan Irwin c790b20169
Add Support for Generating HTML Documentation with LDoc (#58)
* Add Python scripts to generate temp files that can be parsed by LDoc
* Add config & script for generating HTML docs with LDoc...
* Add Lua docstrings for API & items
* Add workflow for building API reference docs on gh-pages branch
* Add LDoc's default stylesheet
* LDoc: make navigation panel fixed
2021-07-30 16:12:29 +02:00

47 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python
# This script will parse source files for craft recipes.
import sys, os, codecs, errno
path = os.path.realpath(__file__)
script = os.path.basename(path)
d_root = os.path.dirname(os.path.dirname(path))
d_ldoc = os.path.join(d_root, ".ldoc")
craftfile = os.path.realpath(os.path.join(d_root, "3d_armor/armor.lua"))
if not os.path.isfile(craftfile):
print("ERROR: craft file does not exist for parsing: {}".format(craftfile))
sys.exit(errnor.ENOENT)
buffer = codecs.open(craftfile, "r", "utf-8")
if not buffer:
print("ERROR: could not open file for reading: {}".format(craftfile))
sys.exit(errno.EIO)
data_in = buffer.read()
buffer.close()
craft = ""
data_in = data_in.replace("\r\n", "\n").replace("\r", "\n")
for sect in data_in.split("\n---"):
if "@craft armor" in sect:
sect = "---{}".format(sect)
for li in sect.split("\n"):
if li.startswith("--"):
craft = "{}\n{}".format(craft, li)
outfile = os.path.join(d_ldoc, "crafting.luadoc")
buffer = codecs.open(outfile, "w", "utf-8")
if not buffer:
print("ERROR: could not open file for writing: {}".format(outfile))
sys.exit(errno.EIO)
buffer.write("\n--- 3D Armor Crafting\n--\n-- @topic crafting\n\n{}\n".format(craft))
buffer.close()
print("crafts exported to\t{}".format(outfile))