Compare commits
No commits in common. "master" and "v1.1.1" have entirely different histories.
53
app.py
53
app.py
|
|
@ -6,8 +6,6 @@ import scp
|
|||
import sys
|
||||
import math
|
||||
import re
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
|
||||
envs = environ
|
||||
|
|
@ -44,33 +42,18 @@ def strip_and_parse_envs(p):
|
|||
return None
|
||||
for c in strips:
|
||||
p = p.strip(c)
|
||||
return path.expandvars(p) if p != "." else f"{path.realpath(p)}/*"
|
||||
return path.expandvars(p)
|
||||
|
||||
|
||||
def connect(callback=None):
|
||||
tmp = tempfile.NamedTemporaryFile(delete=False)
|
||||
try:
|
||||
ssh = paramiko.SSHClient()
|
||||
p_key = None
|
||||
if INPUT_KEY:
|
||||
tmp.write(INPUT_KEY.encode())
|
||||
tmp.close()
|
||||
p_key = paramiko.RSAKey.from_private_key_file(filename=tmp.name)
|
||||
with paramiko.SSHClient() as ssh:
|
||||
p_key = paramiko.RSAKey.from_private_key(INPUT_KEY) if INPUT_KEY else None
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect(INPUT_HOST, port=INPUT_PORT, username=INPUT_USER,
|
||||
pkey=p_key, password=INPUT_PASS,
|
||||
timeout=convert_to_seconds(INPUT_CONNECT_TIMEOUT))
|
||||
except Exception as err:
|
||||
print(f"Connect error\n{err}")
|
||||
sys.exit(1)
|
||||
|
||||
else:
|
||||
if callback:
|
||||
callback(ssh)
|
||||
|
||||
finally:
|
||||
os.unlink(tmp.name)
|
||||
tmp.close()
|
||||
|
||||
|
||||
# Define progress callback that prints the current percentage completed for the file
|
||||
|
|
@ -95,9 +78,7 @@ def ssh_process(ssh, input_ssh):
|
|||
print(command_str)
|
||||
|
||||
stdin, stdout, stderr = ssh.exec_command(command_str)
|
||||
|
||||
ssh_exit_status = stdout.channel.recv_exit_status()
|
||||
|
||||
|
||||
out = "".join(stdout.readlines())
|
||||
out = out.strip() if out is not None else None
|
||||
if out:
|
||||
|
|
@ -106,12 +87,11 @@ def ssh_process(ssh, input_ssh):
|
|||
err = "".join(stderr.readlines())
|
||||
err = err.strip() if err is not None else None
|
||||
if err:
|
||||
print(f"Error: \n{err}")
|
||||
|
||||
if ssh_exit_status != 0:
|
||||
print(f"ssh exit status: {ssh_exit_status}")
|
||||
sys.exit(1)
|
||||
|
||||
if out is None:
|
||||
raise Exception(err)
|
||||
else:
|
||||
print(f"Error: \n{err}")
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
|
@ -137,19 +117,10 @@ def scp_process(ssh, input_scp):
|
|||
with scp.SCPClient(ssh.get_transport(), progress=progress, sanitize=lambda x: x) as conn:
|
||||
for l2r in copy_list:
|
||||
remote = l2r.get('r')
|
||||
try:
|
||||
ssh.exec_command(f"mkdir -p {remote}")
|
||||
except Exception as err:
|
||||
print(f"Remote mkdir error. Can't create {remote}\n{err}")
|
||||
sys.exit(1)
|
||||
|
||||
ssh.exec_command(f"mkdir -p {remote} || true")
|
||||
for f in [f for f in glob(l2r.get('l'))]:
|
||||
try:
|
||||
conn.put(f, remote_path=remote, recursive=True)
|
||||
print(f"{f} -> {remote}")
|
||||
except Exception as err:
|
||||
print(f"Scp error. Can't copy {f} on {remote}\n{err}")
|
||||
sys.exit(1)
|
||||
conn.put(f, remote_path=remote, recursive=True)
|
||||
print(f"{f} -> {remote}")
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,5 @@
|
|||
echo "+++++++++++++++++++STARTING PIPELINES+++++++++++++++++++"
|
||||
|
||||
python3 /opt/tools/app.py
|
||||
RET=$?
|
||||
|
||||
echo "+++++++++++++++++++END PIPELINES+++++++++++++++++++"
|
||||
|
||||
exit $RET
|
||||
|
|
|
|||
Loading…
Reference in New Issue