execution modules updated
This commit is contained in:
parent
b0b59ef3ed
commit
846ef2ba53
43
remote.py
43
remote.py
|
@ -15,7 +15,7 @@ username = "volpi"
|
||||||
|
|
||||||
__exec_main = "cd tesi; /home/volpi/.local/bin/poetry run main"
|
__exec_main = "cd tesi; /home/volpi/.local/bin/poetry run main"
|
||||||
__exec_log = "/usr/bin/tail -f -n 0 tesi/quacc.log"
|
__exec_log = "/usr/bin/tail -f -n 0 tesi/quacc.log"
|
||||||
__log_file = "quacc.log"
|
__log_file = "remote.log"
|
||||||
__target_dir = Path("/home/volpi/tesi")
|
__target_dir = Path("/home/volpi/tesi")
|
||||||
__to_sync_up = {
|
__to_sync_up = {
|
||||||
"dir": [
|
"dir": [
|
||||||
|
@ -161,8 +161,9 @@ def _echo_log(ssh: paramiko.SSHClient, q_: queue.Queue):
|
||||||
_, rout, _ = ssh.exec_command(__exec_log, timeout=5.0)
|
_, rout, _ = ssh.exec_command(__exec_log, timeout=5.0)
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
_line = rout.readline()
|
||||||
with open(__log_file, "a") as f:
|
with open(__log_file, "a") as f:
|
||||||
f.write(rout.readline())
|
f.write(_line)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -173,15 +174,23 @@ def _echo_log(ssh: paramiko.SSHClient, q_: queue.Queue):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def remote():
|
def remote(detatch=False):
|
||||||
ssh = paramiko.SSHClient()
|
ssh = paramiko.SSHClient()
|
||||||
ssh.load_host_keys(known_hosts)
|
ssh.load_host_keys(known_hosts)
|
||||||
ssh.connect(hostname=hostname, username=username)
|
ssh.connect(hostname=hostname, username=username)
|
||||||
sync_code(ssh=ssh)
|
sync_code(ssh=ssh)
|
||||||
|
|
||||||
_, rout, rerr = ssh.exec_command(__exec_main)
|
__to_exec = __exec_main
|
||||||
q = queue.Queue()
|
if detatch:
|
||||||
|
__to_exec += " &> out & disown"
|
||||||
|
|
||||||
|
_, rout, rerr = ssh.exec_command(__to_exec)
|
||||||
|
|
||||||
|
if detatch:
|
||||||
|
ssh.close()
|
||||||
|
return
|
||||||
|
|
||||||
|
q = queue.Queue()
|
||||||
_tlog = threading.Thread(target=_echo_log, args=[ssh, q])
|
_tlog = threading.Thread(target=_echo_log, args=[ssh, q])
|
||||||
_tlog.start()
|
_tlog.start()
|
||||||
|
|
||||||
|
@ -196,6 +205,30 @@ def remote():
|
||||||
q.put(None)
|
q.put(None)
|
||||||
|
|
||||||
sync_output(ssh=ssh)
|
sync_output(ssh=ssh)
|
||||||
|
_tlog.join()
|
||||||
|
|
||||||
|
ssh.close()
|
||||||
|
|
||||||
|
|
||||||
|
def log_remote():
|
||||||
|
ssh = paramiko.SSHClient()
|
||||||
|
ssh.load_host_keys(known_hosts)
|
||||||
|
ssh.connect(hostname=hostname, username=username)
|
||||||
|
|
||||||
|
sftp = ssh.open_sftp()
|
||||||
|
sftp.get(str(__target_dir / "quacc.log"), str(Path(__log_file).absolute()))
|
||||||
|
sftp.close()
|
||||||
|
|
||||||
|
q = queue.Queue()
|
||||||
|
_tlog = threading.Thread(target=_echo_log, args=[ssh, q])
|
||||||
|
_tlog.start()
|
||||||
|
|
||||||
|
try:
|
||||||
|
input()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
q.put(None)
|
||||||
|
|
||||||
_tlog.join()
|
_tlog.join()
|
||||||
ssh.close()
|
ssh.close()
|
||||||
|
|
15
run.py
15
run.py
|
@ -1,24 +1,17 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from quacc.main import main as _main
|
from quacc.main import main as run_local
|
||||||
from remote import remote as _remote
|
from remote import remote as run_remote
|
||||||
|
|
||||||
|
|
||||||
def run_local():
|
|
||||||
_main()
|
|
||||||
|
|
||||||
|
|
||||||
def run_remote():
|
|
||||||
_remote()
|
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-l", "--local", action="store_true", dest="local")
|
parser.add_argument("-l", "--local", action="store_true", dest="local")
|
||||||
parser.add_argument("-r", "--remote", action="store_true", dest="remote")
|
parser.add_argument("-r", "--remote", action="store_true", dest="remote")
|
||||||
|
parser.add_argument("-d", "--detatch", action="store_true", dest="detatch")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.local:
|
if args.local:
|
||||||
run_local()
|
run_local()
|
||||||
elif args.remote:
|
elif args.remote:
|
||||||
run_remote()
|
run_remote(detatch=args.detatch)
|
||||||
|
|
Loading…
Reference in New Issue