ominfra 0.0.0.dev133__py3-none-any.whl → 0.0.0.dev134__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- ominfra/pyremote.py +44 -12
- {ominfra-0.0.0.dev133.dist-info → ominfra-0.0.0.dev134.dist-info}/METADATA +3 -3
- {ominfra-0.0.0.dev133.dist-info → ominfra-0.0.0.dev134.dist-info}/RECORD +7 -7
- {ominfra-0.0.0.dev133.dist-info → ominfra-0.0.0.dev134.dist-info}/LICENSE +0 -0
- {ominfra-0.0.0.dev133.dist-info → ominfra-0.0.0.dev134.dist-info}/WHEEL +0 -0
- {ominfra-0.0.0.dev133.dist-info → ominfra-0.0.0.dev134.dist-info}/entry_points.txt +0 -0
- {ominfra-0.0.0.dev133.dist-info → ominfra-0.0.0.dev134.dist-info}/top_level.txt +0 -0
ominfra/pyremote.py
CHANGED
@@ -17,9 +17,6 @@ import textwrap
|
|
17
17
|
import typing as ta
|
18
18
|
import zlib
|
19
19
|
|
20
|
-
from omlish.lite.check import check_isinstance
|
21
|
-
from omlish.lite.check import check_none
|
22
|
-
|
23
20
|
|
24
21
|
##
|
25
22
|
|
@@ -32,8 +29,8 @@ _PYREMOTE_BOOTSTRAP_ARGV0_VAR = '_OPYR_ARGV0'
|
|
32
29
|
|
33
30
|
_PYREMOTE_BOOTSTRAP_ACK0 = b'OPYR000\n'
|
34
31
|
_PYREMOTE_BOOTSTRAP_ACK1 = b'OPYR001\n'
|
35
|
-
_PYREMOTE_BOOTSTRAP_ACK2 = b'
|
36
|
-
_PYREMOTE_BOOTSTRAP_ACK3 = b'
|
32
|
+
_PYREMOTE_BOOTSTRAP_ACK2 = b'OPYR002\n'
|
33
|
+
_PYREMOTE_BOOTSTRAP_ACK3 = b'OPYR003\n'
|
37
34
|
|
38
35
|
_PYREMOTE_BOOTSTRAP_PROC_TITLE_FMT = '(pyremote:%s)'
|
39
36
|
|
@@ -256,6 +253,8 @@ class PyremoteBootstrapDriver:
|
|
256
253
|
self._main_src = main_src
|
257
254
|
self._main_z = zlib.compress(main_src.encode('utf-8'))
|
258
255
|
|
256
|
+
#
|
257
|
+
|
259
258
|
@dc.dataclass(frozen=True)
|
260
259
|
class Read:
|
261
260
|
sz: int
|
@@ -272,7 +271,7 @@ class PyremoteBootstrapDriver:
|
|
272
271
|
pid: int
|
273
272
|
env_info: PyremoteEnvInfo
|
274
273
|
|
275
|
-
def
|
274
|
+
def gen(self) -> ta.Generator[ta.Union[Read, Write], ta.Optional[bytes], Result]:
|
276
275
|
# Read first ack
|
277
276
|
yield from self._expect(_PYREMOTE_BOOTSTRAP_ACK0)
|
278
277
|
|
@@ -281,8 +280,8 @@ class PyremoteBootstrapDriver:
|
|
281
280
|
pid = struct.unpack('<Q', d)[0]
|
282
281
|
|
283
282
|
# Write main src
|
284
|
-
|
285
|
-
|
283
|
+
yield from self._write(struct.pack('<I', len(self._main_z)))
|
284
|
+
yield from self._write(self._main_z)
|
286
285
|
|
287
286
|
# Read second and third ack
|
288
287
|
yield from self._expect(_PYREMOTE_BOOTSTRAP_ACK1)
|
@@ -305,7 +304,9 @@ class PyremoteBootstrapDriver:
|
|
305
304
|
)
|
306
305
|
|
307
306
|
def _read(self, sz: int) -> ta.Generator[Read, bytes, bytes]:
|
308
|
-
d =
|
307
|
+
d = yield self.Read(sz)
|
308
|
+
if not isinstance(d, bytes):
|
309
|
+
raise self.ProtocolError(f'Expected bytes after read, got {d!r}')
|
309
310
|
if len(d) != sz:
|
310
311
|
raise self.ProtocolError(f'Read {len(d)} bytes, expected {sz}')
|
311
312
|
return d
|
@@ -315,17 +316,47 @@ class PyremoteBootstrapDriver:
|
|
315
316
|
if d != e:
|
316
317
|
raise self.ProtocolError(f'Read {d!r}, expected {e!r}')
|
317
318
|
|
319
|
+
def _write(self, d: bytes) -> ta.Generator[Write, ta.Optional[bytes], None]:
|
320
|
+
i = yield self.Write(d)
|
321
|
+
if i is not None:
|
322
|
+
raise self.ProtocolError('Unexpected input after write')
|
323
|
+
|
324
|
+
#
|
325
|
+
|
326
|
+
def run(self, stdin: ta.IO, stdout: ta.IO) -> Result:
|
327
|
+
gen = self.gen()
|
328
|
+
|
329
|
+
gi: bytes | None = None
|
330
|
+
while True:
|
331
|
+
try:
|
332
|
+
if gi is not None:
|
333
|
+
go = gen.send(gi)
|
334
|
+
else:
|
335
|
+
go = next(gen)
|
336
|
+
except StopIteration as e:
|
337
|
+
return e.value
|
338
|
+
|
339
|
+
if isinstance(go, self.Read):
|
340
|
+
gi = stdout.read(go.sz)
|
341
|
+
elif isinstance(go, self.Write):
|
342
|
+
gi = None
|
343
|
+
stdin.write(go.d)
|
344
|
+
stdin.flush()
|
345
|
+
else:
|
346
|
+
raise TypeError(go)
|
347
|
+
|
318
348
|
|
319
349
|
##
|
320
350
|
|
321
351
|
|
322
352
|
@dc.dataclass(frozen=True)
|
323
|
-
class
|
353
|
+
class PyremotePayloadRuntime:
|
324
354
|
input: ta.BinaryIO
|
325
355
|
main_src: str
|
356
|
+
env_info: PyremoteEnvInfo
|
326
357
|
|
327
358
|
|
328
|
-
def pyremote_bootstrap_finalize() ->
|
359
|
+
def pyremote_bootstrap_finalize() -> PyremotePayloadRuntime:
|
329
360
|
# Restore original argv0
|
330
361
|
sys.executable = os.environ.pop(_PYREMOTE_BOOTSTRAP_ARGV0_VAR)
|
331
362
|
|
@@ -351,7 +382,8 @@ def pyremote_bootstrap_finalize() -> PyremoteBootstrapPayloadRuntime:
|
|
351
382
|
os.write(1, _PYREMOTE_BOOTSTRAP_ACK3)
|
352
383
|
|
353
384
|
# Return
|
354
|
-
return
|
385
|
+
return PyremotePayloadRuntime(
|
355
386
|
input=os.fdopen(_PYREMOTE_BOOTSTRAP_COMM_FD, 'rb', 0),
|
356
387
|
main_src=main_src,
|
388
|
+
env_info=env_info,
|
357
389
|
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: ominfra
|
3
|
-
Version: 0.0.0.
|
3
|
+
Version: 0.0.0.dev134
|
4
4
|
Summary: ominfra
|
5
5
|
Author: wrmsr
|
6
6
|
License: BSD-3-Clause
|
@@ -12,8 +12,8 @@ Classifier: Operating System :: OS Independent
|
|
12
12
|
Classifier: Operating System :: POSIX
|
13
13
|
Requires-Python: >=3.12
|
14
14
|
License-File: LICENSE
|
15
|
-
Requires-Dist: omdev==0.0.0.
|
16
|
-
Requires-Dist: omlish==0.0.0.
|
15
|
+
Requires-Dist: omdev==0.0.0.dev134
|
16
|
+
Requires-Dist: omlish==0.0.0.dev134
|
17
17
|
Provides-Extra: all
|
18
18
|
Requires-Dist: paramiko~=3.5; extra == "all"
|
19
19
|
Requires-Dist: asyncssh~=2.18; extra == "all"
|
@@ -3,7 +3,7 @@ ominfra/__about__.py,sha256=6i1AoruFYQCd-PyhhbDQDWY2d1tiQu9nkwWr-fXAqfY,705
|
|
3
3
|
ominfra/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
ominfra/cmds.py,sha256=E0AfnvEmnKntXWvmLW5L05_NeDpBET1VBXn7vV6EwBQ,2083
|
5
5
|
ominfra/configs.py,sha256=8aU1Qmbr-qjaE2iP3gAbA2SWJYMPZ-uGK007L01PoOI,1727
|
6
|
-
ominfra/pyremote.py,sha256=
|
6
|
+
ominfra/pyremote.py,sha256=nqzmMKZvUMiw2y65v8VVjx832sKfSB7jBOkP8SQBmGI,10121
|
7
7
|
ominfra/ssh.py,sha256=jQpc4WvkMckIfk4vILda8zFaeharRqc_6wxW50b0OjQ,5431
|
8
8
|
ominfra/threadworkers.py,sha256=oX4ubZn7h932saXpRIJu2MNhBExgGGMuGhdXarZxLJw,4948
|
9
9
|
ominfra/clouds/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -100,9 +100,9 @@ ominfra/tailscale/api.py,sha256=C5-t_b6jZXUWcy5k8bXm7CFnk73pSdrlMOgGDeGVrpw,1370
|
|
100
100
|
ominfra/tailscale/cli.py,sha256=DSGp4hn5xwOW-l_u_InKlSF6kIobxtUtVssf_73STs0,3567
|
101
101
|
ominfra/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
102
102
|
ominfra/tools/listresources.py,sha256=4qVg5txsb10EHhvqXXeM6gJ2jx9LbroEnPydDv1uXs0,6176
|
103
|
-
ominfra-0.0.0.
|
104
|
-
ominfra-0.0.0.
|
105
|
-
ominfra-0.0.0.
|
106
|
-
ominfra-0.0.0.
|
107
|
-
ominfra-0.0.0.
|
108
|
-
ominfra-0.0.0.
|
103
|
+
ominfra-0.0.0.dev134.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
104
|
+
ominfra-0.0.0.dev134.dist-info/METADATA,sha256=pJ8EYFED29tv1T8wzhlFFm2rKeNXXS2c4Iw8hjFEvSA,731
|
105
|
+
ominfra-0.0.0.dev134.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
106
|
+
ominfra-0.0.0.dev134.dist-info/entry_points.txt,sha256=kgecQ2MgGrM9qK744BoKS3tMesaC3yjLnl9pa5CRczg,37
|
107
|
+
ominfra-0.0.0.dev134.dist-info/top_level.txt,sha256=E-b2OHkk_AOBLXHYZQ2EOFKl-_6uOGd8EjeG-Zy6h_w,8
|
108
|
+
ominfra-0.0.0.dev134.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|