|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Just a quick wrapper around what is in runestone utils to make it easier to do a full build |
| 4 | +# of a PreTeXt book outside of docker |
| 5 | +import os |
| 6 | +import subprocess |
| 7 | +import sys |
| 8 | +import pathlib |
| 9 | +from runestone.server.utils import _build_ptx_book |
| 10 | + |
| 11 | +p = pathlib.Path.cwd() |
| 12 | + |
| 13 | +if len(sys.argv) < 2: |
| 14 | + if (p / "project.ptx").exists(): # we are in a pretext project |
| 15 | + print(f"Building {p.name} in place") |
| 16 | + bookname = p.name |
| 17 | + else: |
| 18 | + print("You must either name a book or be in the book's folder") |
| 19 | + exit(-1) |
| 20 | + |
| 21 | +elif p.name != sys.argv[1] and "BOOK_PATH" in os.environ: |
| 22 | + print("Not in the right folder") |
| 23 | + newp = pathlib.Path(os.environ["BOOK_PATH"], sys.argv[1]) |
| 24 | + print(f"Trying to change to {newp}") |
| 25 | + if newp.exists(): |
| 26 | + os.chdir(newp) |
| 27 | + bookname = sys.argv[1] |
| 28 | + else: |
| 29 | + print(f"{newp} does not exist") |
| 30 | + print("Build Failed") |
| 31 | + exit(-1) |
| 32 | + |
| 33 | + |
| 34 | +class Config: |
| 35 | + def __init__(self): |
| 36 | + conf = os.environ.get("WEB2PY_CONFIG", "production") |
| 37 | + if conf == "production": |
| 38 | + self.dburl = os.environ.get("DBURL") |
| 39 | + elif conf == "development": |
| 40 | + self.dburl = os.environ.get("DEV_DBURL") |
| 41 | + elif conf == "test": |
| 42 | + self.dburl = os.environ.get("TEST_DBURL") |
| 43 | + else: |
| 44 | + print("Incorrect WEB2PY_CONFIG") |
| 45 | + |
| 46 | + |
| 47 | +config = Config() |
| 48 | +assert bookname |
| 49 | + |
| 50 | +res = _build_ptx_book(config, False, "runestone-manifest.xml", bookname) |
| 51 | +if not res: |
| 52 | + print("build failed") |
| 53 | + exit(-1) |
| 54 | + |
| 55 | +res = subprocess.run(f"chgrp -R www-data .", shell=True, capture_output=True) |
| 56 | +if res.returncode != 0: |
| 57 | + print("failed to change group") |
| 58 | + exit(-1) |
| 59 | +res = subprocess.run(f"chmod -R go+rw .", shell=True, capture_output=True) |
| 60 | +if res.returncode != 0: |
| 61 | + print("failed to change permissions") |
| 62 | + exit(-1) |
0 commit comments