11from __future__ import annotations
22
33import logging
4+ import subprocess
45from pathlib import Path
56from typing import Callable , Dict , List , Optional , Tuple , Union
67
7- import procrunner
8-
98from murfey .util import Processor
109from murfey .util .file_monitor import Monitor
1110
@@ -32,7 +31,7 @@ def __init__(
3231 self .received_bytes = 0
3332 self .byte_rate : float = 0
3433 self .total_size = 0
35- self .runner_return : List [procrunner . ReturnObject ] = []
34+ self .runner_return : List [subprocess . CompletedProcess ] = []
3635 self ._root = root
3736 self ._sub_structure : Optional [Path ] = None
3837 self ._notify = notify or (lambda f : None )
@@ -53,7 +52,7 @@ def _run_rsync(
5352 retry : bool = True ,
5453 ):
5554 """
56- Run rsync -v on a list of files using procrunner .
55+ Run rsync -v on a list of files using subprocess .
5756
5857 :param root: root path of files for transferring; structure below the root is preserved
5958 :type root: pathlib.Path object
@@ -109,25 +108,28 @@ def _single_rsync(
109108 else :
110109 cmd .append (str (self ._finaldir / sub_struct ) + "/" )
111110 self ._transferring = True
112- runner = procrunner .run (
111+ runner = subprocess .run (
113112 cmd ,
114- callback_stdout = self ._parse_rsync_stdout ,
115- callback_stderr = self ._parse_rsync_stderr ,
113+ capture_output = True ,
116114 )
115+ for line in runner .stdout .decode ("utf-8" , "replace" ).split ("\n " ):
116+ self ._parse_rsync_stdout (line )
117+ for line in runner .stderr .decode ("utf-8" , "replace" ).split ("\n " ):
118+ self ._parse_rsync_stderr (line )
117119 self .runner_return .append (runner )
118120 self .failed .extend (root / sub_struct / f for f in self ._failed_tmp )
119121 if retry :
120122 self ._in .put (root / sub_struct / f for f in self ._failed_tmp )
121123
122- def _parse_rsync_stdout (self , stdout : bytes ):
124+ def _parse_rsync_stdout (self , stdout : bytes | str ):
123125 """
124126 Parse rsync stdout to collect information such as the paths of transferred
125127 files and the amount of data transferred.
126128
127129 :param stdout: stdout of rsync process
128130 :type stdout: bytes
129131 """
130- stringy_stdout = str (stdout )
132+ stringy_stdout = str (stdout ) if isinstance ( stdout , bytes ) else stdout
131133 if stringy_stdout :
132134 if self ._transferring :
133135 if stringy_stdout .startswith ("sent" ):
@@ -158,14 +160,14 @@ def _parse_rsync_stdout(self, stdout: bytes):
158160 stringy_stdout .replace ("total size" , "" ).split ()[1 ]
159161 )
160162
161- def _parse_rsync_stderr (self , stderr : bytes ):
163+ def _parse_rsync_stderr (self , stderr : bytes | str ):
162164 """
163165 Parse rsync stderr to collect information on any files that failed to transfer.
164166
165167 :param stderr: stderr of rsync process
166168 :type stderr: bytes
167169 """
168- stringy_stderr = str (stderr )
170+ stringy_stderr = str (stderr ) if isinstance ( stderr , bytes ) else stderr
169171 if stringy_stderr :
170172 if (
171173 stringy_stderr .startswith ("rsync: link_stat" )
0 commit comments