From ef3fe0fc96549e2fc6ff3ae294538d47743cad96 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Sun, 19 Mar 2023 18:10:28 +0100 Subject: [PATCH] refactor --- .../btrfs_receive_chunks_active.py | 2 +- .../btrfs_send_chunks_passive.py | 4 +- .../btrfs_receive_chunks_passive.py | 12 +++--- .../active_send/btrfs_send_chunks_active.py | 41 +++++++++++-------- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/subprocess_util/chunked_transfer/active_receive/btrfs_receive_chunks_active.py b/src/subprocess_util/chunked_transfer/active_receive/btrfs_receive_chunks_active.py index 2fa2935..a06ca8f 100644 --- a/src/subprocess_util/chunked_transfer/active_receive/btrfs_receive_chunks_active.py +++ b/src/subprocess_util/chunked_transfer/active_receive/btrfs_receive_chunks_active.py @@ -38,7 +38,7 @@ def parse_args(): ) parser.add_argument('ssh_source', - help='Hostname of sending side; as configured in ~/.ssh/config.', + help='Hostname of sending side as configured in ~/.ssh/config.', metavar='SSH_SOURCE' ) diff --git a/src/subprocess_util/chunked_transfer/active_receive/btrfs_send_chunks_passive.py b/src/subprocess_util/chunked_transfer/active_receive/btrfs_send_chunks_passive.py index 9cd03f9..d5d487a 100644 --- a/src/subprocess_util/chunked_transfer/active_receive/btrfs_send_chunks_passive.py +++ b/src/subprocess_util/chunked_transfer/active_receive/btrfs_send_chunks_passive.py @@ -34,7 +34,7 @@ def parse_args(): parser = argparse.ArgumentParser(prog='btrfs-send-chunks-passive') parser.add_argument('-p', - help='Path to parent subvolume; forwarded to btrfs-send.', + help='Path to parent subvolume.', dest='parent', default=None, type=Path, @@ -49,7 +49,7 @@ def parse_args(): ) parser.add_argument('--chunk-size', - help='Size in bytes; defaults to 128 MB.', + help='Size in bytes. Defaults to 128 MB.', dest='chunk_size', type=int, default=128 * 1024 * 1024, diff --git a/src/subprocess_util/chunked_transfer/active_send/btrfs_receive_chunks_passive.py b/src/subprocess_util/chunked_transfer/active_send/btrfs_receive_chunks_passive.py index fd2a1ca..09c7812 100644 --- a/src/subprocess_util/chunked_transfer/active_send/btrfs_receive_chunks_passive.py +++ b/src/subprocess_util/chunked_transfer/active_send/btrfs_receive_chunks_passive.py @@ -26,7 +26,7 @@ def parse_args(): parser.add_argument('--chunk-dir', help='Chunks are saved in this directory. ' - 'Defaults to folder `.chunk` next to SUBVOLUME.', + 'Defaults to directory `.chunk` next to TARGET_SUBVOLUME.', dest='chunk_dir', type=Path, metavar='CHUNK_DIR', @@ -36,18 +36,18 @@ def parse_args(): parser.add_argument('target_path', help='Path where the subvolume will be created. ' 'The last component of the path ' - 'must be equal to the name of the subvolume on the sending side.', + 'must be equal to the name of CHILD_SUBVOLUME on the sending side.', type=Path, - metavar='SUBVOLUME' + metavar='TARGET_SUBVOLUME' ) args = parser.parse_args() - # Make all paths absolute. Set default values. + # target_path args.target_path = args.target_path.absolute() - # + + # chunk_dir if args.chunk_dir is None: - # Default value args.chunk_dir = args.target_path.parent.joinpath(f'{args.target_path.name}.chunk') else: args.chunk_dir = args.chunk_dir.absolute() diff --git a/src/subprocess_util/chunked_transfer/active_send/btrfs_send_chunks_active.py b/src/subprocess_util/chunked_transfer/active_send/btrfs_send_chunks_active.py index 1763400..b343e8f 100644 --- a/src/subprocess_util/chunked_transfer/active_send/btrfs_send_chunks_active.py +++ b/src/subprocess_util/chunked_transfer/active_send/btrfs_send_chunks_active.py @@ -39,7 +39,9 @@ def parse_args(): parser = argparse.ArgumentParser(prog='btrfs-send-chunks-active') parser.add_argument('-p', - help='Path to parent subvolume; forwarded to btrfs-send.', + help='Path to parent subvolume of CHILD_SUBVOLUME. ' + 'If given, ' + 'only the difference between PARENT_SUBVOLUME and CHILD_SUBVOLUME is transferred.', dest='parent', default=None, type=Path, @@ -47,14 +49,14 @@ def parse_args(): ) parser.add_argument('--compressed-data', - help='Forwarded to btrfs-send.', + help='Reduce network bandwidth by compressing data.', dest='compressed_data', action='store_true', default=False, ) parser.add_argument('--chunk-size', - help='Size in bytes; defaults to 128 MB.', + help='Size in bytes. Defaults to 128 MB.', dest='chunk_size', type=int, default=128 * 1024 * 1024, @@ -62,7 +64,7 @@ def parse_args(): parser.add_argument('--chunk-dir', help='Chunks are saved in this directory. ' - 'Defaults to folder `.chunk` next to CHILD_SUBVOLUME.', + 'Defaults to directory `.chunk` next to CHILD_SUBVOLUME.', dest='chunk_dir', type=Path, metavar='CHUNK_DIR', @@ -70,9 +72,9 @@ def parse_args(): ) parser.add_argument('--target-chunk-dir', - help='Chunks are saved in this directory on SSH_TARGET. ' + help='Chunks are saved in this directory on the receiving side. ' 'Must be an absolute path. ' - 'Defaults to directory `.chunk` next to TARGET_PATH.', + 'Defaults to directory `.chunk` next to TARGET_SUBVOLUME.', dest='target_chunk_dir', type=Path, metavar='TARGET_CHUNK_DIR', @@ -80,43 +82,46 @@ def parse_args(): ) parser.add_argument('child', - help='Path to child subvolume. Forwarded to btrfs-send.', + help='Path to child subvolume. ' + 'This subvolume gets replicated at TARGET_SUBVOLUME on the receiving side.', type=Path, metavar='CHILD_SUBVOLUME' ) parser.add_argument('ssh_target', - help='Hostname of target computer; as configured in ~/.ssh/config.', + help='Hostname of receiving side as configured in ~/.ssh/config.', metavar='SSH_TARGET' ) parser.add_argument('target_path', - help='Absolute path to the read-only subvolume to be created on SSH_TARGET.', + help='Absolute path to TARGET_SUBVOLUME on the receiving side.', type=Path, - metavar='TARGET_PATH' + metavar='TARGET_SUBVOLUME' ) args = parser.parse_args() - # Make all paths absolute. Set default values. + # child args.child = args.child.absolute() - # + + # target_path if not args.target_path.is_absolute(): - raise ValueError('TARGET_PATH must be absolute') - # + raise ValueError('TARGET_SUBVOLUME must be absolute') + + # chunk_dir if args.chunk_dir is None: - # Default value args.chunk_dir = args.child.parent.joinpath(f'{args.child.name}.chunk') else: args.chunk_dir = args.chunk_dir.absolute() - # + + # target_chunk_dir if args.target_chunk_dir is None: - # Default value args.target_chunk_dir = args.target_path.parent.joinpath(f'{args.target_path.name}.chunk') else: if not args.target_chunk_dir.is_absolute(): raise ValueError('TARGET_CHUNK_DIR must be absolute') - # + + # parent if args.parent is not None: args.parent = args.parent.absolute()