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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
# Check if Markdown produced by --md-description is valid
#
# Requirements:
# - https://github.com/markdownlint/markdownlint
# (on Debian/Ubuntu - apt install markdownlint)
# (using Ruby installer - gem install mdl)
import os
import sys
import argparse
import subprocess
import grass.script as gs
def check_md(filename):
p = subprocess.Popen(["mdl", filename])
p.wait()
def print_line():
print("-" * 80)
def check_module(module):
print_line()
print(module)
tmp_file = gs.tempfile()
with open(tmp_file, "w") as fp:
p = subprocess.Popen([module, "--md-description"], stdout=fp)
p.wait()
p = subprocess.Popen(
[
"mdl",
"--style",
os.path.join(os.path.dirname(__file__), "mdl_style.rb"),
fp.name,
]
)
p.wait()
returncode = p.returncode
return returncode
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="A tool to check markdown files produced by --md-interface"
)
parser.add_argument("-m", "--module", required=False)
args = parser.parse_args()
if args.module is None:
blacklist = ["g.parser"] # modules with no description
mcount_failed = 0
list_cmd = sorted(gs.get_commands()[0])
for cmd in list_cmd:
if cmd not in blacklist:
if check_module(cmd) != 0:
mcount_failed += 1
print_line()
print("Modules processed {} ({} failed)".format(len(list_cmd), mcount_failed))
print_line()
sys.exit(mcount_failed == 0)
else:
sys.exit(check_module(args.module))
|