mirror of
https://codeberg.org/privacy1st/subprocess-util
synced 2024-12-22 22:06:05 +01:00
cleanup
This commit is contained in:
parent
5bb4fe6208
commit
15bbb728e8
@ -1,15 +1,11 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
|
||||||
import shlex
|
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from p1st.exec_capture import execute_capture
|
from p1st.exec_capture import execute_capture
|
||||||
from p1st.exec_print_capture import execute_print_capture
|
from p1st.exec_print_capture import execute_print_capture
|
||||||
from p1st.exec_produce_chunks import execute_produce_chunks
|
from p1st.exec_produce_chunks import execute_produce_chunks
|
||||||
from p1st.transfer_inform import transfer_inform
|
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
@ -43,33 +39,6 @@ def test2():
|
|||||||
returncode, out, err = execute_print_capture(['ls', '/foo/bar'])
|
returncode, out, err = execute_print_capture(['ls', '/foo/bar'])
|
||||||
|
|
||||||
|
|
||||||
def test4():
|
|
||||||
_init(4)
|
|
||||||
|
|
||||||
transfer_inform(
|
|
||||||
['ls', 'test/4-rsync-error'], # rsync src to dst
|
|
||||||
['ls', 'test/4-ssh-error'], # ssh target-pc 'echo "OK" | nc -U "/path/to/unix-socket"'
|
|
||||||
Path('test/4-UNIX-socket')
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _test5_chunk_transfer_fun(chunk_file: Path,
|
|
||||||
chunk_number: int,
|
|
||||||
eof: bool,
|
|
||||||
concat_script: Path,
|
|
||||||
remote_target_file: Path):
|
|
||||||
rsync_cmd = [str(concat_script), str(chunk_file), str(remote_target_file)]
|
|
||||||
inform_cmd = ['ls',
|
|
||||||
chunk_file.parent.joinpath(f'5.remote.EOF={eof}'),
|
|
||||||
]
|
|
||||||
|
|
||||||
transfer_inform(
|
|
||||||
rsync_cmd=rsync_cmd,
|
|
||||||
inform_cmd=inform_cmd,
|
|
||||||
user_input_file=chunk_file.parent.joinpath(f'5.SOCKET'),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test8():
|
def test8():
|
||||||
repo_name = 'subprocess_util'
|
repo_name = 'subprocess_util'
|
||||||
|
|
||||||
@ -108,9 +77,9 @@ def test9():
|
|||||||
def test10():
|
def test10():
|
||||||
_init(10)
|
_init(10)
|
||||||
|
|
||||||
source_file = Path('src/p1st/transfer_inform.py')
|
source_file = Path('src/p1st/exec_capture.py')
|
||||||
chunk_dir = Path('test')
|
chunk_dir = Path('test')
|
||||||
target_file = Path('test/transfer_inform.py')
|
target_file = Path('test/exec_capture.py')
|
||||||
|
|
||||||
def get_chunk_path(chunk_no: int):
|
def get_chunk_path(chunk_no: int):
|
||||||
return chunk_dir.joinpath(f'{source_file.name}.CHUNK.{chunk_no}')
|
return chunk_dir.joinpath(f'{source_file.name}.CHUNK.{chunk_no}')
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from p1st.repeat import repeat_until_successful
|
|
||||||
|
|
||||||
|
|
||||||
def transfer_inform(rsync_cmd: list[str],
|
|
||||||
inform_cmd: list[str],
|
|
||||||
user_input_file: Path):
|
|
||||||
"""
|
|
||||||
First, this method transfers files to a remote pc.
|
|
||||||
|
|
||||||
Then, it informs the remote pc.
|
|
||||||
|
|
||||||
If some error occurs during the above steps,
|
|
||||||
it waits for user input (via a UNIX-socket) and repeats the failed step.
|
|
||||||
|
|
||||||
:param rsync_cmd:
|
|
||||||
:param inform_cmd:
|
|
||||||
:param user_input_file:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
|
|
||||||
# - rsync to remote pc
|
|
||||||
# - catch error
|
|
||||||
# - wait until user input, then repeat
|
|
||||||
repeat_until_successful(rsync_cmd, user_input_file)
|
|
||||||
|
|
||||||
# - inform remote pc about complete rsync
|
|
||||||
# - catch error
|
|
||||||
# - wait until user input, then repeat
|
|
||||||
repeat_until_successful(inform_cmd, user_input_file)
|
|
Loading…
Reference in New Issue
Block a user