mirror of
https://codeberg.org/privacy1st/subprocess-util
synced 2024-12-22 22:06:05 +01:00
print transfer stats
This commit is contained in:
parent
1f38720072
commit
5bb4fe6208
@ -11,6 +11,8 @@ from p1st.repeat import repeat_until_successful
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
|
||||
args = parse_args()
|
||||
#
|
||||
ssh_source: str = args.ssh_source
|
||||
|
@ -1,12 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
from queue import Queue
|
||||
from typing import Callable, IO, AnyStr
|
||||
|
||||
from p1st.data_units import DataUnitConverter
|
||||
|
||||
|
||||
def execute_consume_chunks(command: list[str],
|
||||
handle_chunks: Callable[[Queue.put], None],
|
||||
@ -56,11 +60,23 @@ def execute_consume_chunks(command: list[str],
|
||||
def _stdin_worker(queue_get: Queue.get,
|
||||
binary_stdin: IO[AnyStr],
|
||||
):
|
||||
start_time = time.time()
|
||||
transferred_bytes = 0
|
||||
|
||||
while True:
|
||||
chunk_path, last_chunk = queue_get()
|
||||
chunk = _read_chunk(chunk_path)
|
||||
binary_stdin.write(chunk)
|
||||
# binary_stdin.flush() # TODO: is this required?
|
||||
|
||||
current_time = time.time()
|
||||
elapsed_time = current_time - start_time
|
||||
transferred_bytes += len(chunk)
|
||||
bytes_per_second = round(transferred_bytes / elapsed_time)
|
||||
print(f'Elapsed time: {datetime.timedelta(seconds=elapsed_time)}\n'
|
||||
f'Transferred: {DataUnitConverter.to_unit_auto_str(transferred_bytes)}\n'
|
||||
f'Speed: {DataUnitConverter.to_unit_auto_str(bytes_per_second)}/s')
|
||||
|
||||
if last_chunk:
|
||||
break
|
||||
|
||||
|
@ -21,7 +21,8 @@ def test():
|
||||
# test10()
|
||||
# test11()
|
||||
# test12()
|
||||
test13()
|
||||
# test13()
|
||||
test14()
|
||||
|
||||
|
||||
def test1():
|
||||
@ -182,6 +183,17 @@ def test13():
|
||||
print(f'odroid: sudo btrfs-receive-chunks-active {ssh_source} {source_chunk_dir} {target_path}')
|
||||
|
||||
|
||||
def test14():
|
||||
ssh_source = 'rootnas'
|
||||
source_path = '/mnt/data/snap/cloud.privacy1st.de/20221015T1432_u'
|
||||
source_chunk_dir = '/mnt/data/btrfs-transfer-chunks'
|
||||
|
||||
target_path = '/mnt/backup/snap/cloud.privacy1st.de/20221015T1432_u'
|
||||
|
||||
print(f'nas: sudo btrfs-send-chunks-passive --chunk-dir={source_chunk_dir} {source_path}')
|
||||
print(f'odroid: sudo btrfs-receive-chunks-active {ssh_source} {source_chunk_dir} {target_path}')
|
||||
|
||||
|
||||
def _init(test_number: int):
|
||||
print(f"TEST {test_number}")
|
||||
test_dir = Path('test')
|
||||
|
Loading…
Reference in New Issue
Block a user