Skip to content

Commit 32aee53

Browse files
committed
Make ionice an option of cp and sync commands
1 parent b6c2fab commit 32aee53

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

strato/backends/_aws.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ def __init__(self):
77
self._backend = 'aws'
88
self._call_prefix = ['aws', 's3']
99

10-
def copy(self, filenames):
11-
call_args = ['ionice', '-c', '2', '-n', '7'] if shutil.which('ionice') != None else []
10+
def copy(self, ionice, filenames):
11+
call_args = ['ionice', '-c', '2', '-n', '7'] if ionice and (shutil.which('ionice') != None) else []
1212
call_args += self._call_prefix
1313
call_args.extend(['cp', '--only-show-errors'])
1414

@@ -31,8 +31,8 @@ def copy(self, filenames):
3131
print(' '.join(subcall_args))
3232
check_call(subcall_args)
3333

34-
def sync(self, source, target):
35-
call_args = ['ionice', '-c', '2', '-n', '7'] if shutil.which('ionice') != None else []
34+
def sync(self, ionice, source, target):
35+
call_args = ['ionice', '-c', '2', '-n', '7'] if ionice and (shutil.which('ionice') != None) else []
3636
call_args += self._call_prefix
3737
call_args.extend(['sync', '--delete', '--only-show-errors', source, target])
3838
print(' '.join(call_args))

strato/backends/_gcp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ def __init__(self):
77
self._backend = 'gcp'
88
self._call_prefix = ['gsutil', '-q', '-o', 'GSUtil:parallel_composite_upload_threshold=150M']
99

10-
def copy(self, recursive, parallel, filenames):
11-
call_args = ['ionice', '-c', '2', '-n', '7'] if shutil.which('ionice') != None else []
10+
def copy(self, recursive, parallel, ionice, filenames):
11+
call_args = ['ionice', '-c', '2', '-n', '7'] if ionice and (shutil.which('ionice') != None) else []
1212
call_args += self._call_prefix
1313
if parallel:
1414
call_args.append('-m')
@@ -19,8 +19,8 @@ def copy(self, recursive, parallel, filenames):
1919
print(' '.join(call_args))
2020
check_call(call_args)
2121

22-
def sync(self, parallel, source, target):
23-
call_args = ['ionice', '-c', '2', '-n', '7'] if shutil.which('ionice') != None else []
22+
def sync(self, parallel, ionice, source, target):
23+
call_args = ['ionice', '-c', '2', '-n', '7'] if ionice and (shutil.which('ionice') != None) else []
2424
call_args += self._call_prefix
2525
if parallel:
2626
call_args.append('-m')

strato/backends/_local.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
import os
1+
import os, shutil
22
from subprocess import check_call
33

44
class LocalBackend:
55
def __init__(self):
66
self._backend = 'local'
77

8-
def copy(self, recursive, filenames):
8+
def copy(self, recursive, ionice, filenames):
99
assert len(filenames) >= 2, "Either source or destination is missing!"
1010
target = filenames[-1]
1111
call_args1 = ['mkdir', '-p', target]
1212
print(' '.join(call_args1))
1313
check_call(call_args1)
1414

15-
call_args = ['cp']
15+
call_args = ['ionice', '-c', '2', '-n', '7'] if ionice and (shutil.which('ionice')) != None else []
16+
call_args += ['cp']
1617
if recursive:
1718
call_args.append('-r')
1819
call_args.extend(filenames)
1920
print(' '.join(call_args))
2021
check_call(call_args)
2122

22-
def sync(self, source, target):
23+
def sync(self, ionice, source, target):
2324
target = os.path.dirname(target)
24-
call_args = ['rsync', '-r', '--delete', source, target]
25+
call_args = ['ionice', '-c', '2', '-n', '7'] if ionice and (shutil.which('ionice')) != None else []
26+
call_args += ['rsync', '-r', '--delete', source, target]
2527
print(' '.join(call_args))
2628
check_call(call_args)
2729

strato/commands/cp.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
import argparse
22

33

4-
def copy_files(backend, recursive, parallel, filenames):
4+
def copy_files(backend, recursive, parallel, ionice, filenames):
55
assert backend in ['aws', 'gcp', 'local'], "Backend not supported!"
66

77
if backend == 'aws':
88
from strato.backends import AWSBackend
99
be = AWSBackend()
10-
be.copy(filenames)
10+
be.copy(ionice, filenames)
1111
elif backend == 'gcp':
1212
from strato.backends import GCPBackend
1313
be = GCPBackend()
14-
be.copy(recursive, parallel, filenames)
14+
be.copy(recursive, parallel, ionice, filenames)
1515
else:
1616
from strato.backends import LocalBackend
1717
be = LocalBackend()
18-
be.copy(recursive, filenames)
18+
be.copy(recursive, ionice, filenames)
1919

2020

2121
def main(argsv):
2222
parser = argparse.ArgumentParser(description="Copy files or folders. Notice that for AWS backend, a folder link must end with a slash '/'.")
2323
parser.add_argument('--backend', dest='backend', action='store', required=True, help='Specify which backend to use. Available options: aws, gcp, local.')
2424
parser.add_argument('-r', dest='recursive', action='store_true', help="Recursive copy. Not needed for AWS backend.")
2525
parser.add_argument('-m', dest='parallel', action='store_true', help="Run operations in parallel. Only available for GCP backend.")
26+
parser.add_argument('--ionice', dest='ionice', action='store_true', help="Run with ionice to avoid monopolizing local disk's I/O. Only available for Linux.")
2627
parser.add_argument('files', metavar='filenames', type=str, nargs='+', help='List of file paths.')
2728

2829
args = parser.parse_args(argsv)
29-
copy_files(args.backend, args.recursive, args.parallel, args.files)
30+
copy_files(args.backend, args.recursive, args.parallel, args.ionice, args.files)

strato/commands/sync.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
import argparse
22

33

4-
def synchronize_folders(backend, parallel, source, target):
4+
def synchronize_folders(backend, parallel, ionice, source, target):
55
assert backend in ['aws', 'gcp', 'local'], "Backend not supported!"
66

77
if backend == 'aws':
88
from strato.backends import AWSBackend
99
be = AWSBackend()
10-
be.sync(source, target)
10+
be.sync(ionice, source, target)
1111
elif backend == 'gcp':
1212
from strato.backends import GCPBackend
1313
be = GCPBackend()
14-
be.sync(parallel, source, target)
14+
be.sync(parallel, ionice, source, target)
1515
else:
1616
from strato.backends import LocalBackend
1717
be = LocalBackend()
18-
be.sync(source, target)
18+
be.sync(ionice, source, target)
1919

2020
def main(argsv):
2121
parser = argparse.ArgumentParser(description="Synchronize source and target folders.")
2222
parser.add_argument('--backend', dest='backend', action='store', required=True, help='Specify which backend to use. Available options: aws, gcp, local.')
2323
parser.add_argument('-m', dest='parallel', action='store_true', help="Run operations in parallel. Only available for GCP backend.")
24+
parser.add_argument('--ionice', dest='ionice', action='store_true', help="Run with ionice to avoid monopolizing local disk's I/O. Only available for Linux.")
2425
parser.add_argument('source', metavar='source', type=str, help='Source folder path.')
2526
parser.add_argument('target', metavar='target', type=str, help='Target folder path.')
2627

2728
args = parser.parse_args(argsv)
28-
synchronize_folders(args.backend, args.parallel, args.source, args.target)
29+
synchronize_folders(args.backend, args.parallel, args.ionice, args.source, args.target)

0 commit comments

Comments
 (0)