salt/tools/docs.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
2.6 KiB
Python
Raw Normal View History

2023-01-24 22:14:48 -07:00
"""
These commands are used to generate Salt's manpages.
"""
# pylint: disable=resource-leakage,broad-except
from __future__ import annotations
import logging
import os
import pathlib
import shutil
import sys
2023-01-24 22:14:48 -07:00
from ptscripts import Context, command_group
import tools.utils
2023-01-24 22:14:48 -07:00
log = logging.getLogger(__name__)
2023-01-24 22:14:48 -07:00
# Define the command group
docs = command_group(
name="docs",
help="Manpages tools",
description=__doc__,
venv_config={
"requirements_files": [
tools.utils.REPO_ROOT
/ "requirements"
/ "static"
/ "ci"
/ "py{}.{}".format(*sys.version_info)
/ "docs.txt"
],
},
)
2023-01-24 22:14:48 -07:00
2023-01-25 01:09:32 -07:00
@docs.command(
2023-01-24 22:14:48 -07:00
name="man",
arguments={
"no_clean": {
"help": "Don't cleanup prior to building",
}
},
2023-01-24 22:14:48 -07:00
)
def man(ctx: Context, no_clean: bool = False):
if no_clean is False:
ctx.run("make", "clean", cwd="doc/", check=True)
2023-01-25 00:18:08 -07:00
ctx.run("make", "man", "SHPINXOPTS=-W", cwd="doc/", check=True)
2023-01-24 22:14:48 -07:00
for root, dirs, files in os.walk("doc/_build/man"):
for file in files:
shutil.copy(os.path.join(root, file), os.path.join("doc/man", file))
@docs.command(
2023-01-24 22:14:48 -07:00
name="html",
arguments={
"no_clean": {
"help": "Don't cleanup prior to building",
},
"archive": {
"help": "Compress the generated documentation into the provided archive.",
},
},
2023-01-24 22:14:48 -07:00
)
def html(ctx: Context, no_clean: bool = False, archive: pathlib.Path = None):
if no_clean is False:
ctx.run("make", "clean", cwd="doc/", check=True)
2023-01-24 22:14:48 -07:00
ctx.run("make", "html", "SHPINXOPTS=-W", cwd="doc/", check=True)
if archive is not None:
ctx.info(f"Compressing the generated documentation to '{archive}'...")
ctx.run("tar", "caf", str(archive.resolve()), ".", cwd="doc/_build/html")
2023-01-24 22:14:48 -07:00
@docs.command(
2023-01-24 22:14:48 -07:00
name="epub",
arguments={
"no_clean": {
"help": "Don't cleanup prior to building",
}
},
2023-01-24 22:14:48 -07:00
)
def epub(ctx: Context, no_clean: bool = False):
if no_clean is False:
ctx.run("make", "clean", cwd="doc/", check=True)
2023-01-24 22:14:48 -07:00
ctx.run("make", "epub", "SHPINXOPTS=-W", cwd="doc/", check=True)
@docs.command(
2023-01-24 22:14:48 -07:00
name="pdf",
arguments={
"no_clean": {
"help": "Don't cleanup prior to building",
}
},
2023-01-24 22:14:48 -07:00
)
def pdf(ctx: Context, no_clean: bool = False):
2023-01-24 22:14:48 -07:00
if not shutil.which("inkscape"):
ctx.warn("No inkscape binary found")
ctx.exit(1)
if no_clean is False:
ctx.run("make", "clean", cwd="doc/", check=True)
2023-01-24 22:14:48 -07:00
ctx.run("make", "pdf", "SHPINXOPTS=-W", cwd="doc/", check=True)