ominfra 0.0.0.dev7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. ominfra/__about__.py +27 -0
  2. ominfra/__init__.py +0 -0
  3. ominfra/bootstrap/__init__.py +0 -0
  4. ominfra/bootstrap/bootstrap.py +8 -0
  5. ominfra/cmds.py +83 -0
  6. ominfra/deploy/__init__.py +0 -0
  7. ominfra/deploy/_executor.py +1036 -0
  8. ominfra/deploy/configs.py +19 -0
  9. ominfra/deploy/executor/__init__.py +1 -0
  10. ominfra/deploy/executor/base.py +115 -0
  11. ominfra/deploy/executor/concerns/__init__.py +0 -0
  12. ominfra/deploy/executor/concerns/dirs.py +28 -0
  13. ominfra/deploy/executor/concerns/nginx.py +47 -0
  14. ominfra/deploy/executor/concerns/repo.py +17 -0
  15. ominfra/deploy/executor/concerns/supervisor.py +46 -0
  16. ominfra/deploy/executor/concerns/systemd.py +88 -0
  17. ominfra/deploy/executor/concerns/user.py +25 -0
  18. ominfra/deploy/executor/concerns/venv.py +22 -0
  19. ominfra/deploy/executor/main.py +119 -0
  20. ominfra/deploy/poly/__init__.py +1 -0
  21. ominfra/deploy/poly/_main.py +725 -0
  22. ominfra/deploy/poly/base.py +179 -0
  23. ominfra/deploy/poly/configs.py +38 -0
  24. ominfra/deploy/poly/deploy.py +25 -0
  25. ominfra/deploy/poly/main.py +18 -0
  26. ominfra/deploy/poly/nginx.py +60 -0
  27. ominfra/deploy/poly/repo.py +41 -0
  28. ominfra/deploy/poly/runtime.py +39 -0
  29. ominfra/deploy/poly/site.py +11 -0
  30. ominfra/deploy/poly/supervisor.py +64 -0
  31. ominfra/deploy/poly/venv.py +52 -0
  32. ominfra/deploy/remote.py +91 -0
  33. ominfra/pyremote/__init__.py +0 -0
  34. ominfra/pyremote/_runcommands.py +824 -0
  35. ominfra/pyremote/bootstrap.py +149 -0
  36. ominfra/pyremote/runcommands.py +56 -0
  37. ominfra/ssh.py +191 -0
  38. ominfra/tools/__init__.py +0 -0
  39. ominfra/tools/listresources.py +256 -0
  40. ominfra-0.0.0.dev7.dist-info/LICENSE +21 -0
  41. ominfra-0.0.0.dev7.dist-info/METADATA +19 -0
  42. ominfra-0.0.0.dev7.dist-info/RECORD +44 -0
  43. ominfra-0.0.0.dev7.dist-info/WHEEL +5 -0
  44. ominfra-0.0.0.dev7.dist-info/top_level.txt +1 -0
ominfra/__about__.py ADDED
@@ -0,0 +1,27 @@
1
+ from omlish.__about__ import ProjectBase
2
+ from omlish.__about__ import SetuptoolsBase
3
+ from omlish.__about__ import __version__
4
+
5
+
6
+ class Project(ProjectBase):
7
+ name = 'ominfra'
8
+ description = 'ominfra'
9
+
10
+ dependencies = [
11
+ f'omlish == {__version__}',
12
+ ]
13
+
14
+ optional_dependencies = {
15
+ 'ssh': [
16
+ 'paramiko >= 3.4', # !! LGPL
17
+
18
+ "asyncssh >= 2.16; python_version < '3.13'", # cffi
19
+ ],
20
+ }
21
+
22
+
23
+ class Setuptools(SetuptoolsBase):
24
+ find_packages = {
25
+ 'include': ['ominfra', 'ominfra.*'],
26
+ 'exclude': [*SetuptoolsBase.find_packages['exclude']],
27
+ }
ominfra/__init__.py ADDED
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ """
2
+ Jobs:
3
+ - globals
4
+ - pkgs
5
+ - pyenv
6
+ - tailscale
7
+ - docker
8
+ """
ominfra/cmds.py ADDED
@@ -0,0 +1,83 @@
1
+ """
2
+ TODO:
3
+ - timeout
4
+ - stream in/out/err
5
+ - *sessions*
6
+ - anyio
7
+ """
8
+ import abc
9
+ import asyncio
10
+ import io
11
+ import typing as ta
12
+
13
+ from omlish import check
14
+ from omlish import dataclasses as dc
15
+ from omlish import lang
16
+
17
+
18
+ class CommandRunner(lang.Abstract):
19
+ @dc.dataclass(frozen=True)
20
+ class Command:
21
+ args: ta.Sequence[str]
22
+ in_: bytes | None = None
23
+
24
+ @dc.dataclass(frozen=True)
25
+ class Result:
26
+ rc: int
27
+ out: bytes
28
+ err: bytes
29
+
30
+ def check(self) -> ta.Self:
31
+ if self.rc != 0:
32
+ raise CommandRunner.ReturnCodeError(self)
33
+ return self
34
+
35
+ class ReturnCodeError(Exception):
36
+ def __init__(self, result: 'CommandRunner.Result') -> None:
37
+ super().__init__(f'Bad return code: {result.rc}', result)
38
+ self.result = result
39
+
40
+ @abc.abstractmethod
41
+ async def run_command(self, cmd: Command) -> Result:
42
+ raise NotImplementedError
43
+
44
+
45
+ class LocalCommandRunner(CommandRunner):
46
+ @dc.dataclass(frozen=True)
47
+ class Config:
48
+ cwd: str | None = None
49
+
50
+ def __init__(self, cfg: Config = Config()) -> None:
51
+ super().__init__()
52
+ self._cfg = check.isinstance(cfg, LocalCommandRunner.Config)
53
+
54
+ async def run_command(self, cmd: CommandRunner.Command) -> CommandRunner.Result:
55
+ proc = await asyncio.create_subprocess_exec(
56
+ *cmd.args,
57
+ stdin=io.BytesIO(cmd.in_) if cmd.in_ is not None else None,
58
+ stdout=asyncio.subprocess.PIPE,
59
+ stderr=asyncio.subprocess.PIPE,
60
+ **(dict(cwd=self._cfg.cwd) if self._cfg.cwd is not None else {}), # type: ignore
61
+ )
62
+
63
+ out, err = await proc.communicate()
64
+
65
+ return CommandRunner.Result(
66
+ rc=check.not_none(proc.returncode),
67
+ out=out,
68
+ err=err,
69
+ )
70
+
71
+
72
+ async def _a_main() -> None:
73
+ cmd = CommandRunner.Command(
74
+ ['ls', '-al'],
75
+ )
76
+
77
+ rc = await LocalCommandRunner().run_command(cmd)
78
+ check.equal(rc.rc, 0)
79
+ print(rc.out.decode())
80
+
81
+
82
+ if __name__ == '__main__':
83
+ asyncio.run(_a_main())
File without changes