strip quotes

This commit is contained in:
Nguyen Huu Thuong
2020-06-13 09:10:12 +02:00
parent 013057800c
commit 6bf8174723
2 changed files with 22 additions and 11 deletions

View File

@@ -24,7 +24,7 @@ jobs:
local: './test/*'
remote: /home/github/test/
scp: |
./test/test*.csv => "/home/github/test/test2/"
'./test/test*.csv' => "/home/github/test/test2/"
- name: local remote scp
uses: cross-the-world/scp-pipeline@master

31
app.py
View File

@@ -34,6 +34,17 @@ def convert_to_seconds(s):
return 30
strips = ["", "\"", "", "'", ""]
def strip_path(p):
if not p:
return None
for c in strips:
p = p.strip(c)
return p
def connect():
ssh = paramiko.SSHClient()
p_key = paramiko.RSAKey.from_private_key(INPUT_KEY) if INPUT_KEY else None
@@ -64,8 +75,8 @@ def scp_process():
continue
l2r = c.split("=>")
if len(l2r) == 2:
local = l2r[0].strip()
remote = l2r[1].strip()
local = strip_path(l2r[0])
remote = strip_path(l2r[1])
if local and remote:
copy_list.append({"l": local, "r": remote})
continue
@@ -76,14 +87,14 @@ def scp_process():
print("SCP no copy list found")
return
ssh = connect()
with scp.SCPClient(ssh.get_transport(), progress=progress, sanitize=lambda x: x) as conn:
for l2r in copy_list:
remote = l2r.get('r')
ssh.exec_command(f"mkdir -p {remote} || true")
for f in [f for f in glob(l2r.get('l'))]:
conn.put(f, remote_path=remote, recursive=True)
print(f"{f} -> {remote}")
with connect() as ssh:
with scp.SCPClient(ssh.get_transport(), progress=progress, sanitize=lambda x: x) as conn:
for l2r in copy_list:
remote = l2r.get('r')
ssh.exec_command(f"mkdir -p {remote} || true")
for f in [f for f in glob(l2r.get('l'))]:
conn.put(f, remote_path=remote, recursive=True)
print(f"{f} -> {remote}")
if __name__ == '__main__':