Skip to content

Commit

Permalink
Renamed sync strategy class names.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleknap committed Oct 13, 2014
1 parent b41e3fe commit 9f56e8f
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 70 deletions.
9 changes: 5 additions & 4 deletions awscli/customizations/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,8 @@ def create_help_command(self):
command_help_table = {}
if self.SUBCOMMANDS:
command_help_table = self.create_help_command_table()
arg_help_table = self.arg_table
if arg_help_table is None:
arg_help_table = self._build_arg_table()
return BasicHelp(self._session, self, command_table=command_help_table,
arg_table=arg_help_table)
arg_table=self.arg_table)

def create_help_command_table(self):
"""
Expand Down Expand Up @@ -257,10 +254,14 @@ def _build_arg_table(self):

@property
def arg_table(self):
if self._arg_table is None:
self._arg_table = self._build_arg_table()
return self._arg_table

@property
def subcommand_table(self):
if self._subcommand_table is None:
self._subcommand_table = self._build_subcommand_table()
return self._subcommand_table

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion awscli/customizations/s3/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from awscli.customizations.commands import BasicCommand
from awscli.customizations.s3.subcommands import ListCommand, WebsiteCommand, \
CpCommand, MvCommand, RmCommand, SyncCommand, MbCommand, RbCommand
from awscli.customizations.s3.syncstrategy.registerstrategy import \
from awscli.customizations.s3.syncstrategy.register import \
register_sync_strategies


Expand Down
14 changes: 6 additions & 8 deletions awscli/customizations/s3/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from awscli.customizations.s3.s3handler import S3Handler, S3StreamHandler
from awscli.customizations.s3.utils import find_bucket_key, uni_print, \
AppendFilter, find_dest_path_comp_key
from awscli.customizations.s3.syncstrategy.syncstrategy import \
DefaultSyncStrategy, DefaultNotAtDestSyncStrategy, \
DefaultNotAtSrcSyncStrategy
from awscli.customizations.s3.syncstrategy.base import MissingFileSync, \
SizeAndLastModifiedSync, NeverSync



RECURSIVE = {'name': 'recursive', 'action': 'store_true', 'dest': 'dir_op',
Expand Down Expand Up @@ -529,11 +529,9 @@ def choose_sync_strategies(self):
sync_strategies = {}
# Set the default strategies.
sync_strategies['file_at_src_and_dest_sync_strategy'] = \
DefaultSyncStrategy()
sync_strategies['file_not_at_dest_sync_strategy'] = \
DefaultNotAtDestSyncStrategy()
sync_strategies['file_not_at_src_sync_strategy'] = \
DefaultNotAtSrcSyncStrategy()
SizeAndLastModifiedSync()
sync_strategies['file_not_at_dest_sync_strategy'] = MissingFileSync()
sync_strategies['file_not_at_src_sync_strategy'] = NeverSync()

# Determine what strategies to overide if any.
responses = self.session.emit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'file_not_at_src']


class BaseSyncStrategy(object):
class BaseSync(object):
"""Base sync strategy
To create a new sync strategy, subclass from this class.
Expand Down Expand Up @@ -223,7 +223,7 @@ def compare_time(self, src_file, dest_file):
return False


class DefaultSyncStrategy(BaseSyncStrategy):
class SizeAndLastModifiedSync(BaseSync):

def determine_should_sync(self, src_file, dest_file):
same_size = self.compare_size(src_file, dest_file)
Expand All @@ -237,17 +237,17 @@ def determine_should_sync(self, src_file, dest_file):
return should_sync


class DefaultNotAtSrcSyncStrategy(BaseSyncStrategy):
class NeverSync(BaseSync):
def __init__(self, sync_type='file_not_at_src'):
super(DefaultNotAtSrcSyncStrategy, self).__init__(sync_type)
super(NeverSync, self).__init__(sync_type)

def determine_should_sync(self, src_file, dest_file):
return False


class DefaultNotAtDestSyncStrategy(BaseSyncStrategy):
class MissingFileSync(BaseSync):
def __init__(self, sync_type='file_not_at_dest'):
super(DefaultNotAtDestSyncStrategy, self).__init__(sync_type)
super(MissingFileSync, self).__init__(sync_type)

def determine_should_sync(self, src_file, dest_file):
LOG.debug("syncing: %s -> %s, file does not exist at destination",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# language governing permissions and limitations under the License.
import logging

from awscli.customizations.s3.syncstrategy.syncstrategy import \
BaseSyncStrategy
from awscli.customizations.s3.syncstrategy.base import BaseSync


LOG = logging.getLogger(__name__)
Expand All @@ -25,7 +24,7 @@
"deleted during sync.")}


