Shorten Module.orchestrator and Orchestrator.console
`Orchestrator.console` was shortened to `Orchestrator.c` for convenience so that a function `@module def foo(o: Orchestrator, ...)` can just use `o.c.print` instead of `o.console.print`. Existing `class Foo(Module)` should still use `self.c` like before. Module.orchestrator was shortened to Module.o for convenience and consistency with `Module.c`.
This commit is contained in:
parent
5bb1105f38
commit
442f389b36
3 changed files with 10 additions and 15 deletions
|
|
@ -113,7 +113,7 @@ class Files(Module):
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(orchestrator)
|
super().__init__(orchestrator)
|
||||||
self._files: dict[str, bytes] = {}
|
self._files: dict[str, bytes] = {}
|
||||||
self._file_db = FileDb(self.orchestrator.state_dir / file_db_name)
|
self._file_db = FileDb(self.o.state_dir / file_db_name)
|
||||||
self._root = root or Path.home()
|
self._root = root or Path.home()
|
||||||
|
|
||||||
def _read_path(self, path: Path | str) -> Path:
|
def _read_path(self, path: Path | str) -> Path:
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ class Pacman(Module):
|
||||||
return self._resolve_packages(groups, packages)
|
return self._resolve_packages(groups, packages)
|
||||||
|
|
||||||
def _install_packages(self, packages: set[str]) -> None:
|
def _install_packages(self, packages: set[str]) -> None:
|
||||||
if self.orchestrator.dry_run:
|
if self.o.dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
if packages:
|
if packages:
|
||||||
|
|
@ -88,7 +88,7 @@ class Pacman(Module):
|
||||||
self._pacman_execute("-D", "--asexplicit", *sorted(packages))
|
self._pacman_execute("-D", "--asexplicit", *sorted(packages))
|
||||||
|
|
||||||
def _uninstall_packages(self, packages: set[str]) -> None:
|
def _uninstall_packages(self, packages: set[str]) -> None:
|
||||||
if self.orchestrator.dry_run:
|
if self.o.dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
if packages:
|
if packages:
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,9 @@ from xdg_base_dirs import xdg_state_home
|
||||||
|
|
||||||
class Module(ABC):
|
class Module(ABC):
|
||||||
def __init__(self, orchestrator: Orchestrator) -> None:
|
def __init__(self, orchestrator: Orchestrator) -> None:
|
||||||
self.orchestrator = orchestrator
|
self.o = orchestrator
|
||||||
self.orchestrator.register(self)
|
self.o.register(self)
|
||||||
self.c = self.orchestrator.console
|
self.c = self.o.c
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def realize(self) -> None: ...
|
def realize(self) -> None: ...
|
||||||
|
|
@ -29,19 +29,14 @@ def _snake_to_camel(s: str) -> str:
|
||||||
def module[**P](
|
def module[**P](
|
||||||
func: Callable[Concatenate[Orchestrator, P], None],
|
func: Callable[Concatenate[Orchestrator, P], None],
|
||||||
) -> Callable[Concatenate[Orchestrator, P], None]:
|
) -> Callable[Concatenate[Orchestrator, P], None]:
|
||||||
def __init__(
|
def __init__(self, o: Orchestrator, *args: P.args, **kwargs: P.kwargs) -> None:
|
||||||
self,
|
super(self.__class__, self).__init__(o)
|
||||||
orchestrator: Orchestrator,
|
|
||||||
*args: P.args,
|
|
||||||
**kwargs: P.kwargs,
|
|
||||||
) -> None:
|
|
||||||
super(self.__class__, self).__init__(orchestrator)
|
|
||||||
self.args = args
|
self.args = args
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
def realize(self) -> None:
|
def realize(self) -> None:
|
||||||
# pyrefly: ignore
|
# pyrefly: ignore
|
||||||
return func(self.orchestrator, *self.args, **self.kwargs)
|
return func(self.o, *self.args, **self.kwargs)
|
||||||
|
|
||||||
# pyrefly: ignore
|
# pyrefly: ignore
|
||||||
return type(
|
return type(
|
||||||
|
|
@ -57,7 +52,7 @@ class Orchestrator:
|
||||||
self.dry_run = dry_run
|
self.dry_run = dry_run
|
||||||
|
|
||||||
self.state_dir = xdg_state_home() / self.name
|
self.state_dir = xdg_state_home() / self.name
|
||||||
self.console = Console(highlight=False)
|
self.c = Console(highlight=False)
|
||||||
|
|
||||||
self.user = getpass.getuser()
|
self.user = getpass.getuser()
|
||||||
self.host = socket.gethostname()
|
self.host = socket.gethostname()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue