mirror of
https://codeberg.org/privacy1st/subprocess-util
synced 2024-12-22 22:06:05 +01:00
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
|
#!/usr/bin/env python3
|
||
|
# -*- coding: utf-8 -*-
|
||
|
import argparse
|
||
|
from pathlib import Path
|
||
|
|
||
|
from exec_print_receive import execute_print_receive_chunks
|
||
|
from common import _get_chunk_file, _get_remote_socket
|
||
|
|
||
|
|
||
|
def main():
|
||
|
args = parse_args()
|
||
|
|
||
|
target_path: Path = args.target_path
|
||
|
command = ['btrfs', 'receive', str(target_path)]
|
||
|
target_socket = _get_remote_socket(target_path)
|
||
|
|
||
|
execute_print_receive_chunks(
|
||
|
command=command,
|
||
|
socket_file=target_socket,
|
||
|
chunk_file_tmpl=args.chunk_tmpl,
|
||
|
get_chunk_file=_get_chunk_file,
|
||
|
)
|
||
|
|
||
|
|
||
|
def parse_args():
|
||
|
parser = argparse.ArgumentParser(prog='btrfs-receive-chunks')
|
||
|
|
||
|
parser.add_argument('--chunk-tmpl',
|
||
|
help='During btrfs-receive, chunks are saved as "CHUNK_TMPL.CHUNK_NUMBER". '
|
||
|
'The default value of CHUNK_TMPL is "SUBVOLUME.CHUNK". '
|
||
|
'One can change it to e.g. "/tmp/chunk/SUBVOLUME".',
|
||
|
dest='chunk_tmpl',
|
||
|
default=None,
|
||
|
type=Path,
|
||
|
metavar='CHUNK_TMPL'
|
||
|
)
|
||
|
|
||
|
parser.add_argument('target_path',
|
||
|
help='Path were the subvolume will be created; forwarded to btrfs-receive.',
|
||
|
type=Path,
|
||
|
metavar='SUBVOLUME'
|
||
|
)
|
||
|
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
if not args.chunk_tmpl:
|
||
|
target_path: Path = args.target_path
|
||
|
args.chunk_tmpl = target_path.parent.joinpath(f'{target_path.name}.CHUNK')
|
||
|
|
||
|
return args
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|