bugfix
This commit is contained in:
parent
277d442acc
commit
0feae81eb8
@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import shlex
|
import shlex
|
||||||
|
from functools import partial
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from appPublic.myTE import tmpTml
|
from appPublic.myTE import tmpTml
|
||||||
import asyncio, asyncssh, sys
|
import asyncio, asyncssh, sys
|
||||||
@ -98,8 +99,11 @@ class SSHNode:
|
|||||||
async def _cmd(self, cmd, input=None, stdin=None, stdout=None):
|
async def _cmd(self, cmd, input=None, stdin=None, stdout=None):
|
||||||
return await self.conn.run(cmd, input=input, stdin=stdin, stdout=stdout)
|
return await self.conn.run(cmd, input=input, stdin=stdin, stdout=stdout)
|
||||||
|
|
||||||
async def _xcmd(self, cmd, xmsgs=[], ns={}):
|
async def _xcmd(self, cmd, xmsgs=[], ns={},
|
||||||
|
show_input=None,
|
||||||
|
show_stdout=None):
|
||||||
proc = await self._process(cmd, term_type='xterm',
|
proc = await self._process(cmd, term_type='xterm',
|
||||||
|
|
||||||
term_size=(80,24),
|
term_size=(80,24),
|
||||||
encoding='utf-8'
|
encoding='utf-8'
|
||||||
)
|
)
|
||||||
@ -111,23 +115,40 @@ class SSHNode:
|
|||||||
break
|
break
|
||||||
s = xmsgs[i][1].format(**ns)
|
s = xmsgs[i][1].format(**ns)
|
||||||
proc.stdin.write(s)
|
proc.stdin.write(s)
|
||||||
|
keyin = False
|
||||||
|
def feed_data(xmsgs, debug_input):
|
||||||
|
if len(xmsgs) == 0:
|
||||||
|
return
|
||||||
|
a = xmsgs[0]
|
||||||
|
xmsgs.reverse()
|
||||||
|
xmsgs.pop()
|
||||||
|
xmsgs.reverse()
|
||||||
|
s = a[1].format(**ns)
|
||||||
|
proc.stdin.write(s)
|
||||||
|
if debug_input:
|
||||||
|
debug_input(f'{s=},{a=}')
|
||||||
|
keyin = True
|
||||||
|
|
||||||
|
already_output = False
|
||||||
|
callee = None
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
while True:
|
while True:
|
||||||
if proc.stdout.at_eof():
|
if proc.stdout.at_eof():
|
||||||
break
|
break
|
||||||
x = await proc.stdout.read(1024)
|
|
||||||
buffer += x
|
|
||||||
if i >= msglen:
|
|
||||||
continue
|
|
||||||
|
|
||||||
k = xmsgs[i][0].format(**ns)
|
if keyin:
|
||||||
kin = buffer.split(k, 1)
|
keyin = False
|
||||||
if len(kin) > 1:
|
|
||||||
s = xmsgs[i][1].format(**ns)
|
|
||||||
proc.stdin.write(s)
|
|
||||||
await proc.stdin.drain()
|
await proc.stdin.drain()
|
||||||
buffer = kin[1]
|
|
||||||
i += 1
|
if len(xmsgs) > 0 and already_output:
|
||||||
|
f = partial(feed_data, xmsgs, show_input)
|
||||||
|
callee = loop.call_later(xmsgs[0][0], f)
|
||||||
|
x = await proc.stdout.read(1024)
|
||||||
|
if callee:
|
||||||
|
callee.cancel()
|
||||||
|
if show_stdout:
|
||||||
|
show_stdout(x)
|
||||||
|
already_output = True
|
||||||
|
|
||||||
async def _run(self, cmd, input=None, stdin=None, stdout=None):
|
async def _run(self, cmd, input=None, stdin=None, stdout=None):
|
||||||
if cmd.startswith('l2r'):
|
if cmd.startswith('l2r'):
|
||||||
|
@ -16,3 +16,4 @@ requests
|
|||||||
jinja2
|
jinja2
|
||||||
pyzmq
|
pyzmq
|
||||||
cryptography
|
cryptography
|
||||||
|
asyncssh
|
||||||
|
Loading…
Reference in New Issue
Block a user