1
0
Fork 0

Sphinx: simplify running process as another user

This commit is contained in:
Brecht Van Lommel 2023-05-09 16:45:35 +02:00
commit 5c53375672
2 changed files with 7 additions and 18 deletions

View file

@ -10,11 +10,7 @@ import subprocess
import sys
import tempfile
parser = argparse.ArgumentParser(prog="sphinx_to_html")
parser.add_argument("filename_rst", help="Input .rst file")
parser.add_argument("--user", help="Run sphinx as another user", type=str)
parser.add_argument("--user-work-dir", help="Do work in specified folder accessible by user", type=str)
args = parser.parse_args()
page_contents = sys.stdin.read()
base_url = "https://projects.blender.org"
local_url = "http://localhost:3000"
@ -44,15 +40,12 @@ else:
image_url = ""
# Set up temporary directory with sphinx configuration.
with tempfile.TemporaryDirectory(dir=args.user_work_dir) as tmp_dir:
with tempfile.TemporaryDirectory() as tmp_dir:
work_dir = pathlib.Path(tmp_dir) / "work"
script_dir = pathlib.Path(__file__).parent.resolve()
shutil.copytree(script_dir / "template", work_dir)
page_filepath = work_dir / "contents.rst"
shutil.copyfile(args.filename_rst, page_filepath)
page_contents = page_filepath.read_text()
# Turn links into external links since internal links are not found and stripped.
def path_to_label(path):
@ -103,10 +96,7 @@ with tempfile.TemporaryDirectory(dir=args.user_work_dir) as tmp_dir:
out_filepath = out_dir / "contents.html"
sphinx_cmd = ["sphinx-build", "-b", "html", work_dir, out_dir]
if args.user:
result = subprocess.run(sphinx_cmd, capture_output=True, user=args.user)
else:
result = subprocess.run(sphinx_cmd, capture_output=True)
result = subprocess.run(sphinx_cmd, capture_output=True)
# Output errors.
error = result.stderr.decode("utf-8", "ignore").strip()