Skip to content
Snippets Groups Projects
Commit 153e18de authored by Gary Ruben's avatar Gary Ruben
Browse files

Replaced os.system with subprocess.run and added node.processed flag

parent 26f112fa
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import os ...@@ -10,6 +10,7 @@ import os
import warnings import warnings
from dataclasses import dataclass from dataclasses import dataclass
import pathlib import pathlib
import subprocess
# This isn't suppressing the warnings that fabric is generating; we need to # This isn't suppressing the warnings that fabric is generating; we need to
# investigate further # investigate further
...@@ -26,6 +27,7 @@ KERNEL_CHECKSUM=$(cpio --to-stdout -i kernel.fat16 < archive.cpio | sha256sum | ...@@ -26,6 +27,7 @@ KERNEL_CHECKSUM=$(cpio --to-stdout -i kernel.fat16 < archive.cpio | sha256sum |
""" """
REMOTE_LOGIN = "gary.ruben@monash.edu@sftp.synchrotron.org.au" REMOTE_LOGIN = "gary.ruben@monash.edu@sftp.synchrotron.org.au"
# SRC_PATH = "/data/13660a/asci/input"
SRC_PATH = "/data/13660a/asci/output/tar_test" SRC_PATH = "/data/13660a/asci/output/tar_test"
DEST_PATH = "/home/grub0002/bapcxi/vault/rubbish" DEST_PATH = "/home/grub0002/bapcxi/vault/rubbish"
...@@ -34,6 +36,7 @@ DEST_PATH = "/home/grub0002/bapcxi/vault/rubbish" ...@@ -34,6 +36,7 @@ DEST_PATH = "/home/grub0002/bapcxi/vault/rubbish"
class Node: class Node:
src: str src: str
dest: str dest: str
processed: bool = False
def tar_and_send_directory(node): def tar_and_send_directory(node):
...@@ -57,16 +60,21 @@ def tar_and_send_directory(node): ...@@ -57,16 +60,21 @@ def tar_and_send_directory(node):
files = files.stdout.strip() files = files.stdout.strip()
count = files.count('/') count = files.count('/')
print(f'Node:{node.src}, file count:{count}')
if count == 0: if count == 0:
# No files at this node, just return # No files at this node, just return
return pass
elif count == 1: elif count == 1:
# Only one file. No need to tar. Just copy unchanged. # Only one file. No need to tar. Just copy unchanged.
os.system( output = subprocess.run(
f"ssh {REMOTE_LOGIN} 'cd {node.src};" f"ssh {REMOTE_LOGIN} 'cd {node.src};"
f"find -type f -maxdepth 1 | cpio -o' |" f"find -type f -maxdepth 1 | cpio -o' |"
f"cat > {node.dest}/{files}" f"cat > {node.dest}/{files}",
shell=True,
check=True
) )
print('stdout:', output.stdout)
print('stderr:', output.stderr)
os.chmod(f'{node.dest}/{files}', 0o550) os.chmod(f'{node.dest}/{files}', 0o550)
print(f'transfer {node.src} -> {node.dest}') print(f'transfer {node.src} -> {node.dest}')
else: else:
...@@ -76,14 +84,19 @@ def tar_and_send_directory(node): ...@@ -76,14 +84,19 @@ def tar_and_send_directory(node):
else: else:
filename = node.src.replace(SRC_PATH+'/', '').replace('/', '_') filename = node.src.replace(SRC_PATH+'/', '').replace('/', '_')
os.system( output = subprocess.run(
f"ssh {REMOTE_LOGIN} 'cd {node.src};" f"ssh {REMOTE_LOGIN} 'cd {node.src};"
f"find -type f -maxdepth 1 -print0 | cpio -o -H ustar -0' |" f"find -type f -maxdepth 1 -print0 | cpio -o -H ustar -0' |"
f"cat > {node.dest}/{filename}.tar" f"cat > {node.dest}/{filename}.tar",
shell=True,
check=True
) )
print('stdout:', output.stdout)
print('stderr:', output.stderr)
os.chmod(f'{node.dest}/{filename}.tar', 0o550) os.chmod(f'{node.dest}/{filename}.tar', 0o550)
print(f'transfer {node.src} -> {node.dest}') print(f'transfer {node.src} -> {node.dest}')
node.processed = True
if __name__ == "__main__": if __name__ == "__main__":
# Get the directory tree from remote server as a list # Get the directory tree from remote server as a list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment