prepare for nodes parallel
This commit is contained in:
parent
3b7bee233e
commit
59b38bb58a
@ -87,14 +87,20 @@ class configfile:
|
||||
return False
|
||||
return result
|
||||
|
||||
def getitem(self, unique):
|
||||
def getitem(self, unique, keys = None):
|
||||
uniques = self._explode_unique(unique)
|
||||
if unique.startswith("@"):
|
||||
if uniques.keys() >= {"folder", "subfolder"}:
|
||||
folder = self.connections[uniques["folder"]][uniques["subfolder"]]
|
||||
else:
|
||||
folder = self.connections[uniques["folder"]]
|
||||
return folder
|
||||
newfolder = folder.copy()
|
||||
newfolder.pop("type")
|
||||
if keys == None:
|
||||
return newfolder
|
||||
else:
|
||||
f_newfolder = dict((k, newfolder[k]) for k in keys)
|
||||
return f_newfolder
|
||||
else:
|
||||
if uniques.keys() >= {"folder", "subfolder"}:
|
||||
node = self.connections[uniques["folder"]][uniques["subfolder"]][uniques["id"]]
|
||||
@ -102,7 +108,8 @@ class configfile:
|
||||
node = self.connections[uniques["folder"]][uniques["id"]]
|
||||
else:
|
||||
node = self.connections[uniques["id"]]
|
||||
return node
|
||||
newnode = node.copy()
|
||||
return newnode
|
||||
|
||||
def _connections_add(self,*, id, host, folder='', subfolder='', options='', logs='', password='', port='', protocol='', user='', type = "connection" ):
|
||||
if folder == '':
|
||||
|
@ -88,6 +88,10 @@ class connapp:
|
||||
if args.action == "connect" or args.action == "debug":
|
||||
if args.data == None:
|
||||
matches = self.nodes
|
||||
if len(matches) == 0:
|
||||
print("There are no nodes created")
|
||||
print("try: conn --help")
|
||||
exit(9)
|
||||
else:
|
||||
if args.data.startswith("@"):
|
||||
matches = list(filter(lambda k: args.data in k, self.nodes))
|
||||
|
63
conn/core.py
63
conn/core.py
@ -104,6 +104,8 @@ class node:
|
||||
def interact(self, debug = False):
|
||||
connect = self._connect(debug = debug)
|
||||
if connect == True:
|
||||
size = re.search('columns=([0-9]+).*lines=([0-9]+)',str(os.get_terminal_size()))
|
||||
self.child.setwinsize(int(size.group(2)),int(size.group(1)))
|
||||
print("Connected to " + self.unique + " at " + self.host + (":" if self.port != '' else '') + self.port + " via: " + self.protocol)
|
||||
if 'logfile' in dir(self):
|
||||
self.child.logfile_read = open(self.logfile, "wb")
|
||||
@ -121,21 +123,33 @@ class node:
|
||||
def run(self, commands,*, folder = '', prompt = '>$|#$|\$$|>.$|#.$|\$.$', stdout = False):
|
||||
connect = self._connect()
|
||||
if connect == True:
|
||||
winsize = self.child.getwinsize()
|
||||
self.child.setwinsize(65535,winsize[1])
|
||||
expects = [prompt, pexpect.EOF]
|
||||
output = ''
|
||||
if isinstance(commands, list):
|
||||
for c in commands:
|
||||
self.child.expect(prompt)
|
||||
result = self.child.expect(expects)
|
||||
self.child.sendline(c)
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
match result:
|
||||
case 0:
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
case 1:
|
||||
output = output + self.child.before.decode()
|
||||
else:
|
||||
self.child.expect(prompt)
|
||||
result = self.child.expect(expects)
|
||||
self.child.sendline(commands)
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
self.child.expect(prompt)
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
match result:
|
||||
case 0:
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
case 1:
|
||||
output = output + self.child.before.decode()
|
||||
result = self.child.expect(expects)
|
||||
match result:
|
||||
case 0:
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
case 1:
|
||||
output = output + self.child.before.decode()
|
||||
self.child.close()
|
||||
output = output.lstrip()
|
||||
if stdout == True:
|
||||
print(output)
|
||||
if folder != '':
|
||||
@ -146,35 +160,50 @@ class node:
|
||||
self.output = output
|
||||
return output
|
||||
else:
|
||||
self.output = connect
|
||||
return connect
|
||||
|
||||
def test(self, commands, expected, *, prompt = '>$|#$|\$$|>.$|#.$|\$.$'):
|
||||
connect = self._connect()
|
||||
if connect == True:
|
||||
winsize = self.child.getwinsize()
|
||||
self.child.setwinsize(65535,winsize[1])
|
||||
expects = [prompt, pexpect.EOF]
|
||||
output = ''
|
||||
if isinstance(commands, list):
|
||||
for c in commands:
|
||||
self.child.expect(prompt)
|
||||
result = self.child.expect(expects)
|
||||
self.child.sendline(c)
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
match result:
|
||||
case 0:
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
case 1:
|
||||
output = output + self.child.before.decode()
|
||||
else:
|
||||
self.child.expect(prompt)
|
||||
self.child.expect(expects)
|
||||
self.child.sendline(commands)
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
expects = [expected, prompt]
|
||||
expects = [expected, prompt, pexpect.EOF]
|
||||
results = self.child.expect(expects)
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
self.output = output
|
||||
match results:
|
||||
case 0:
|
||||
self.child.close()
|
||||
self.test = True
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
output = output.lstrip()
|
||||
self.output = output
|
||||
return True
|
||||
case 1:
|
||||
case 1 | 2:
|
||||
self.child.close()
|
||||
self.test = False
|
||||
if results == 1:
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
elif results == 2:
|
||||
output = output + self.child.before.decode()
|
||||
output = output.lstrip()
|
||||
self.output = output
|
||||
return False
|
||||
else:
|
||||
self.test = None
|
||||
self.output = connect
|
||||
return connect
|
||||
|
||||
def _connect(self, debug = False):
|
||||
|
Loading…
Reference in New Issue
Block a user