mirror of
https://codeberg.org/privacy1st/subprocess-util
synced 2024-12-22 22:06:05 +01:00
refactor
This commit is contained in:
parent
a952ace8b4
commit
ef3fe0fc96
@ -38,7 +38,7 @@ def parse_args():
|
|||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('ssh_source',
|
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'
|
metavar='SSH_SOURCE'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ def parse_args():
|
|||||||
parser = argparse.ArgumentParser(prog='btrfs-send-chunks-passive')
|
parser = argparse.ArgumentParser(prog='btrfs-send-chunks-passive')
|
||||||
|
|
||||||
parser.add_argument('-p',
|
parser.add_argument('-p',
|
||||||
help='Path to parent subvolume; forwarded to btrfs-send.',
|
help='Path to parent subvolume.',
|
||||||
dest='parent',
|
dest='parent',
|
||||||
default=None,
|
default=None,
|
||||||
type=Path,
|
type=Path,
|
||||||
@ -49,7 +49,7 @@ def parse_args():
|
|||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('--chunk-size',
|
parser.add_argument('--chunk-size',
|
||||||
help='Size in bytes; defaults to 128 MB.',
|
help='Size in bytes. Defaults to 128 MB.',
|
||||||
dest='chunk_size',
|
dest='chunk_size',
|
||||||
type=int,
|
type=int,
|
||||||
default=128 * 1024 * 1024,
|
default=128 * 1024 * 1024,
|
||||||
|
@ -26,7 +26,7 @@ def parse_args():
|
|||||||
|
|
||||||
parser.add_argument('--chunk-dir',
|
parser.add_argument('--chunk-dir',
|
||||||
help='Chunks are saved in this directory. '
|
help='Chunks are saved in this directory. '
|
||||||
'Defaults to folder `<SUBVOLUME>.chunk` next to SUBVOLUME.',
|
'Defaults to directory `<TARGET_SUBVOLUME>.chunk` next to TARGET_SUBVOLUME.',
|
||||||
dest='chunk_dir',
|
dest='chunk_dir',
|
||||||
type=Path,
|
type=Path,
|
||||||
metavar='CHUNK_DIR',
|
metavar='CHUNK_DIR',
|
||||||
@ -36,18 +36,18 @@ def parse_args():
|
|||||||
parser.add_argument('target_path',
|
parser.add_argument('target_path',
|
||||||
help='Path where the subvolume will be created. '
|
help='Path where the subvolume will be created. '
|
||||||
'The last component of the path '
|
'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,
|
type=Path,
|
||||||
metavar='SUBVOLUME'
|
metavar='TARGET_SUBVOLUME'
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Make all paths absolute. Set default values.
|
# target_path
|
||||||
args.target_path = args.target_path.absolute()
|
args.target_path = args.target_path.absolute()
|
||||||
#
|
|
||||||
|
# chunk_dir
|
||||||
if args.chunk_dir is None:
|
if args.chunk_dir is None:
|
||||||
# Default value
|
|
||||||
args.chunk_dir = args.target_path.parent.joinpath(f'{args.target_path.name}.chunk')
|
args.chunk_dir = args.target_path.parent.joinpath(f'{args.target_path.name}.chunk')
|
||||||
else:
|
else:
|
||||||
args.chunk_dir = args.chunk_dir.absolute()
|
args.chunk_dir = args.chunk_dir.absolute()
|
||||||
|
@ -39,7 +39,9 @@ def parse_args():
|
|||||||
parser = argparse.ArgumentParser(prog='btrfs-send-chunks-active')
|
parser = argparse.ArgumentParser(prog='btrfs-send-chunks-active')
|
||||||
|
|
||||||
parser.add_argument('-p',
|
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',
|
dest='parent',
|
||||||
default=None,
|
default=None,
|
||||||
type=Path,
|
type=Path,
|
||||||
@ -47,14 +49,14 @@ def parse_args():
|
|||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('--compressed-data',
|
parser.add_argument('--compressed-data',
|
||||||
help='Forwarded to btrfs-send.',
|
help='Reduce network bandwidth by compressing data.',
|
||||||
dest='compressed_data',
|
dest='compressed_data',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('--chunk-size',
|
parser.add_argument('--chunk-size',
|
||||||
help='Size in bytes; defaults to 128 MB.',
|
help='Size in bytes. Defaults to 128 MB.',
|
||||||
dest='chunk_size',
|
dest='chunk_size',
|
||||||
type=int,
|
type=int,
|
||||||
default=128 * 1024 * 1024,
|
default=128 * 1024 * 1024,
|
||||||
@ -62,7 +64,7 @@ def parse_args():
|
|||||||
|
|
||||||
parser.add_argument('--chunk-dir',
|
parser.add_argument('--chunk-dir',
|
||||||
help='Chunks are saved in this directory. '
|
help='Chunks are saved in this directory. '
|
||||||
'Defaults to folder `<CHILD_SUBVOLUME>.chunk` next to CHILD_SUBVOLUME.',
|
'Defaults to directory `<CHILD_SUBVOLUME>.chunk` next to CHILD_SUBVOLUME.',
|
||||||
dest='chunk_dir',
|
dest='chunk_dir',
|
||||||
type=Path,
|
type=Path,
|
||||||
metavar='CHUNK_DIR',
|
metavar='CHUNK_DIR',
|
||||||
@ -70,9 +72,9 @@ def parse_args():
|
|||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('--target-chunk-dir',
|
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. '
|
'Must be an absolute path. '
|
||||||
'Defaults to directory `<TARGET_PATH>.chunk` next to TARGET_PATH.',
|
'Defaults to directory `<TARGET_SUBVOLUME>.chunk` next to TARGET_SUBVOLUME.',
|
||||||
dest='target_chunk_dir',
|
dest='target_chunk_dir',
|
||||||
type=Path,
|
type=Path,
|
||||||
metavar='TARGET_CHUNK_DIR',
|
metavar='TARGET_CHUNK_DIR',
|
||||||
@ -80,43 +82,46 @@ def parse_args():
|
|||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('child',
|
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,
|
type=Path,
|
||||||
metavar='CHILD_SUBVOLUME'
|
metavar='CHILD_SUBVOLUME'
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('ssh_target',
|
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'
|
metavar='SSH_TARGET'
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('target_path',
|
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,
|
type=Path,
|
||||||
metavar='TARGET_PATH'
|
metavar='TARGET_SUBVOLUME'
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Make all paths absolute. Set default values.
|
# child
|
||||||
args.child = args.child.absolute()
|
args.child = args.child.absolute()
|
||||||
#
|
|
||||||
|
# target_path
|
||||||
if not args.target_path.is_absolute():
|
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:
|
if args.chunk_dir is None:
|
||||||
# Default value
|
|
||||||
args.chunk_dir = args.child.parent.joinpath(f'{args.child.name}.chunk')
|
args.chunk_dir = args.child.parent.joinpath(f'{args.child.name}.chunk')
|
||||||
else:
|
else:
|
||||||
args.chunk_dir = args.chunk_dir.absolute()
|
args.chunk_dir = args.chunk_dir.absolute()
|
||||||
#
|
|
||||||
|
# target_chunk_dir
|
||||||
if args.target_chunk_dir is None:
|
if args.target_chunk_dir is None:
|
||||||
# Default value
|
|
||||||
args.target_chunk_dir = args.target_path.parent.joinpath(f'{args.target_path.name}.chunk')
|
args.target_chunk_dir = args.target_path.parent.joinpath(f'{args.target_path.name}.chunk')
|
||||||
else:
|
else:
|
||||||
if not args.target_chunk_dir.is_absolute():
|
if not args.target_chunk_dir.is_absolute():
|
||||||
raise ValueError('TARGET_CHUNK_DIR must be absolute')
|
raise ValueError('TARGET_CHUNK_DIR must be absolute')
|
||||||
#
|
|
||||||
|
# parent
|
||||||
if args.parent is not None:
|
if args.parent is not None:
|
||||||
args.parent = args.parent.absolute()
|
args.parent = args.parent.absolute()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user