Compare commits
18 commits
4e369df232
...
db47d5c80a
Author | SHA1 | Date | |
---|---|---|---|
db47d5c80a | |||
04eaae7ba3 | |||
5a25c6df27 | |||
f8567686fd | |||
63c179a0a4 | |||
304c2bc617 | |||
5038e587af | |||
73c7ac00f4 | |||
f2991cff04 | |||
0ad5cc9701 | |||
6f9ba7f8f7 | |||
4d8c1d7aab | |||
148f757d5d | |||
f4498f691c | |||
c5930b4107 | |||
e75a624c46 | |||
9c1136cfa0 | |||
909e652f0d |
10 changed files with 140 additions and 17 deletions
|
@ -31,6 +31,11 @@ requires-python = ">= 3.11"
|
|||
[tool.hatch.version]
|
||||
path = "rwx/__init__.py"
|
||||
|
||||
[tool.pydoclint]
|
||||
allow-init-docstring = true
|
||||
skip-checking-short-docstrings = false
|
||||
style = "sphinx"
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 80
|
||||
|
||||
|
|
|
@ -4,6 +4,10 @@ import sys
|
|||
|
||||
|
||||
def split() -> tuple[str, list[str]]:
|
||||
"""Split command & actual arguments."""
|
||||
"""Split command & actual arguments.
|
||||
|
||||
:return: both
|
||||
:rtype: tuple[str, list[str]]
|
||||
"""
|
||||
command, *arguments = sys.argv
|
||||
return command, arguments
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
"""Control Operating Systems."""
|
||||
|
||||
from os import sep
|
||||
from pathlib import Path
|
||||
|
||||
from .abstract import OS
|
||||
from .debian import Debian
|
||||
|
||||
class OS:
|
||||
"""Operating System."""
|
||||
|
||||
def __init__(self, path: str) -> None:
|
||||
"""Set root."""
|
||||
self.root = Path(path)
|
||||
def from_path(path: Path) -> OS:
|
||||
"""Initialize from an already existing path."""
|
||||
return Debian(path)
|
||||
|
||||
|
||||
up = from_path(Path(sep))
|
||||
|
|
24
rwx/os/abstract.py
Normal file
24
rwx/os/abstract.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
"""Abstract Operating System."""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class OS(ABC):
|
||||
"""Operating System."""
|
||||
|
||||
def __init__(self, path: Path) -> None:
|
||||
"""Set root."""
|
||||
self.root = path
|
||||
self.name = self.get_name()
|
||||
|
||||
@abstractmethod
|
||||
def get_name(self) -> str:
|
||||
"""Return mandatory name."""
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Return root & name."""
|
||||
return f"""\
|
||||
root = {self.root}
|
||||
name = {self.name}
|
||||
"""
|
11
rwx/os/debian.py
Normal file
11
rwx/os/debian.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
"""Debian operating system."""
|
||||
|
||||
from .abstract import OS
|
||||
|
||||
|
||||
class Debian(OS):
|
||||
"""Debian operating system."""
|
||||
|
||||
def get_name(self) -> str:
|
||||
"""Return name."""
|
||||
return "Debian"
|
29
rwx/os/pm/__init__.py
Normal file
29
rwx/os/pm/__init__.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
"""Package Manager."""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from rwx.ps import Command
|
||||
|
||||
|
||||
class PM(ABC):
|
||||
"""Package Manager."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Set commands."""
|
||||
self.clean = self.get_clean_command()
|
||||
self.install = self.get_install_command()
|
||||
|
||||
@abstractmethod
|
||||
def get_clean_command(self) -> Command:
|
||||
"""Command to clean packages cache."""
|
||||
|
||||
@abstractmethod
|
||||
def get_install_command(self) -> Command:
|
||||
"""Command to install package(s)."""
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Return commands."""
|
||||
return f"""\
|
||||
clean = {self.clean}
|
||||
install = {self.install}
|
||||
"""
|
16
rwx/os/pm/apt.py
Normal file
16
rwx/os/pm/apt.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
"""Advanced Package Tool."""
|
||||
|
||||
from rwx.os.pm import PM
|
||||
from rwx.ps import Command
|
||||
|
||||
|
||||
class APT(PM):
|
||||
"""Advanced Package Tool."""
|
||||
|
||||
def get_clean_command(self) -> Command:
|
||||
"""Return clean command."""
|
||||
return Command()
|
||||
|
||||
def get_install_command(self) -> Command:
|
||||
"""Return install command."""
|
||||
return Command()
|
|
@ -6,8 +6,22 @@ from pathlib import Path
|
|||
class Project:
|
||||
"""Parent class for any type of project."""
|
||||
|
||||
def __init__(self, file_path: str) -> None:
|
||||
def __init__(self, file: Path) -> None:
|
||||
"""Set file, root & name."""
|
||||
self.file: Path = Path(file_path).resolve()
|
||||
self.raw = file
|
||||
self.file = self.raw.resolve()
|
||||
self.root: Path = self.file.parent
|
||||
self.name: str = self.root.name
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""Represent project."""
|
||||
return f"Project(file={self.raw!r})"
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Return file, root & name."""
|
||||
return f"""\
|
||||
raw = {self.raw}
|
||||
file = {self.file}
|
||||
root = {self.root}
|
||||
name = {self.name}
|
||||
"""
|
||||
|
|
|
@ -2,22 +2,18 @@
|
|||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
from sphinx.cmd.build import build_main
|
||||
|
||||
from rwx.fs import wipe
|
||||
from rwx.prj import Project
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class SphinxProject(Project):
|
||||
"""Child class for a project based on Sphinx."""
|
||||
|
||||
def __init__(self, file_path: str) -> None:
|
||||
"""Call the parent constructor."""
|
||||
super().__init__(file_path)
|
||||
|
||||
def build(self) -> None:
|
||||
"""Build the project."""
|
||||
output_root: Path = self.root / "out"
|
||||
|
@ -31,9 +27,9 @@ class SphinxProject(Project):
|
|||
"-D",
|
||||
f"project={self.name}",
|
||||
"-D",
|
||||
"master_doc={}".format("index"),
|
||||
"master_doc=index",
|
||||
"-D",
|
||||
"html_theme={}".format("sphinx_rtd_theme"),
|
||||
"html_theme=sphinx_rtd_theme",
|
||||
"-c",
|
||||
str(self.root),
|
||||
# "-C",
|
||||
|
|
|
@ -5,6 +5,26 @@ import subprocess
|
|||
from rwx import txt
|
||||
|
||||
|
||||
class Command:
|
||||
"""Command to run."""
|
||||
|
||||
def __init__(self, *arguments: str | tuple[str, ...]) -> None:
|
||||
"""Set raw & flat arguments."""
|
||||
self.raw = arguments
|
||||
self.flat: list[str] = []
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""Represent command."""
|
||||
return f"Command({self.raw!r})"
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Return raw & flat."""
|
||||
return f"""\
|
||||
raw = {self.raw}
|
||||
flat = {self.flat}
|
||||
"""
|
||||
|
||||
|
||||
def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]:
|
||||
"""Turn arguments tuples into an arguments list."""
|
||||
args: list[str] = []
|
||||
|
|
Loading…
Reference in a new issue