Skip to content

Commit fdba42b

Browse files
author
Rakshil Modi
committed
Updating Sync Strategy
Updated comments Updated comments
1 parent c6f8eaf commit fdba42b

File tree

3 files changed

+84
-97
lines changed

3 files changed

+84
-97
lines changed

awscli/customizations/s3/syncstrategy/nooverwrite.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"). You
44
# may not use this file except in compliance with the License. A copy of
@@ -27,19 +27,19 @@ class NoOverwriteSync(BaseSync):
2727

2828
ARGUMENT = NO_OVERWRITE
2929

30+
def __init__(self, sync_type='file_not_at_dest'):
31+
super().__init__(sync_type)
32+
3033
def determine_should_sync(self, src_file, dest_file):
31-
if not dest_file:
32-
# Sync if file does not exist at destination
33-
return True
34-
elif src_file.compare_key != dest_file.compare_key:
35-
# Sync if file exists at both source and destination but the
36-
# source file's key is different than the destination file's key
34+
if self.sync_type == 'file_not_at_dest':
35+
LOG.debug(
36+
f"syncing: {src_file.src} -> {src_file.dest}, file does not exist at destination"
37+
)
3738
return True
38-
else:
39-
# Skip if file exists at both source and destination
39+
elif self.sync_type == 'file_at_src_and_dest':
40+
# Files exist at both locations must not be synced
4041
LOG.debug(
41-
"Warning: Skipping file %s as it already exists on %s",
42-
src_file.src,
43-
src_file.dest,
42+
f"warning: skipping {src_file.src} -> {src_file.dest}, file exists at destination"
4443
)
4544
return False
45+
return False

awscli/customizations/s3/syncstrategy/register.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def register_sync_strategies(command_table, session, **kwargs):
5050
register_sync_strategy(session, DeleteSync, 'file_not_at_src')
5151

5252
# Register the noOverwrite sync strategy
53+
register_sync_strategy(session, NoOverwriteSync, 'file_not_at_dest')
5354
register_sync_strategy(session, NoOverwriteSync, 'file_at_src_and_dest')
5455

5556
# Register additional sync strategies here...
Lines changed: 71 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"). You
44
# may not use this file except in compliance with the License. A copy of
@@ -12,99 +12,85 @@
1212
# language governing permissions and limitations under the License.
1313
import datetime
1414

15+
import pytest
16+
1517
from awscli.customizations.s3.filegenerator import FileStat
1618
from awscli.customizations.s3.syncstrategy.nooverwrite import NoOverwriteSync
17-
from awscli.testutils import unittest
1819

1920

20-
class TestNoOverwriteSync(unittest.TestCase):
21-
def setUp(self):
22-
self.sync_strategy = NoOverwriteSync()
21+
@pytest.fixture
22+
def sync_strategy():
23+
return NoOverwriteSync()
24+
2325

24-
def test_file_does_not_exist_at_destination(self):
25-
"""
26-
Confirms that files are synced when not present at destination.
27-
"""
28-
time_src = datetime.datetime.now()
26+
def test_file_does_not_exist_at_destination(sync_strategy):
27+
time_src = datetime.datetime.now()
2928

30-
src_file = FileStat(
31-
src='',
32-
dest='',
33-
compare_key='test.py',
34-
size=10,
35-
last_update=time_src,
36-
src_type='s3',
37-
dest_type='local',
38-
operation_name='download',
39-
)
40-
dest_file = None
41-
should_sync = self.sync_strategy.determine_should_sync(
42-
src_file, dest_file
43-
)
44-
self.assertTrue(should_sync)
29+
src_file = FileStat(
30+
src='',
31+
dest='',
32+
compare_key='test.py',
33+
size=10,
34+
last_update=time_src,
35+
src_type='s3',
36+
dest_type='local',
37+
operation_name='download',
38+
)
39+
dest_file = None
40+
should_sync = sync_strategy.determine_should_sync(src_file, dest_file)
41+
assert should_sync
4542

46-
def test_file_exists_at_destination_with_different_key(self):
47-
"""
48-
Confirms that files are synced when key differs.
49-
"""
50-
time_src = datetime.datetime.now()
5143

52-
src_file = FileStat(
53-
src='',
54-
dest='',
55-
compare_key='test.py',
56-
size=10,
57-
last_update=time_src,
58-
src_type='s3',
59-
dest_type='s3',
60-
operation_name='copy',
61-
)
62-
dest_file = FileStat(
63-
src='',
64-
dest='',
65-
compare_key='test1.py',
66-
size=100,
67-
last_update=time_src,
68-
src_type='s3',
69-
dest_type='s3',
70-
operation_name='',
71-
)
72-
should_sync = self.sync_strategy.determine_should_sync(
73-
src_file, dest_file
74-
)
75-
self.assertTrue(should_sync)
44+
def test_file_exists_at_destination_with_different_key(sync_strategy):
45+
time_src = datetime.datetime.now()
7646

77-
def test_file_exists_at_destination_with_same_key(self):
78-
"""
79-
Confirm that files with the same key are not synced.
80-
"""
81-
time_src = datetime.datetime.now()
47+
src_file = FileStat(
48+
src='',
49+
dest='',
50+
compare_key='test.py',
51+
size=10,
52+
last_update=time_src,
53+
src_type='s3',
54+
dest_type='s3',
55+
operation_name='copy',
56+
)
57+
dest_file = FileStat(
58+
src='',
59+
dest='',
60+
compare_key='test1.py',
61+
size=100,
62+
last_update=time_src,
63+
src_type='s3',
64+
dest_type='s3',
65+
operation_name='',
66+
)
67+
should_sync = sync_strategy.determine_should_sync(src_file, dest_file)
68+
assert should_sync
8269

83-
src_file = FileStat(
84-
src='',
85-
dest='',
86-
compare_key='test.py',
87-
size=10,
88-
last_update=time_src,
89-
src_type='local',
90-
dest_type='s3',
91-
operation_name='upload',
92-
)
93-
dest_file = FileStat(
94-
src='',
95-
dest='',
96-
compare_key='test.py',
97-
size=100,
98-
last_update=time_src,
99-
src_type='local',
100-
dest_type='s3',
101-
operation_name='',
102-
)
103-
should_sync = self.sync_strategy.determine_should_sync(
104-
src_file, dest_file
105-
)
106-
self.assertFalse(should_sync)
10770

71+
def test_file_exists_at_destination_with_same_key():
72+
sync_strategy = NoOverwriteSync('file_at_src_and_dest')
73+
time_src = datetime.datetime.now()
10874

109-
if __name__ == "__main__":
110-
unittest.main()
75+
src_file = FileStat(
76+
src='',
77+
dest='',
78+
compare_key='test.py',
79+
size=10,
80+
last_update=time_src,
81+
src_type='local',
82+
dest_type='s3',
83+
operation_name='upload',
84+
)
85+
dest_file = FileStat(
86+
src='',
87+
dest='',
88+
compare_key='test.py',
89+
size=100,
90+
last_update=time_src,
91+
src_type='local',
92+
dest_type='s3',
93+
operation_name='',
94+
)
95+
should_sync = sync_strategy.determine_should_sync(src_file, dest_file)
96+
assert not should_sync

0 commit comments

Comments
 (0)