mirror of
https://github.com/cross-the-world/scp-pipeline.git
synced 2025-09-10 11:39:52 +08:00
strip quotes
This commit is contained in:
2
.github/workflows/deploy.yml
vendored
2
.github/workflows/deploy.yml
vendored
@@ -24,7 +24,7 @@ jobs:
|
|||||||
local: './test/*'
|
local: './test/*'
|
||||||
remote: /home/github/test/
|
remote: /home/github/test/
|
||||||
scp: |
|
scp: |
|
||||||
./test/test*.csv => "/home/github/test/test2/"
|
'./test/test*.csv' => "/home/github/test/test2/"
|
||||||
|
|
||||||
- name: local remote scp
|
- name: local remote scp
|
||||||
uses: cross-the-world/scp-pipeline@master
|
uses: cross-the-world/scp-pipeline@master
|
||||||
|
31
app.py
31
app.py
@@ -34,6 +34,17 @@ def convert_to_seconds(s):
|
|||||||
return 30
|
return 30
|
||||||
|
|
||||||
|
|
||||||
|
strips = ["", "\"", "", "'", ""]
|
||||||
|
|
||||||
|
|
||||||
|
def strip_path(p):
|
||||||
|
if not p:
|
||||||
|
return None
|
||||||
|
for c in strips:
|
||||||
|
p = p.strip(c)
|
||||||
|
return p
|
||||||
|
|
||||||
|
|
||||||
def connect():
|
def connect():
|
||||||
ssh = paramiko.SSHClient()
|
ssh = paramiko.SSHClient()
|
||||||
p_key = paramiko.RSAKey.from_private_key(INPUT_KEY) if INPUT_KEY else None
|
p_key = paramiko.RSAKey.from_private_key(INPUT_KEY) if INPUT_KEY else None
|
||||||
@@ -64,8 +75,8 @@ def scp_process():
|
|||||||
continue
|
continue
|
||||||
l2r = c.split("=>")
|
l2r = c.split("=>")
|
||||||
if len(l2r) == 2:
|
if len(l2r) == 2:
|
||||||
local = l2r[0].strip()
|
local = strip_path(l2r[0])
|
||||||
remote = l2r[1].strip()
|
remote = strip_path(l2r[1])
|
||||||
if local and remote:
|
if local and remote:
|
||||||
copy_list.append({"l": local, "r": remote})
|
copy_list.append({"l": local, "r": remote})
|
||||||
continue
|
continue
|
||||||
@@ -76,14 +87,14 @@ def scp_process():
|
|||||||
print("SCP no copy list found")
|
print("SCP no copy list found")
|
||||||
return
|
return
|
||||||
|
|
||||||
ssh = connect()
|
with connect() as ssh:
|
||||||
with scp.SCPClient(ssh.get_transport(), progress=progress, sanitize=lambda x: x) as conn:
|
with scp.SCPClient(ssh.get_transport(), progress=progress, sanitize=lambda x: x) as conn:
|
||||||
for l2r in copy_list:
|
for l2r in copy_list:
|
||||||
remote = l2r.get('r')
|
remote = l2r.get('r')
|
||||||
ssh.exec_command(f"mkdir -p {remote} || true")
|
ssh.exec_command(f"mkdir -p {remote} || true")
|
||||||
for f in [f for f in glob(l2r.get('l'))]:
|
for f in [f for f in glob(l2r.get('l'))]:
|
||||||
conn.put(f, remote_path=remote, recursive=True)
|
conn.put(f, remote_path=remote, recursive=True)
|
||||||
print(f"{f} -> {remote}")
|
print(f"{f} -> {remote}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Reference in New Issue
Block a user