Skip to content

Commit 3694090

Browse files
committed
250609.2
1 parent a61df4c commit 3694090

File tree

6 files changed

+76
-16
lines changed

6 files changed

+76
-16
lines changed
-36.1 KB
Binary file not shown.
36.1 KB
Binary file not shown.
2.64 MB
Binary file not shown.

easycoder/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
from .ec_timestamp import *
1010
from .ec_value import *
1111

12-
__version__ = "250609.1"
12+
__version__ = "250609.2"

easycoder/ec_core.py

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import json, math, hashlib, threading, os, subprocess, sys, time, numbers, base64, binascii, random, requests
1+
import json, math, hashlib, threading, os, subprocess, sys, time
2+
import numbers, base64, binascii, random, requests, paramiko
23
from psutil import Process
34
from datetime import datetime
45
from random import randrange
@@ -712,7 +713,7 @@ def r_input(self, command):
712713
return self.nextPC()
713714

714715
# 1 Load a plugin. This is done at compile time.
715-
# 2 Load text from a file
716+
# 2 Load text from a file or ssh
716717
def k_load(self, command):
717718
self.nextToken()
718719
if self.tokenIs('plugin'):
@@ -726,7 +727,15 @@ def k_load(self, command):
726727
if symbolRecord['hasValue']:
727728
command['target'] = symbolRecord['name']
728729
if self.nextIs('from'):
729-
command['file'] = self.nextValue()
730+
if self.nextIsSymbol():
731+
record = self.getSymbolRecord()
732+
if record['keyword'] == 'ssh':
733+
command['ssh'] = record['name']
734+
command['path'] = self.nextValue()
735+
self.add(command)
736+
return True
737+
738+
command['file'] = self.getValue()
730739
self.add(command)
731740
return True
732741
else:
@@ -735,15 +744,24 @@ def k_load(self, command):
735744

736745
def r_load(self, command):
737746
target = self.getVariable(command['target'])
738-
filename = self.getRuntimeValue(command['file'])
739-
try:
740-
with open(filename) as f: content = f.read()
741-
except:
742-
content = ''
743-
try:
744-
if filename.endswith('.json'): content = json.loads(content)
745-
except:
746-
RuntimeError(self.program, 'Bad or null JSON string')
747+
if 'ssh' in command:
748+
ssh = self.getVariable(command['ssh'])
749+
path = self.getRuntimeValue(command['path'])
750+
sftp = ssh['sftp']
751+
try:
752+
with sftp.open(path, 'r') as remote_file: content = remote_file.read().decode()
753+
except:
754+
RuntimeError(self.program, 'Unable to read data')
755+
else:
756+
filename = self.getRuntimeValue(command['file'])
757+
try:
758+
with open(filename) as f: content = f.read()
759+
except:
760+
content = ''
761+
try:
762+
if filename.endswith('.json'): content = json.loads(content)
763+
except:
764+
RuntimeError(self.program, 'Bad or null JSON string')
747765
value = {}
748766
value['type'] = 'text'
749767
value['content'] = content
@@ -1277,16 +1295,40 @@ def r_send(self, command):
12771295

12781296
# Set a value
12791297
# set {variable}
1298+
# set {ssh} host {host} user {user} password {password}
12801299
# set the elements of {variable} to {value}
12811300
# set element/property of {variable} to {value}
12821301
def k_set(self, command):
12831302
if self.nextIsSymbol():
1284-
target = self.getSymbolRecord()
1285-
if target['hasValue']:
1303+
record = self.getSymbolRecord()
1304+
command['target'] = record['name']
1305+
if record['hasValue']:
12861306
command['type'] = 'set'
1287-
command['target'] = target['name']
12881307
self.add(command)
12891308
return True
1309+
elif record['keyword'] == 'ssh':
1310+
host = None
1311+
user = None
1312+
password = None
1313+
while True:
1314+
token = self.peek()
1315+
if token == 'host':
1316+
self.nextToken()
1317+
host = self.nextValue()
1318+
elif token == 'user':
1319+
self.nextToken()
1320+
user = self.nextValue()
1321+
elif token == 'password':
1322+
self.nextToken()
1323+
password = self.nextValue()
1324+
else: break
1325+
command['host'] = host
1326+
command['user'] = user
1327+
command['password'] = password
1328+
command['type'] = 'ssh'
1329+
self.add(command)
1330+
return True
1331+
12901332
return False
12911333

12921334
token = self.getToken()
@@ -1415,6 +1457,17 @@ def r_set(self, command):
14151457
val['content'] = content
14161458
self.putSymbolValue(targetVariable, val)
14171459
return self.nextPC()
1460+
1461+
elif cmdType == 'ssh':
1462+
target = self.getVariable(command['target'])
1463+
host = self.getRuntimeValue(command['host'])
1464+
user = self.getRuntimeValue(command['user'])
1465+
password = self.getRuntimeValue(command['password'])
1466+
ssh = paramiko.SSHClient()
1467+
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
1468+
ssh.connect(host, username=user, password=password)
1469+
target['sftp'] = ssh.open_sftp()
1470+
return self.nextPC()
14181471

14191472
# Shuffle a list
14201473
def k_shuffle(self, command):
@@ -1485,6 +1538,12 @@ def r_split(self, command):
14851538

14861539
return self.nextPC()
14871540

1541+
def k_ssh(self, command):
1542+
return self.compileVariable(command, False)
1543+
1544+
def r_ssh(self, command):
1545+
return self.nextPC()
1546+
14881547
# Declare a stack variable
14891548
def k_stack(self, command):
14901549
return self.compileVariable(command)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dynamic = ["version"]
1414
dependencies = [
1515
"pytz",
1616
"requests",
17+
"paramiko",
1718
"pyside6"
1819
]
1920

0 commit comments

Comments
 (0)