class DeleteSyncStrategy(BaseSyncStrategy):
class DeleteSync(BaseSync):

ARGUMENT = DELETE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# language governing permissions and limitations under the License.
import logging

from awscli.customizations.s3.syncstrategy.syncstrategy import \
BaseSyncStrategy
from awscli.customizations.s3.syncstrategy.base import BaseSync


LOG = logging.getLogger(__name__)
Expand All @@ -28,7 +27,7 @@
'than the S3 version.')}


class ExactTimestampsSyncStrategy(BaseSyncStrategy):
class ExactTimestampsSync(BaseSync):

ARGUMENT = EXACT_TIMESTAMPS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from awscli.customizations.s3.syncstrategy.sizeonlystrategy import \
SizeOnlySyncStrategy
from awscli.customizations.s3.syncstrategy.exacttimestampsstrategy import \
ExactTimestampsSyncStrategy
from awscli.customizations.s3.syncstrategy.deletestrategy import \
DeleteSyncStrategy
from awscli.customizations.s3.syncstrategy.sizeonly import SizeOnlySync
from awscli.customizations.s3.syncstrategy.exacttimestamps import \
ExactTimestampsSync
from awscli.customizations.s3.syncstrategy.delete import DeleteSync


def register_sync_strategy(session, strategy_cls,
Expand All @@ -40,13 +38,12 @@ def register_sync_strategies(command_table, session, **kwargs):
"""

# Register the size only sync strategy.
register_sync_strategy(session, SizeOnlySyncStrategy)
register_sync_strategy(session, SizeOnlySync)

# Register the exact timestamps sync strategy.
register_sync_strategy(session, ExactTimestampsSyncStrategy)
register_sync_strategy(session, ExactTimestampsSync)

# Register the delete sync strategy.
register_sync_strategy(session, DeleteSyncStrategy,
'file_not_at_src')
register_sync_strategy(session, DeleteSync, 'file_not_at_src')

# Register additional sync strategies here...
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# language governing permissions and limitations under the License.
import logging

from awscli.customizations.s3.syncstrategy.syncstrategy import \
BaseSyncStrategy
from awscli.customizations.s3.syncstrategy.base import BaseSync


LOG = logging.getLogger(__name__)
Expand All @@ -25,7 +24,7 @@
'decide whether to sync from source to destination.')}


class SizeOnlySyncStrategy(BaseSyncStrategy):
class SizeOnlySync(BaseSync):

ARGUMENT = SIZE_ONLY

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,25 @@
from mock import Mock, patch

from awscli.customizations.s3.filegenerator import FileStat
from awscli.customizations.s3.syncstrategy.syncstrategy import \
BaseSyncStrategy, DefaultSyncStrategy, DefaultNotAtSrcSyncStrategy, \
DefaultNotAtDestSyncStrategy
from awscli.customizations.s3.syncstrategy.base import BaseSync, \
SizeAndLastModifiedSync, MissingFileSync, NeverSync
from awscli.testutils import unittest


class TestBaseSyncStrategy(unittest.TestCase):
class TestBaseSync(unittest.TestCase):
def setUp(self):
self.sync_strategy = BaseSyncStrategy()
self.sync_strategy = BaseSync()

def test_init(self):
valid_sync_types = ['file_at_src_and_dest', 'file_not_at_dest',
'file_not_at_src']
for sync_type in valid_sync_types:
strategy = BaseSyncStrategy(sync_type)
strategy = BaseSync(sync_type)
self.assertEqual(strategy.sync_type, sync_type)

# Check for invalid ``sync_type`` options.
with self.assertRaises(ValueError):
BaseSyncStrategy('wrong_sync_type')
BaseSync('wrong_sync_type')

def test_register_strategy(self):
"""
Expand Down Expand Up @@ -162,9 +161,9 @@ def test_no_use_sync_strategy_for_dest_but_only_name_in_params(self):
self.assertEqual(self.sync_strategy.use_sync_strategy(params), None)


class TestDefaultSyncStrategy(unittest.TestCase):
class TestSizeAndLastModifiedSync(unittest.TestCase):
def setUp(self):
self.sync_strategy = DefaultSyncStrategy()
self.sync_strategy = SizeAndLastModifiedSync()

def test_compare_size(self):
"""
Expand Down Expand Up @@ -253,9 +252,9 @@ def test_compare_lastmod_download(self):
self.assertFalse(should_sync)


class TestDefaultNotAtSrcSyncStrategy(unittest.TestCase):
class TestNeverSync(unittest.TestCase):
def setUp(self):
self.sync_strategy = DefaultNotAtSrcSyncStrategy()
self.sync_strategy = NeverSync()

def test_constructor(self):
self.assertEqual(self.sync_strategy.sync_type, 'file_not_at_src')
Expand All @@ -273,9 +272,9 @@ def test_determine_should_sync(self):
self.assertFalse(should_sync)


class TestDefaultNotAtDestSyncStrategy(unittest.TestCase):
class TestMissingFileSync(unittest.TestCase):
def setUp(self):
self.sync_strategy = DefaultNotAtDestSyncStrategy()
self.sync_strategy = MissingFileSync()

def test_constructor(self):
self.assertEqual(self.sync_strategy.sync_type, 'file_not_at_dest')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
import datetime

from awscli.customizations.s3.filegenerator import FileStat
from awscli.customizations.s3.syncstrategy.deletestrategy import \
DeleteSyncStrategy
from awscli.customizations.s3.syncstrategy.delete import DeleteSync

from awscli.testutils import unittest


class TestDeleteSyncStrategy(unittest.TestCase):
class TestDeleteSync(unittest.TestCase):
def setUp(self):
self.sync_strategy = DeleteSyncStrategy()
self.sync_strategy = DeleteSync()

def test_determine_should_sync(self):
timenow = datetime.datetime.now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
import datetime

from awscli.customizations.s3.filegenerator import FileStat
from awscli.customizations.s3.syncstrategy.exacttimestampsstrategy import \
ExactTimestampsSyncStrategy
from awscli.customizations.s3.syncstrategy.exacttimestamps import \
ExactTimestampsSync

from awscli.testutils import unittest


class TestExactTimestampsSyncStrategy(unittest.TestCase):
class TestExactTimestampsSync(unittest.TestCase):
def setUp(self):
self.sync_strategy = ExactTimestampsSyncStrategy()
self.sync_strategy = ExactTimestampsSync()

def test_compare_exact_timestamps_dest_older(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# language governing permissions and limitations under the License.
from mock import Mock

from awscli.customizations.s3.syncstrategy.registerstrategy import \
from awscli.customizations.s3.syncstrategy.register import \
register_sync_strategy
from awscli.testutils import unittest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
import datetime

from awscli.customizations.s3.filegenerator import FileStat
from awscli.customizations.s3.syncstrategy.sizeonlystrategy import \
SizeOnlySyncStrategy
from awscli.customizations.s3.syncstrategy.sizeonly import SizeOnlySync

from awscli.testutils import unittest


class TestSizeOnlySyncStrategy(unittest.TestCase):
class TestSizeOnlySync(unittest.TestCase):
def setUp(self):
self.sync_strategy = SizeOnlySyncStrategy()
self.sync_strategy = SizeOnlySync()

def test_compare_size_only(self):
"""
Expand Down
11 changes: 5 additions & 6 deletions tests/unit/customizations/s3/test_subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
from awscli.customizations.s3.s3 import S3
from awscli.customizations.s3.subcommands import CommandParameters, \
CommandArchitecture, CpCommand, SyncCommand, ListCommand, get_endpoint
from awscli.customizations.s3.syncstrategy.syncstrategy import \
DefaultSyncStrategy, DefaultNotAtDestSyncStrategy, \
DefaultNotAtSrcSyncStrategy
from awscli.customizations.s3.syncstrategy.base import \
SizeAndLastModifiedSync, NeverSync, MissingFileSync
from awscli.testutils import unittest, BaseAWSHelpOutputTest
from tests.unit.customizations.s3 import make_loc_files, clean_loc_files, \
make_s3_files, s3_cleanup, S3HandlerBaseTest
Expand Down Expand Up @@ -206,15 +205,15 @@ def test_choose_sync_strategy_default(self):
sync_strategies = cmd_arc.choose_sync_strategies()
self.assertEqual(
sync_strategies['file_at_src_and_dest_sync_strategy'].__class__,
DefaultSyncStrategy
SizeAndLastModifiedSync
)
self.assertEqual(
sync_strategies['file_not_at_dest_sync_strategy'].__class__,
DefaultNotAtDestSyncStrategy
MissingFileSync
)
self.assertEqual(
sync_strategies['file_not_at_src_sync_strategy'].__class__,
DefaultNotAtSrcSyncStrategy
NeverSync
)

def test_choose_sync_strategy_overwrite(self):
Expand Down
Loading

0 comments on commit 9f56e8f

Please sign in to comment.