Compare commits
No commits in common. "78dd431ca5fd969841774f9deb4129d9eb299c7f" and "3393f0990742dda006ded747dae2e50319356af2" have entirely different histories.
78dd431ca5
...
3393f09907
3 changed files with 19 additions and 22 deletions
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from rwx import ps
|
from rwx import ps
|
||||||
|
|
||||||
|
@ -49,23 +48,20 @@ def get_path_uuid(path: str) -> str:
|
||||||
|
|
||||||
def make_directory(path: str) -> None:
|
def make_directory(path: str) -> None:
|
||||||
"""Make a directory (and its parents) from a path."""
|
"""Make a directory (and its parents) from a path."""
|
||||||
Path(path).mkdir(exist_ok=True, parents=True)
|
os.makedirs(path, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
def read_file_bytes(file_path: str) -> bytes:
|
def read_file(file_path: str):
|
||||||
"""Read whole file bytes."""
|
with open(file_path, "br") as file_object:
|
||||||
with Path(file_path).open("br") as file_object:
|
|
||||||
return file_object.read()
|
return file_object.read()
|
||||||
|
|
||||||
|
|
||||||
def read_file_lines(file_path: str, charset: str = CHARSET) -> list[str]:
|
def read_file_lines(file_path: str, charset: str = CHARSET):
|
||||||
"""Read whole file lines."""
|
return read_file_text(file_path).split(os.linesep)
|
||||||
return read_file_text(file_path, charset).split(os.linesep)
|
|
||||||
|
|
||||||
|
|
||||||
def read_file_text(file_path: str, charset: str = CHARSET) -> str:
|
def read_file_text(file_path: str, charset: str = CHARSET):
|
||||||
"""Read whole file text."""
|
return read_file(file_path).decode(charset)
|
||||||
return read_file_bytes(file_path).decode(charset)
|
|
||||||
|
|
||||||
|
|
||||||
def wipe(path: str) -> None:
|
def wipe(path: str) -> None:
|
||||||
|
@ -73,12 +69,12 @@ def wipe(path: str) -> None:
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
except NotADirectoryError:
|
except NotADirectoryError:
|
||||||
Path(path).unlink(missing_ok=True)
|
os.remove(path)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def write(file_path: str, text: str, charset: str = CHARSET) -> None:
|
def write(file_path: str, text: str, charset: str = CHARSET) -> None:
|
||||||
"""Write text into a file."""
|
"""Write text into a file."""
|
||||||
with Path(file_path).open(encoding=charset, mode="w") as file_object:
|
with open(file_path, "bw") as file_object:
|
||||||
file_object.write(text)
|
file_object.write(text.encode(charset))
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""Handle projects."""
|
"""Handle projects."""
|
||||||
|
|
||||||
from os.path import realpath
|
from os import path
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
class Project:
|
class Project:
|
||||||
|
@ -9,6 +8,6 @@ class Project:
|
||||||
|
|
||||||
def __init__(self, file_path: str) -> None:
|
def __init__(self, file_path: str) -> None:
|
||||||
"""Set file, root & name."""
|
"""Set file, root & name."""
|
||||||
self.file: str = realpath(file_path)
|
self.file: str = path.realpath(file_path)
|
||||||
self.root: str = Path(self.file).parent
|
self.root: str = path.dirname(self.file)
|
||||||
self.name: str = self.root.name
|
self.name: str = path.basename(self.root)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
"""Project consisting only of a Sphinx documentation."""
|
"""Project consisting only of a Sphinx documentation."""
|
||||||
|
|
||||||
|
from os import path
|
||||||
|
|
||||||
from sphinx.cmd.build import build_main
|
from sphinx.cmd.build import build_main
|
||||||
|
|
||||||
from rwx.fs import wipe
|
from rwx.fs import wipe
|
||||||
|
@ -15,7 +17,7 @@ class SphinxProject(Project):
|
||||||
|
|
||||||
def build(self) -> None:
|
def build(self) -> None:
|
||||||
"""Build the project."""
|
"""Build the project."""
|
||||||
output_root: str = self.root / "out"
|
output_root: str = path.join(self.root, "out")
|
||||||
wipe(output_root)
|
wipe(output_root)
|
||||||
arguments: list[str] = [
|
arguments: list[str] = [
|
||||||
"-E",
|
"-E",
|
||||||
|
@ -32,7 +34,7 @@ class SphinxProject(Project):
|
||||||
"-c",
|
"-c",
|
||||||
self.root,
|
self.root,
|
||||||
# "-C",
|
# "-C",
|
||||||
self.root / self.name,
|
path.join(self.root, self.name),
|
||||||
output_root / "web",
|
path.join(output_root, "web"),
|
||||||
]
|
]
|
||||||
build_main(arguments)
|
build_main(arguments)
|
||||||
|
|
Loading…
Reference in a new issue