mirror of
https://codeberg.org/privacy1st/subprocess-util
synced 2024-12-22 22:06:05 +01:00
refactor
This commit is contained in:
parent
a0e2db42e6
commit
a952ace8b4
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
name = subprocess-util
|
name = subprocess-util
|
||||||
version = 0.0.1
|
version = 0.0.2
|
||||||
author = Daniel Langbein
|
author = Daniel Langbein
|
||||||
author_email = daniel@systemli.org
|
author_email = daniel@systemli.org
|
||||||
description = subprocess utility functions
|
description = subprocess utility functions
|
||||||
|
@ -14,24 +14,23 @@ def main():
|
|||||||
target_chunk_dir: Path = args.chunk_dir
|
target_chunk_dir: Path = args.chunk_dir
|
||||||
target_path: Path = args.target_path
|
target_path: Path = args.target_path
|
||||||
|
|
||||||
target_path.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
command = ['btrfs', 'receive', str(target_path.parent)]
|
command = ['btrfs', 'receive', str(target_path.parent)]
|
||||||
|
|
||||||
exec_receive_chunks_active(
|
returncode = exec_receive_chunks_active(
|
||||||
command,
|
command,
|
||||||
ssh_source,
|
ssh_source,
|
||||||
source_chunk_dir,
|
source_chunk_dir,
|
||||||
target_chunk_dir,
|
target_chunk_dir,
|
||||||
)
|
)
|
||||||
|
exit(returncode)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(prog='btrfs-receive-chunks')
|
parser = argparse.ArgumentParser(prog='btrfs-receive-chunks-active')
|
||||||
|
|
||||||
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 parent directory of SUBVOLUME.',
|
'Defaults to directory `<SUBVOLUME>.chunk` next to SUBVOLUME.',
|
||||||
dest='chunk_dir',
|
dest='chunk_dir',
|
||||||
type=Path,
|
type=Path,
|
||||||
metavar='CHUNK_DIR',
|
metavar='CHUNK_DIR',
|
||||||
@ -39,35 +38,60 @@ def parse_args():
|
|||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('ssh_source',
|
parser.add_argument('ssh_source',
|
||||||
help='Hostname of source computer; as configured in ~/.ssh/config.',
|
help='Hostname of sending side; as configured in ~/.ssh/config.',
|
||||||
metavar='SSH_SOURCE'
|
metavar='SSH_SOURCE'
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('source_chunk_dir',
|
parser.add_argument('--child',
|
||||||
help='Chunks are saved in this directory on SSH_SOURCE. '
|
help='Path to child subvolume on sending side. '
|
||||||
'Must be an absolute path.',
|
'Must be an absolute path.',
|
||||||
|
dest='child',
|
||||||
|
type=Path,
|
||||||
|
metavar='CHILD_SUBVOLUME',
|
||||||
|
default=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument('--source-chunk-dir',
|
||||||
|
help='Chunks are saved in this directory on sending side. '
|
||||||
|
'Must be an absolute path. '
|
||||||
|
'Defaults to directory `<CHILD_SUBVOLUME>.chunk` next to CHILD_SUBVOLUME',
|
||||||
|
dest='source_chunk_dir',
|
||||||
type=Path,
|
type=Path,
|
||||||
metavar='SOURCE_CHUNK_DIR',
|
metavar='SOURCE_CHUNK_DIR',
|
||||||
|
default=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
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='SUBVOLUME'
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Make all paths absolute. Set default values.
|
# child and source_chunk_dir
|
||||||
args.target_path = args.target_path.absolute()
|
if args.child is None and args.source_chunk_dir is None:
|
||||||
if args.chunk_dir:
|
raise ValueError('Either CHILD_SUBVOLUME or SOURCE_CHUNK_DIR must be given')
|
||||||
args.chunk_dir = args.chunk_dir.absolute()
|
|
||||||
else:
|
if args.source_chunk_dir is not None:
|
||||||
args.chunk_dir = args.target_path.absolute().parent
|
|
||||||
if not args.source_chunk_dir.is_absolute():
|
if not args.source_chunk_dir.is_absolute():
|
||||||
raise ValueError(f'SOURCE_CHUNK_DIR must be absolute')
|
raise ValueError('SOURCE_CHUNK_DIR must be absolute')
|
||||||
|
if args.child is not None:
|
||||||
|
if not args.child.is_absolute():
|
||||||
|
raise ValueError('CHILD_SUBVOLUME must be absolute')
|
||||||
|
|
||||||
|
if args.source_chunk_dir is None:
|
||||||
|
args.source_chunk_dir = args.child.parent.joinpath(f'{args.child.name}.chunk')
|
||||||
|
|
||||||
|
# target_path
|
||||||
|
args.target_path = args.target_path.absolute()
|
||||||
|
|
||||||
|
# chunk_dir
|
||||||
|
if args.chunk_dir is None:
|
||||||
|
args.chunk_dir = args.target_path.parent.joinpath(f'{args.target_path.name}.chunk')
|
||||||
|
args.chunk_dir = args.chunk_dir.absolute()
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
@ -15,8 +15,6 @@ def main():
|
|||||||
parent: Path | None = args.parent
|
parent: Path | None = args.parent
|
||||||
source_chunk_dir: Path = args.chunk_dir
|
source_chunk_dir: Path = args.chunk_dir
|
||||||
|
|
||||||
source_chunk_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
command_parts = (
|
command_parts = (
|
||||||
['btrfs', 'send'],
|
['btrfs', 'send'],
|
||||||
['-p', str(parent)] if parent else [],
|
['-p', str(parent)] if parent else [],
|
||||||
@ -33,7 +31,7 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(prog='btrfs-send-chunks')
|
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; forwarded to btrfs-send.',
|
||||||
@ -59,7 +57,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 parent directory of CHILD.',
|
'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',
|
||||||
@ -74,15 +72,16 @@ def parse_args():
|
|||||||
|
|
||||||
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()
|
||||||
#
|
|
||||||
if args.chunk_dir:
|
# chunk_dir
|
||||||
|
if args.chunk_dir is None:
|
||||||
|
args.chunk_dir = args.child.parent.joinpath(f'{args.child.name}.chunk')
|
||||||
|
else:
|
||||||
args.chunk_dir = args.chunk_dir.absolute()
|
args.chunk_dir = args.chunk_dir.absolute()
|
||||||
else: # Default value
|
|
||||||
args.chunk_dir = args.child.absolute().parent
|
if args.parent is not None:
|
||||||
#
|
|
||||||
if args.parent:
|
|
||||||
args.parent = args.parent.absolute()
|
args.parent = args.parent.absolute()
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
@ -22,11 +22,11 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(prog='btrfs-receive-chunks')
|
parser = argparse.ArgumentParser(prog='btrfs-receive-chunks-passive')
|
||||||
|
|
||||||
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 parent directory of SUBVOLUME.',
|
'Defaults to folder `<SUBVOLUME>.chunk` next to SUBVOLUME.',
|
||||||
dest='chunk_dir',
|
dest='chunk_dir',
|
||||||
type=Path,
|
type=Path,
|
||||||
metavar='CHUNK_DIR',
|
metavar='CHUNK_DIR',
|
||||||
|
@ -36,7 +36,7 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(prog='btrfs-send-chunks')
|
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; forwarded to btrfs-send.',
|
||||||
|
Loading…
Reference in New Issue
Block a user